Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

viRead spontaneously terminates on TCP/IP

I'm trying to get a LabVIEW driver working.

Here's some background on the device: it responds in two different methods: an IEEE 488.2 compatible format (i.e. one or more arbitrarily formatted responses, delimited by ';' and terminated with a \n) or an "internal format" which is always 20 hex characters followed by a \n. When working with TCP/IP the device's embedded processor calls a function to send a string. (More accurately, a pointer to an array of bytes and a length.) I'm pretty sure it uses the Nagle algorithm. In the case of the internal format, the function is called once for all 21 characters. viRead can catch dozens of them each second without a problem. In the case of the 488.2 type, it will call the function with the response to the first query, decide if there's another response needed, call it with a ";" and repeat the process or call it with a "\n" if it's done. (I don't know exactly how much time elapses between calls but I would guess that it's less than a ms and would be shocked if it was more than 10ms.) (The "strings" are sent without NULL terminators.)

Here's a situation:
I send an *idn?\n via viWrite (everything synchronously) "call" viRead to get the response, send something in the internal format via viWrite then call viRead to get the 21 character response. Termination character is enabled. The string indicator for the 1st viRead should be an *idn? response with a \n and the 2nd viRead's indicator should have the 20 hex characters and the terminating \n. Since in both reads I specify more than enough space I should get the "termination encountered" warning in error out. The session's timeout is 2000 ms.

Here's what happens:
The first viRead's indicator has the string without the \n and there's no error or warning. The second viRead returns the "missing" "\n" with the termination encountered warning.

If I insert a 150ms delay between the first viWrite and the viRead, the string arrives with the termination and the second viWrite/viRead also returns the correct string.

(Actually, I always have a 10ms delay between the two. At this point, let me add that the device also has GPIB and serial and the driver works correctly with them.)

My guess is that there is some delay (1, 2, 3 ms?) between the arrival of the text and the arrival of the \n. So what? it's TCP/IP. Yes, it would be nice if the device sent it all at once, but with TCP/IP there's no guarantee that it will arrive in one packet anyway.

My question is why is viRead returning. It didn't encounter the termination character, it didn't timeout and it didn't reach its count. So what if it got a whole packet? No termination, no return.

I'm using VISA 3.0.1 and LabVIEW 7

Thanx,
Roger Lemberg
0 Kudos
Message 1 of 2
(2,908 Views)
Hi Roger,

I have been trying to reproduce the behavior without any luck. I basically perform two *IDN? queries back to back. Do you get the same behavior with two *IDN? queries and no delay?.

Could you include a spy capture of the VI running when the reads return. If you are not familiar with NI-Spy, here is a tutorial.

If you have a simple VI that reproduces the problem, it mioght alos be helpful.

DiegoF
National Instruments.
0 Kudos
Message 2 of 2
(2,908 Views)