Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Procedure for reliable GPIB programming

Dear,
 
I am writing some GPIB program using LV-VISA functions in following steps.
 
1. open visa (omitting initialize)
2. writing visa
3. reading visa
4. close visa
 
My problem is that the result is not reliable.
(sometimes, okay... sometimes, result was not expected.. or GPIB communication error)
I think this was caused from the unexpected stopping of the code by LV's abort execution button.
 
I put the some VISA(flush I/O, VISA clear, etc) to clear the buffer prior to "open VISA".
but this thing was useless.
 
Could you please recommend some practical ways of removing buffer or resolving my problem?
 
Thank you in advance.
0 Kudos
Message 1 of 5
(3,830 Views)

You haven't given a lot to work with. What's the instrument and what commands are you sending? Posting the VI you've written would also help enormously. And, using the abort button will result in unexpected results and should not be used except when you're debugging the program. Sometimes, the best thing to do is to reset the instrument before rerunning the VI just because it may be in some really weird state.

Doing a VISA Clear should work but do it after the VISA Open. Also, when doing a read, make sure that number of bytes to read is high enough to get the entire buffer of the instrument. The number you specify can be much higher than what you might expect. Since the VISA Read will terminate automatically when the instrument sends EOI at the end of it's data, whether you specify 10 or 10000 bytes to read, it will take the same amount of time to read 10 or less bytes. But, if you specify 10 bytes and the instrument is actually sending 11, the last byte will remain in the buffer and mess up your next read. Another thing to do is to have a VI that will read the instrument's error status. Every time you write a command with a syntax error or illegal parameters, most instruments will generate an error message that's stored. You should be reading this often during debug. Watch for an error indicator on the instrument to go on. Almost all instrument drivers from NI have an error query function that you can look to for an example.

Message 2 of 5
(3,824 Views)
Thank you for the invaluable comments.
 
Please see my attachment.
This subroutine will be run under "WHILE" loop.
(Of course, I opened VISA prior to the while loop just one time)
After inserting Clear visa to the subroutine(for reading VISA), I got to a correct result.
But my another question is "should I insert the clear VISA WHENEVER just before reading data"
How about this?
 
Second, why there is no difference in data reading-time whether 10 or 1000 bytes in GPIB (not RS-232)?
 
Thank you again.
 
0 Kudos
Message 3 of 5
(3,811 Views)
Normally, a Clear VISA wouldn't be required at all but if you are going to use it, it should only be used once and right after you do your VISA Open. I suspect that the reason the VISA Clear helps is that you weren't reading all of the data in the buffer.
 
There is a difference in the time it takes to read 10 bytes or 1000 bytes. You may not be able to detect the difference since the transfer rate of GPIB is about 1Mb/sec. What I said was that for VISA Read, you can specify a much higher number of bytes to read than what you actually expect. For example, if you think that the response is going to be 50 bytes long, you can pass VISA Read a value of 1000 since VISA Read will automatically stop when it sees the GPIB termination signal. The advantage of using the higher number is if the instrument will return 51 or more bytes on some measurements. If you had only specified 50, then you would only have done a partial read and the extra bytes would still be in the buffer when you did another read.
Message 4 of 5
(3,790 Views)
Very thank you for your explanation in detail.
I understand what you said.
0 Kudos
Message 5 of 5
(3,770 Views)