From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

case statement

I'm having trouble using a case statement with a string.  The Cal Calling button sometimes lights but the send message never goes when the proper string is received.  I do not have this problem if I use the case statement as True/False and use the output of the equal to. 

Suggestions please. 

0 Kudos
Message 1 of 6
(2,395 Views)

What do you mean by proper string? The string given in the case structure? If that is the case even if you have a space in the input/the string defined in the case structure they won't match and the case structure won't execute.

-----

The best solution is the one you find it by yourself
0 Kudos
Message 2 of 6
(2,389 Views)

Hi,

 

I can see that you have edited the udp example that ships with LabVIEW, that's usually a good place to start.

 

You've introduced some errors that you will want to get sorted before moving on.

 

Firstly, what is the second (outer) loop doing? The inner while loop will keep reading/writing data until you press the stop button. The second loop will then wait a second and start the reading/writing loop again. This isn't really necessary.

 

Secondly, you've got a potential race condition because of your local variable of 'cal calling'. It'd be better to wire to the indicator icon directly.

 

But the main problem is that your case structure will never execute the "REQSTAT" state because you have wired two constants ('OA' and '5245 5153 5441 540A') to the 'match pattern' vi. Therefore you will get the same answer out each time and this will never equal REQSTAT!

 

You probably want to wire the 'Data received' string into the 'match pattern' vi instead of the constant.

 

-CC

----------------------------------------------------------------------------------------------------------------------------
"If anyone needs me, I'll be in the Angry Dome!"


0 Kudos
Message 3 of 6
(2,368 Views)

Thanks.  A fresh eye is also better and sleep is good.  I changed the input to the matched pattern; I'll be able to check it later. As far as the double loop: It does look a little strange. Wrote the code awhile ago so I don't remember the rationales. This is a sub vi. I need to look into this a little more. 

0 Kudos
Message 4 of 6
(2,350 Views)

@exo wrote:

... A fresh eye is also better and sleep is good. 


Very true! Smiley Very Happy

 

Feel free to post pack again when you've had a look at it whilst properly awake!

 

-CC

----------------------------------------------------------------------------------------------------------------------------
"If anyone needs me, I'll be in the Angry Dome!"


0 Kudos
Message 5 of 6
(2,347 Views)

New Code 

Unfortunately, I don't sleep.

0 Kudos
Message 6 of 6
(2,344 Views)