LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

What's the equivalent of a "TCP/IP listen" for a serial port?

Hi,
 
I want to listen to a serial port and wait til the data comes.
I want something exactly like a TCP/IP listen because this function always wait til there's data.
 
Any suggestion?
 
Thank you
 
Stephanie
0 Kudos
Message 1 of 5
(4,670 Views)
There's a few ways of doing this. Normally you can just do this with a simple polling mechanism and possibly couple with a notifier, or something similar. You can also try to use the "VISA Wait on Event" function. You can read more in the online help. Note that you will need to use "VISA Enable Event" and "VISA Disable Event". There's an example that ships with LabVIEW that shows you how to use this to detect a serial break, which you can adapt.
0 Kudos
Message 2 of 5
(4,660 Views)
Hi again,
 
Thank you for your answer. I've try what you said with the VISA Wait on event (see detectevent.JPG).
I took the "Detect Break Event.vi" example and instead of the "Serial Break" event, I took Serial Character (or sometimes Serial Term Char). I always get these errors ("Could not perform operation because of I/O error." or "Timeout expired before operation completed."). What I want to do is always wait til I receive an CRLF and then read it. Something as easy as the TCP/IP listen. Do you know why I have these errors?
 
Also I have another error. I've try the "Basic Serial Write and Read.vi" example and I get the same error (see basicserialwriteandread.JPG). I can easily write and I get the error when it tries to read it. Do you have any idea why it works only in one way?
 
Thank you again
 
Stéphanie
Download All
0 Kudos
Message 3 of 5
(4,596 Views)
Could it be that you don't have a timeout set on the VISA Wait on Event VI?  In the Detect Break Event example I saw through the help file, they have a 5000 ms timeout set.  On your jpeg, there is nothing set which means it is the default of zero.
0 Kudos
Message 4 of 5
(4,588 Views)
In your detectevent.jpg example the problem is likely due to the fact that you have the termination character disabled. This means you have to explicitly check how many bytes are on the serial port and feed that to the VISA Read. You can't just wire "500", as it doesn't work the same way as GPIB. Doing so will generate a timout event. If you enable the termination character then the VISA Read will stop reading once it encounteres the specified termination character. Also, the configuration, event enabling, event disabling, and close should all be outside the loop, as you don't want to keep doing this each and every time.

In the other example, the termination character is enabled, but it's not clear what you're wiring to the VISA Read for the number of bytes. I've attached a modified version of the Basic Serial Write and Read VI, but I'm not sure if it saved properly for 7.0, as I have 7.1.1f2. A picture of the code is also attached. You may need to play around with the timeout.
0 Kudos
Message 5 of 5
(4,551 Views)