04-23-2009 04:36 AM
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
Solved! Go to Solution.
04-23-2009 04:58 AM
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
04-23-2009 05:10 AM
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
04-23-2009 07:59 AM
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!
04-24-2009 12:25 AM - edited 04-24-2009 12:33 AM
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
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
04-24-2009 03:36 AM
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!