07-17-2015 10:30 AM
Hi all!
I'm trying to manipulate a device through its serial port. I established a serial communication between LabView and the device. I can see the serial data coming out and can also send commands to the device. Now I'm trying to create a vi controller that would send a command as soon as certain data is read by LabView. For instance, I have the following data transmitted from the device:
I'm ok I'm ok I'm ok I'm cold I'm ok
As soon as the 'I'm cold' string is transmited, I want to send a comand (e.g. 'heating up'). The easiest way I can think of is to AND 'I'm cold' with the received output from the device, which would raise a flag as soon as 'I'm cold' appears. However, I can't figure out how to feed the serial output back to LabView. This is only an idea, of course, so I'm open to suggestions on how to go about this. The final result should involve no human interraction and only LabView should control the device.
Regards,
Pavel
07-17-2015 10:59 AM
Hello, Pavel. You can simply compare the Serial String to the string "I'm Cold", something like the following:
I've "hidden the details" of how to get a Serial String (actually, that's an empty sub-VI, but it certainly could be "the real thing") and how to Send a Warm Command inside two sub-VIs. Notice that, by doing this, I make the logic of what's happening here much clearer than if there were lots of wires, lots of VISA functions, cluttering up the Block Diagram. Also, if these were "real" sub-VIs, I could run them in isolation to specifically test that the code works. And it makes such a neater, smaller Block Diagram ... [I'm something of a nut on sub-VIs, if you couldn't tell ...].
The "equality" comparison works if you know the exact string that you need. If you worry about matching string case (i.e. allowing "I'm cold" or "I'm Cold"), you can use the "To Lower Case" function on the strings before the equality. There are also String Functions (on the String Palette) that will let you do more sophisicated searches, should the need arise.
Bob Schor
07-17-2015 11:03 AM
07-17-2015 11:38 AM
07-28-2015 10:22 AM
Thanks for the replies!
Should I worry about line termination on the received serial messages or does LV detect a new line without explicitly marking a new line?
07-28-2015 10:33 AM
@plaser wrote:
Thanks for the replies!
Should I worry about line termination on the received serial messages or does LV detect a new line without explicitly marking a new line?
Yes you will need to deal with the termination. The VISA read will include the termination.
You can use "Trim Whitespace.vi" to remove it or you can include it in the compare
"I'm Cold\n"