Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does VISA READ function read inconsistently?

I am controlling a device through the serial port (COM 1) and have modified the basic write and read.vi for that purpose. The problem is that the same VI, with the same serial configuration, gives inconsistent results. Please see the attached screenshots of correct and incorrect replies. Out of the 10 times I run the VI only once or twice does it reply correctly. I can understand if it replies incorrect or incomplete every time I run the VI, but randomly? I have disabled the termination character. Can anyone shed some light?
Download All
0 Kudos
Message 1 of 5
(3,737 Views)
The VISA Read is returning the correct number of bytes that are in the serial buffer. Why the number of bytes would vary is possibly due to a slow response from the instrument. If the instrument does not return a termination character, then you probably want to use a different VI. What I often do is place the VISA Bytes at Serial Port in a while loop. When the number of bytes is greater than 0, exit that loop and go to another while loop. In that loop, another VISA Bytes at Serial Port is used with a VISA Read and that loop will exit when the byte count is equal to 0. This way, you don't have to use a fixed delay and when the last loop finishes, you know you have completely flushed the buffer of all characters. It's also a good idea to provide some sort of timeout in the first loop so that if no response comes, the loop will eventually finish.
0 Kudos
Message 2 of 5
(3,721 Views)

Dennis,

I have modified the block diagram as you have suggested and stlll face the same problem. I want to believe that its an instrument speed issue but it responds correctly and consistently when using hyperterminal. I have configured the serial config VI with the same parameters (baud rate, data bits..) as in the HT. Is there any other reason you can think of?

0 Kudos
Message 3 of 5
(3,697 Views)

Below is what I use. You need the shift register in order to keep the results from a previous iteration.

When you run Hyperterminal, does it seem slow to update?

 



Message Edited by Dennis Knutson on 05-30-2008 12:06 PM
0 Kudos
Message 4 of 5
(3,691 Views)
I understand the shift register part- thank's for the suggestion. As for the HT, it is responds pretty fast.
0 Kudos
Message 5 of 5
(3,683 Views)