LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic visa read byte count question

Solved!
Go to solution

Hello,

 

I'm a newbie and have trouble setting a byte count in labview (visa). So i set a scippy command and wonder what i should set as byte count.

some info:

My instrument has a 128 character input buffer

and the scpi code expect return format : None

 

i think maybe since return format is none i dont need a visa read yet, but what if i use a different command with returned "BR=D60.2dB 1.3"?

 

thank you for reading

0 Kudos
Message 1 of 2
(2,952 Views)
Solution
Accepted by topic author hallvardhen

Generally you have to consider two cases when communicating with instruments:

 

- Binary data protocol: This has generally a fixed frame format and while there may be specific characters to define the start and end of a data frame they are only for control purposes, not for protocol handling. The data frame is either fixed size, or with a fixed size header which contains information as to how much data follows.

 

- ASCII text based protocol: Here in almost all cases a specific byte code that does not normally occur in the command data is designated as termination character. Most common are either the Carriage Return (hex code 0xD, Decimal code 13, often referred to also as <CR> or \r) and the New Line (hex code 0xA, decimal 10, often referred to also as <LF> or \n). A variant that is also often used is the combination of both of these characters as <CR><LF> at the end of the command.

 

Your device is ASCII and therefore almost certainly uses a termination character (if it doesn't, it is a freak that will be difficult to program reliably).

 

You don't mention the bus with which it is connected but I assume it is a serial port device.

 

When you use the Configure Serial Port.vi to configure the baudrate and data format, you also have two connector inputs at the top called "Enable Termination Character (T)" and "Termination Character (0xA = '\n' = LF)".

 

If your device uses the Line Feed as termination character you are already done here, otherwise you have to wire the according ASCII code for your termination character to the second parameter.

 

Now when you send a command, you have to make sure that this termination character is appended to the command you send. This can be done by right clicking on the LabVIEW string constant or control, selecting "Visible Items->Display Style". A glyph will appear on the left side of the string constant or control and here you can click on and select "'\'Codes Display" and now you can enter in your string command followed by \n (or whatever your devices termination character is). This is very important as most devices will not start to accept a command until they see this termination character in the incoming data buffer (some have a timeout of 1 or several seconds after no data was received after which they will attempt to interpret whatever is in the buffer already but most don't do that at all and even if your device does that you unnecessarily slow down the data communication as you will have to always wait for this timeout before the device will respond.

 

With proper termination character configured you can simply use a VISA Read and wire a count to it that is guaranteed to be larger than the largest possible string you expect. VISA Read will terminate on these conditions in this order:

 

- as soon as the underlaying driver reports an error (returns an according error)

- as soon as the number of requested bytes has been received (returns a warning that the number of received bytes matches the number of requested bytes and hence there might be more data in the buffer waiting)

- as soon as the configured termination character has been encountered (returns successful)

- when the timeout occurred before any of the above conditions happened (returns with a timeout error)

 

If the device does not respond at all to a particular command (quite unusual but it happens), you should of course not attempt to read the non-existent answer after sending this particular command. You would end up waiting for the configured timeout period and VISA Read will return with the timeout error, which is not what you want.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 2
(2,907 Views)