Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Problem with buffer

Hi

 

I communicate with a device with VISA tools.

I get a buffer and then I extract data .

This works well except some times the buffer is not read entirety . The first part of the buffer is missing and my data are in this part !

On 150 iterations I have 1 case where the buffer is truncated. I don't understand why...

 

I tried to change the waiting time between writing and reading, it changes nothing .

I inserted the tool "VISA flush" to empty the buffer between each reading but it does nothing more.

 

Can you help me?

0 Kudos
Message 1 of 9
(4,493 Views)

So let's talk about the command protocol here.  I see you are sending a Carriage Return at the end of your message.  Does your instrument also send a Carriage Return at the end of its message?  If so, that is called a Termination Character.  You can turn that on and then just set the bytes to read on the VISA Read to something more than the longest messge you would ever expect to recieve.  The VISA Read will stop when it encounters the termination character.  This would eliminate the need for the wait and the flush as well as guarantee you are getting complete messages.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 9
(4,488 Views)

Thank for your help

 

Yes my instrument send a Carriage Return at the end of its message. The buffer is like this:

$REM:SN Number!

$TST0:00.00.48.22.1c.b0.2d.e7!

$REM:Battery Voltage!

$TST1:3852!

$REM:Temp Led!

$TST2:526!

$REM:Optical ref!

$TST3:29847!

$REM:Optical val!

$TST4:21825!

$REM:Temp Board!

$TST7:-25924!

$REM:Modem Radio Quality !

$REM:Quality Link!

$TST5:49!

$REM:RSSI!

$TST6:15!

$TST9:OK!

$EOT!

Or with code :

$REM:SN\sNumber!\r\r\n$TST0:00.00.48.22.1c.b0.2d.e7!\r\r\n$REM:Battery\sVoltage!\r\r\n$TST1:3852!\r\r\n$REM:Temp\sLed!\r\r\n$TST2:526!\r\r\n$REM:Optical\sref!\r\r\n$TST3:29847!\r\r\n$REM:Optical\sval!\r\r\n$TST4:21825!\r\r\n$REM:Temp\sBoard!\r\r\n$TST7:-25924!\r\r\n$REM:Modem\sRadio\sQuality\s!\r\r\n$REM:Quality\sLink!\r\r\n$TST5:49!\r\r\n$REM:RSSI!\r\r\n$TST6:15!\r\r\n$TST9:OK!\r\r\n$EOT!\r\n\r

if in my VI "L Init", I turn on "Termination Character", the main VI doesn't work

0 Kudos
Message 3 of 9
(4,485 Views)

Marcelito wrote:  if in my VI "L Init", I turn on "Termination Character", the main VI doesn't work

Did you remove the "Bytes At Port" property nodes and replace them with "large" constants?  By large, I would use something like 50 or 100 for the number of bytes to read in the VISA Read.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 9
(4,482 Views)

I remove "the bytes at port" and replace it by a contants of 400.

The value of "bytes at port" is 331.

 

In my "VI Init" I turn on character termination but what is this caracter exactly? 

The message at the end is 

\r\n\r

 

But I can only choose 0xD; 0xA...

0 Kudos
Message 5 of 9
(4,475 Views)

Time to pull out the ASCII table.

 

\n=0xA

\r=0xD


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(4,468 Views)

yes I know the conversion ASCII Table. But see the code buffer

$REM:SN\sNumber!\r\r\n$TST0:00.00.48.22.1c.b0.2d.e7!\r\r\n$REM:Battery\sVoltage!\r\r\n$TST1:3852!\r\r\n$REM:Temp\sLed!\r\r\n$TST2:526!\r\r\n$REM:Optical\sref!\r\r\n$TST3:29847!\r\r\n$REM:Optical\sval!\r\r\n$TST4:21825!\r\r\n$REM:Temp\sBoard!\r\r\n$TST7:-25924!\r\r\n$REM:Modem\sRadio\sQuality\s!\r\r\n$REM:Quality\sLink!\r\r\n$TST5:49!\r\r\n$REM:RSSI!\r\r\n$TST6:15!\r\r\n$TST9:OK!\r\r\n$EOT!\r\n\r

If I define ther terminal character with:

- 0xD or 13 or /r, I have only the first line and an error code -1073807252

- 0xA or 10 or /n, I have only the first line again but no error.

 

 

0 Kudos
Message 7 of 9
(4,465 Views)

I would use 0xA as your termination character.  You then use a While loop to keep reading the lines until you get your $EOT message.  You can either process the data as it comes in or use an autoindexing tunnel to create an array of recieved messages.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 9
(4,455 Views)

Hi 

I made a new vi following your advice but I still have problems with an empty table sometimes...

I don't understant why...

0 Kudos
Message 9 of 9
(4,429 Views)