06-16-2016 08:15 AM - edited 06-16-2016 08:19 AM
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?
06-16-2016 08:30 AM
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.
06-16-2016 08:46 AM
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
06-16-2016 08:56 AM
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.
06-16-2016 09:08 AM
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...
06-16-2016 09:29 AM
Time to pull out the ASCII table.
\n=0xA
\r=0xD
06-16-2016 09:41 AM
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.
06-16-2016 12:01 PM
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.
06-17-2016 06:00 AM
Hi
I made a new vi following your advice but I still have problems with an empty table sometimes...
I don't understant why...