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: 

Can the carriage return within a variant be read as the termination condition for VISA READ?

Solved!
Go to solution

Hi guys, I am trying to read a variant data using VISA READ. The VISA READ is set to terminate reading when it sees a carriage return.

 

Is there a chance that for the CR "encapsulated" within the variant be read by the VISA READ, and cause it to terminate?

 

Cheers! Smiley Happy

0 Kudos
Message 1 of 5
(2,498 Views)

It certainly would cause a VISA read to terminate (assuming termination characters are on and it is set for carriage return.)

 

VISA doesn't work with variants.  It is all string based which means it is a string of one of the 256 characters defined in the ASCII set.  If it gets the carriage return byte (ASCII 13), it will terminate on that.  When you say it is within a variant, do you mean you are using the Variant to Flattened String functions.

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

thanx Fan,

 

precisely the data I am trying to read is a cluster flattened to a string (with the VI VARIANT to FLATTEN ) + CR

 

The cluster consists of:

 

-The variant data

-The standard labview error cluster

-An interger

 

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

btw

 

"precisely the data I am trying to read is a cluster flattened to a string (with the VI VARIANT to FLATTEN ) + CR" <---that CR is the CR that's meant to be read.

 

What I fear is that there may be a CR in the variant, or the cluster to cause VISA READ terminate at the wrong time

0 Kudos
Message 4 of 5
(2,471 Views)
Solution
Accepted by topic author jack@nz

Since with the Flatten to String you are basically sending a binary representation of the data, you are going to have problems if you have the termination character enabled since byte 13 would be part of perfectly valid data and not just represent the end of a transmission.

 

What you might want to do is disable the termination character.  Of course now you don't know how many bytes to read.  So prepend your message to write with the number of bytes that are a part of the message (string length).  You may want to use two bytes, (one byte would only give you messages up to 255 characters in length.)

 

Now on your reading end, read 2 bytes, convert them to a number and feed that number in the next VISA read which will then read that many bytes.

 

For examples, look at the TCP/IP read write examples in the example finder and you'll see how they send a message with 4 bytes to tell how much data makes up the rest of the message.

Message 5 of 5
(2,458 Views)