LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Case structures - what is the best of using them?

Solved!
Go to solution

Hello

 

I am trying to look for a particular number then make a decison based on that number and I am trying to use a case structure to achieve this.

 

I am reading in packet of data from a serial port and putting my raw data into a 2d array (one line respresents a packet of data), the piece of code I am having difficulty with is to make decisions based on which packet I have received (packets are lettered A,B and C, hence the ascii values 65,66 and 67).

 

I am then doing some analysis on the raw data and putting it into an new 2d array with the similar data from other packets on one row within a new 2d array.

 

I used to using C,  so I'd usually write something like this;

 

if(number==65)

       // Change starting position of new 2d array (on the current row)

else if(number==66)

      // Change starting position of new 2d array (on the current row)

 else if(number==67)

      // Change starting position of new 2d array (on the current row)

else

      // Show some sort of error message

 

 

I have attached a jpeg of the particular piece of code with the broken wire left in so hopefully you'll be able to see my problem. I've also attached my VI so you can see the code in context. Is this the correct way of using case structures?

 

 Let me know if you need more/info want to explain something.

 

Thanks,

 

Jack

Download All
0 Kudos
Message 1 of 6
(3,549 Views)
Solution
Accepted by bluefocs

Hi Jack,

use only one case structure. You can connet your number directly to it. Create your cases and write the value in it.

See this link please http://forums.ni.com/ni/board/message?board.id=170&thread.id=391012

 

Mike

Message 2 of 6
(3,538 Views)

Here is an example on how to do it. For more complex cases you may also use a formula node.

Here is some useful tips for the Labview beginner (we have all been there some time)

1)Then starting a new Labview session enable context help (Ctrl+h). Do not be afraid to use the detailed help option

2)Then stuck, go to help in the toolbar then select find examples



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Download All
Message 3 of 6
(3,534 Views)

to6,

 

Nice emoticon!

 

 

The forums have a convulted* method for including images. You start out as you have done but then...

 

After posting click on the link for you image and copy the URL to your clipboard.

Return to your post and from the options menu for your post (right hand side) select edit (must be done with 5 minutes of posting!)

In the edit screen insert the image with the URL you copied.

Post the edited version.

 

Ben

 

* Can you imagine waht it used be like supporting a LV forum before they allowed adding images!

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 4 of 6
(3,490 Views)

I hope you are up for some constructive critisim.

 

I took your vi and edited it using a state machine design pattern.  Study this design pattern and forget everything you know about programming in C.

 

some of the things I noticed in your code 

  •  To change datatypes simply right click on the control and click representation and choose the correct datatype
  •  when you are waiting for bytes at the serial port your cpu usage probably goes to 100% quick because you do not have a delay in the loop
  •  the way you used the stop button is incorrect

 

I hope this design pattern helps

 

if you are not using projects in labview then learn about them

 

this example is a project so open the .lvproj file

 

 

Message Edited by James R on 04-24-2009 12:33 AM
- James

Using LV 2012 on Windows 7 64 bit
Message 5 of 6
(3,435 Views)

Thanks very much for all the helpful replies!

 

I don't know that you could wire a number directly in like that. The link was very useful.

 

James, thank you so much for rewritting my vi! I may not have time to implement all your suggestions, but state machines are something I'll clearly need to look into.

 

I knew the stop button was dodgy, that'll need to be fixed.

 

I knew about putting into a delay into the part where I am scanning my serial port, but I was being lazy when I first wrote the VI. So far I have got away with not doing it, but I don't think I can get away with it for much longer.

 

I didn't know about the datatype thing, I shall be using it in future!

 

I'll try and arrange what I've done into a project.

 

Thank you!

 

 

0 Kudos
Message 6 of 6
(3,409 Views)