Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How can do event driven serial(RS232) communication in Labview?

Hi, I am new to Labview. The current goal for me is to read data on the RS232 port which is sent out by others. Since I don't know when will there be data on the RS232 port, I wonder if I can do event driven serial communication: when the RS232 port receives some data, it will put into some buffer and notify me, then I read all the data and clear the buffer.

I have written a small VI which took a while loop and polling the RS232 port. The problem with polling is that I don't know how to remember last data. Here is the flow: in a while loop, use "bytes at serial port" and "read serial port" to read the buffer data, and user string conversion function to convert it to decimal number, and link the decimal
number to a wave form. But when there is no data on the RS232 port, the string conversion will convert it to 0. How can I tell the string conversion function not to convert when there is no data on the RS232 port?
0 Kudos
Message 1 of 2
(4,056 Views)
What you should do is have two nested while loops. In the inner loop, wait until the bytes at the port are at least a certain number. When they are enough bytes exit the inner loop. After exiting, read that number of bytes, convert the string to a decimal number, then loop again.

Alternatively, if your device uses a delimiter, and sends data a regular intervals, you can just set the delimiter as your termination character and eliminate the inner loop entirely.
0 Kudos
Message 2 of 2
(4,056 Views)