04-15-2010 01:16 PM
Hello everybody,
Here is a vi that is reading data on a power meter, by serial communication (actually, the link is USB, but the USB->serial adapter is inside the instrument)
Basically, I check if there is data available with the command DAV?, and then read the power by POWER?
The problem is that randomly, the POWER? command answer the DAV? question, unless I use VISA Clear each time a data is available.
I have investigate with NI Spy :
As you see in the text file attached I don't understand why data transfer rate is so fast, it seems that the Visa Read do not wait until a new data is available in the buffer, so the DAV loop execute very fast. (If I wait 1 second in each iteration, the problemoccure less often, but I don't think it is the solution)
In tha attched file the proble occur at line 528.
With Portmon, the situation seems different as the DAV? command is sent without any read command between two DAV?. So randomly there is like in the line 2286 in the attached log, a group of DAV? answers. After there is a mess up between the answer of DAV? and POWER?
If I use VISA Clear, the problem do no occur.
I have try sych and async mode without differences
Probably, there is something I do not understand in the VISA behaviour, I though that as I configured the com setting, the VISA read should wait for data or timeout before proceeding, it seems no to be the case
Thanks for your help.
04-20-2010 01:42 AM
Hi,
The VISA read function reads until it gets the number of bytes you have defined, reaches the end of the buffer, reaches a termination character, or if a timeout occurs. But it doesn't wait for your instrument to be ready.
So you can try to create a delay between the VISA write and the VISA read function and assure that you are getting all the information written in the buffer by inserting something like that between your write and read function:
Choose the value of input of the wait function for your instrument.
I hope this will help,
Charlotte F. | CLAD
National Instruments France