LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading 2 digit numbers and 3 digit numbers without encountering error

I wrote a program that takes in temperature values from a hotplate, and displays real-time on a time vs. Temperature plot. It communicates through serial via VISA. The byte count for VISA read was initially set as 3 and it ran without errors when the temperature was only two digits. However, it displayed wrong numbers when the temperature was three digits (above 100C). Likewise, starting from byte count of 4, I was able to read three digit numbers, but when it was below 100, encountered a timeout error. How can I solve this problem?

 

 

0 Kudos
Message 1 of 3
(1,911 Views)

Ideally there should be a termination character to signal the end of the message, usually a return constant "\r". If the interface doesn't define that, you could use the "bytes at port" property node to see how many bytes to read.

 

bytesatport.png

0 Kudos
Message 2 of 3
(1,907 Views)

There have been dozens of discussions over the past 6 months raising questions/problems about reading data from a VISA instrument that sends data as strings of text.  In almost every case, the Original Poster (OP), generally a beginner with LabVIEW, was using Bytes at Port, and encountering problems.

 

Most (but not all!) devices that send text data via VISA terminate their text strings with a Termination Character of some kind.  The most common is "End of Line", which is most commonly either <Carriage Return><Line Feed> or just <Line Feed> (<CR> is 0xD, <LF> is 0xA).

 

If you look at the Help for VISA Configure Serial Port, you'll notice that two of the top terminals have default values (meaning that they are set to these if you do not wire them) of "Enable Termination Character" and Termination Character = LF.  So if your "sending Device" sends lines to text terminated by <LF> (which includes lines terminated by <CR><LF>), then the proper, error-free way to handle VISA Reads is the following:

  1. Ask VISA to read "far more characters than you'll ever see in a line".  Two common choices for Byte Count are 1000 and 1024 (I often use this).
  2. When the Read succeeds, process the characters (in your case, just a handful, provided your device ends the lines with <LF>.
  3. Stop worrying -- even if you get a 6 digit number, you'll be covered!

Bob Schor

0 Kudos
Message 3 of 3
(1,868 Views)