Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA: (Hex 0xBFFF0015) Timeout handling

Solved!
Go to solution

Hi All,

 

I am trying to commuincate with a  proprietary device.  In full operation it is meant to transmit keepalive type

data periodically, so the first thing to do is flush the recieve buffer.

 

My program is as follows, (attached):

 

1. Set the baud rate to 15200
2. Open VISA communication.
3. FLush the recieve buffer.
4. Write \r\n
5. Wait 100ms
6. Read the bytes at port value
7. Read the messages until the return count is zero.

 

The number of bytes at serial port is 360

 

The length of the message array is as follows:

 

Message element 0 has a string length of 87
Message element 1 has a string length of 90
Message element 2 has a string length of 90
Message element 3 has a string length of 90
Message element 4 has a string length of 3
Message element 5 has a string length of 0

 

Total concatenated string length : 360

 

Error element 0 has error : none
Error element 1 has error : none
Error element 2 has error : none
Error element 3 has error : none
Error element 4 has error : -1073807339
Error element 5 has error : -1073807339

 

I can easily scrub out the errors but I was wondering if there is a method that does not generate errors?


Also, why do I not get a single response rather than 5 separate responses, one of which generates an error?

 

Finally, I don't like waits, is it better to poll for a number of bytes > 0 or x number of repsonses that do not change.

Is there a particular methodology that NI recommend for this simple serial query?

 

TIA,
Sean

Download All
0 Kudos
Message 1 of 5
(22,633 Views)

It would be better if you first had a loop that checks for number of bytes greater than 0. This would eliminate any fixed wait. Then, inside a following loop, have another Bytes at Serial Port and exit this loop when the number is zero. It is in the second loop that you have the VISA Read wired to the number of available bytes. You would use a shift register and concantanate sttring function to get the entire string. You can also place the VISA Read inside a case statement so that you only do the read when the byte count is greater than 0.

 

Also, in your first loop you would want to have a timeout function so that you would not wait forever in the case of the instrument never responding.

0 Kudos
Message 2 of 5
(22,629 Views)

Thanks Dennis,

 

I guess that answers my question in that there doesn't seem to be a particularly recommended implementation.

 

However, the other questions remain.

 

1. Why do I get an error at the 5 message element which has a string length of 3?

2. Why does the VISA read component not read the complete string, i.e. why is it breaking it into smaller sub-elements?

3. On the first loop could it return a smaller number of bytes at the port, e.g. 200?  Should the be a settling period check?

 

Sean

0 Kudos
Message 3 of 5
(22,621 Views)

Apologies,

 

1. Why do I get an error at the 5 message element which has a string length of 3?

 

When bytes port at port is put in the loop, the error becomes a warning: 1073676294

 

Warning 1073676294 occurred at VISA Read in serial test.vi
Possible reason(s):
VISA:  (Hex 0x3FFF0006) The number of bytes transferred is equal to the requested input count. More data might be available.

 

if I increment the byte count by 1 I get:

 

Error -1073807339 occurred at VISA Read in serial test.vi
Possible reason(s):
VISA:  (Hex 0xBFFF0015) Timeout expired before operation completed.

 

I am going to erase the specific warning but would be interested to know if there is anyway I can complete the command without generating an error/ warning?

 

Sean

0 Kudos
Message 4 of 5
(22,620 Views)
Solution
Accepted by topic author SeanJ

Some VISA basics.

 

You have the termination character enabled with the VISA Configure Serial Port. You then use the VISA Bytes at Serial Port. Using both is not recomended. The VISA Read will automatically terminate when the termination character is detected. If you have a termination character, you might as well place some high number for the number of bytes to read. If you have no termination character, disable it.

 

You are not sending a carriage return/line feed with the \r\n. You are sending each character separately. In order to send '\' codes, you must enable them. You simply right click on the string control and select '\' Codes Display.

 

The warning is expected and normal whenever the VISA Read does not detect a termination character.

 

Placing the VISA Bytes at Serial Port outside the loop is just incorrect and using a while loop with the VISA Read is just making it worse. You are guaranteeing an error.

0 Kudos
Message 5 of 5
(22,611 Views)