From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

visa read function question

Hi, all:

 

I use Visa to write/read data from hardware through COM port,  the protocol is interactive communication, labview send commnd frame first, then hardware send back required data frame.if labview don't send command frame, then hardware send 0x00 continuously.  frame length is 10 bytes.

 

My idea is:  use Visa Write to send one frame down, then inside a While loop a Visa Read to get the data frame, when get the right data frame, stop while loop.

But I found the while loop can't stop, with probe, I found the data frame sliped once, it seems that Visa Read get the data then very soon it get 0x00 so that the comparison function can't finish to handle the data, then 0x00 arrives to the probe which sticked the input terminal of comparison funciton.

 

I solved this problem use a buffer string to store Visa Read's output read buffer, and make Visa Write and Visa Read a pair inside the while loop.

 

I wonder why the comparison function can't catch the data frame from Visa Read exactly.

 

Please refer to the attchment jpg file, it is not the real vi, just illustration

0 Kudos
Message 1 of 2
(2,253 Views)

Is it possible that your device is already sending 0x00 when you start running your VI?  If so, you may get that in the serial port buffer.  Then, when you do the VISA Read, you will read 0x00 as the first byte, then the first 9 bytes of your frame (cutting off the last byte) so the comparison won't work.

 

EDIT: by the way, it's common to read the "Bytes at Port" VISA property, then feed that into VISA Read as the number of bytes to read, so that you read the entire buffer contents.  You can then scan that string for the expected data.

0 Kudos
Message 2 of 2
(2,246 Views)