LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Another question on serial port communication

Solved!
Go to solution

Hi all!

I'm starting to work with LV serial communication tools (actually, I'm a newbie in LV at all).

The question is - how can I efficiently detect is there a new data arrived in the VISA read buffer?

I mean, in the examples I found, there is always a fixed delay between the serial write and read operation - it makes the instrument dependent on the communication speed and (what is worse) on the requested device response time. What I want to implement is a vi which writes a request (or different requests) via serial port and then checks periodically (with relatively small period, say, 1ms) the Serial read buffer for the response data until the new data stops arriving. For this purpose I need to know either the number of data bytes available in the read buffer or some property (if any) detecting the new data arrival.

As I read from this forum (and figured out from my own experience) - using VISA Bytes at Serial Port is't a good idea 🙂 Also I didn't find a solution without user-defined delay between the write and read operation in recent previous topics.

Can you give me an advice?

 

Thnx in advance.

0 Kudos
Message 1 of 5
(2,574 Views)
Solution
Accepted by topic author oreshvv

Use VISARead with a number of bytes to read and a timeout.

 

When your data is recieved it will be read instantly. When no data arrives, you will get a timeout error, that you can handle!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,568 Views)
Solution
Accepted by topic author oreshvv

and check if your device is sending any termination character. That you can use in configure VISA then you do not need to put a wait.

when a fresh byte will arrive it will be read by VISA read.

0 Kudos
Message 3 of 5
(2,548 Views)

to GerdW:

 

In common situation I don't know how many bytes are there in the reply - so I wire some big value to the 'byte count' terminal. In that case, if the requested device doesn't send the termination character (fortunately, my device does) the timeout should be quite small for the vi not to waste time waiting for the end of reply. But if so, then small timeout will affect the Serial Write operation (since there is one timeout value both for write and read).

 

Anyway, thanks - I understood the idea of using the VISA Read without delay before.

0 Kudos
Message 4 of 5
(2,519 Views)

to Neos:

 

Yes, my device does send the termination character - that makes the communication simple.

Finally, I wired the Serial Write and Read instruments without a delay, set the 'byte count' for Read to 1000 and enabled the termination char in Configure Serial Port.

Also I added a schematic which calculates the 'timeout' value for Configure Serial Port according to the baud rate specified.

 

Although, wouldn't my device send a termination character - the communication was not as simple...

 

Thank you.

0 Kudos
Message 5 of 5
(2,510 Views)