LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait on Event causes serial communication errors

Hi,

    I've been trying to to create a VI that can send and receive text data to a device via RS-232.  I started out with the Basic Serial Read and Write.vi that comes as an example with LabView and that works.  However, all it does is wait for specified amount of time before trying to read incoming data.  I thought to make that example more robust by polling the serial port for incoming characters.  I did some Googling and I came upon this page:

 

http://digital.ni.com/public.nsf/allkb/179E61F87CF8B340862571EA0037CFA3

 

Preventing LabVIEW from Continuously Polling the Serial Port.

 

 

When I modified the Basic ... VI to include this however, I get all manner of errors.  Sometimes, I don't get any response at all.  Sometimes, I get response data from a previous request (but not all of it), and sometimes the device I'm communicating with tells me it's seeing a framing error.  I don't think I've ever actually received a correct response.  Can someone tell me if I've implemented this incorrectly?  Does the page above ONLY apply to PXI controllers or can I use this for RS-232 communication?  Do I need to be waiting on a different event?

 

Thanks,

 

Jason Mazzotta 

 

17693iFEE00851ED14183D

0 Kudos
Message 1 of 13
(4,335 Views)

I think the CLR function was a bad idea-  unless you also RESET your instrument.  by blowing away the IO buffer data your chopping off a lot of stuff that may be happening- kind of like crashing into a tree- and leaving the device in a unknown state. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 13
(4,329 Views)

Post your vi instead of a screen shot.  I can't see a thing because the picture is too small and grainy.

  Also, with a vi, we can see all of the other cases not shown.

- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 13
(4,326 Views)

Here is a sample vi that writes to the serial port and then waits for a minimum amount of bytes to be present at the serial port before it reads.  The wait loop will abort if there is an error or if the timeout value is reached so that you don't get stuck in an infinite loop in case there is no response or in case of an error.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 13
(4,320 Views)

0 Kudos
Message 5 of 13
(4,290 Views)

 

 

If I don't flush the I/O buffers each time I read and write to the serial port, how do I make sure there's nothing in those buffers the next time I try to read and write to the serial port?

0 Kudos
Message 6 of 13
(4,286 Views)

tbob.  Thanks again.  That does seem to work.  I'm going to see if I can modify it to read out the characters individually.  I'd still be interested to find out why those events don't seem to behave they're advertised (or maybe I'm just misinterpreting the advertisement).

0 Kudos
Message 7 of 13
(4,277 Views)

 


@jazzdman wrote:

 

 

If I don't flush the I/O buffers each time I read and write to the serial port, how do I make sure there's nothing in those buffers the next time I try to read and write to the serial port?


Generally, use some form of flow control.  a temination character is one common approach so that you read until a specific character is seen (0x0A, linefeed is very common).  the RS-232 recommendation (RS stands for Recommended Standard) allows for several handshaking method of flow control as well.  Perhaps your equipment uses one of these methods?

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 13
(4,270 Views)

@jazzdman wrote:

... I'm going to see if I can modify it to read out the characters individually.  ....


Why do you want to read the characters individually?  Why not just read the whole thing and then if you want to process the characters individually you can use string subset to do this.  It is much quicker to read once and get a 100 character string than to read 100 times.  Parsing the string is very quick, quicker than a serial read.

 

- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 13
(4,260 Views)

Seems like your expected string is actually terminated by a linefeed character. VISA supports character terminated reads and even enables that for serial ports by default.

 

The entire loop in the middle and the "wait for event "can be simply replaced by a single VISA Read when you let VISA use read termination mode. It even uses line feed by default as termination character but you can easily modify that at the VISA Serial Init function.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 10 of 13
(4,220 Views)