Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic VISA Problems USB Timeout

Hello,

 

This is my first time working with VISA or any instrument control software so this is a pretty basic question.

 

I have both NI VISA and TekVISA avaliable and the IVI drive package if this makes any difference.

 

I am trying to control and read waveforms from a digital oscilloscope through USB. I am hoping to make the code fairly universal so I have a TDS2022B, 2024B and a DPO 4104 to play around with.

 

I have been playing around with some examples from the TekVisa programming manual. I can make ID queries perfectly fine but when it comes to code to read waveforms etc I keep encountering timeout errors.

 

I won't post the whole code for the moment but this is where i begin to encounter problems.

 

// Request 8-bit binary data on the curve query
    status = viPrintf(vi, "DATA:ENCDG RIBINARY;WIDTH 1\n");
    viStatusDesc(vi, status, buffer);
    fprintf(stderr, "printf: %s\n", buffer);

    // Request the curve
    status = viPrintf(vi, "CURVE?\n");
    viStatusDesc(vi, status, buffer);
    fprintf(stderr, "printf: %s\n", buffer);

 

     /*SNIP*/

 

    // Get first char and validate
    status = viScanf(vi, "%c", &c);
    viStatusDesc(vi, status, buffer);
    fprintf(stderr, "scanf: %s\n", buffer);

    assert(c == '#');
    // Get width of element field.
    status = viScanf(vi, "%c", &c);
    viStatusDesc(vi, status, buffer);
    fprintf(stderr, "scanf: %s\n", buffer);

    assert(c >= '0' && c <= '9');

 

Then second scanf times out and then (not surprisingly) the assert fails.

 

Any help you can give would be much appreciated! Especially links to good intro/tutorials on the subject as that saves your time re-writing something thats already there!

 

Thanks in advance,

David.

0 Kudos
Message 1 of 5
(6,501 Views)

Hi David,

 

 Is there any particular reason why your using text based programming instead of Labview - as VISA control is very simple in labview. What language are you using/program?

 

However, I found lots of information of VISA control on the support pages, just search VISA control...I found this tutorial, but you'd need to convert it into CVI. 

Also, maybe look in the example finder in CVI.

 

I have attached some code example I had, see if you can pick anything up from it. 

 

If I am honest, I am not very familar with text based VISA. I'll continue looking into it.

 

Regards

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 2 of 5
(6,472 Views)

Thanks for the response!

 

I'm working in C++ just now.

 

I'm using text based VISA to keep costs down essentially..

 

The example you gave ran perfectly, ID queries always seem to be fine.

 

The problems occur with a few commands, this is a cut down version with just the commands I've also attached the full code for the two functions called.

 

    viSetAttribute(vi, VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
    viSetAttribute(vi, VI_ATTR_RD_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
   
    status = viPrintf(vi, "header off\n");

    status = viSetAttribute(vi, VI_ATTR_TMO_VALUE, 5000);//set timeout value

    status = viQueryf(vi, "hor:reco?\n", "%ld", elements);//check how many points there are

    status = viPrintf(vi, "data:start %d;data:stop %d\n", 0, (*elements)-1);//get start and finnish

    status = viQueryf(vi, "WFMOUTPRE:YOFF?\n", "%f", &yoffset);//Get the yoffset. FAILS TIMEOUT

    status = viQueryf(vi, "WFMOutpre:YMULT?\n", "%f", &ymult);// Get the ymult  FAILS TIMEOUT

    status = viPrintf(vi, "DATA:ENCDG RIBINARY;WIDTH 1\n");// Request 8-bit binary data on the curve query

    status = viPrintf(vi, "CURVE?\n");// Request the curve

    fprintf(stderr, "flush: %s\n", buffer);//flush the buffer

    status = viScanf(vi, "%c", &c);// Get first char and validate
    assert(c == '#');
   
    status = viScanf(vi, "%c", &c);// Get width of element field. FAILS TIMEOUT
    assert(c >= '0' && c <= '9');

 

The code is copied from a programming example in the TekVisa 1.1 programmers manual. I have marked the commands that fail, the rest seem to complete succesfully.

 

I'm guessing that the problem is with the actual commands sent i.e. WFMOUTPRE:YOFF?\n  etc rather than scanf, printf etc as they work with other commands but I have no idea what to change.


Thanks again,

David

 

 

0 Kudos
Message 3 of 5
(6,467 Views)

Hi David,

 

I found this useful document.
 
Suggested using the GetWaveform. This method gets a waveform at the
current oscilloscope settings, along with its sample interval and trigger
position. You can specify the channel from which to retrieve the waveform
and the desired screen resolution to use in displaying the waveform.
 
Also, p179: gave an example of finding the YOFF etc.
 yoff = query(g,'WFMOUTPRE:YOFF?','%s','%e');

Seems to be what your after.. Just written a bit differently.
 
Let me know if this is any use, also - do you get an error codes?
 
Regards

 

Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help! 😉
0 Kudos
Message 4 of 5
(6,461 Views)

Looks like this was the problem!

 

viSetAttribute(vi, VI_ATTR_WR_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);
    viSetAttribute(vi, VI_ATTR_RD_BUF_OPER_MODE, VI_FLUSH_ON_ACCESS);

 

It seems to work with those lines taken out. I'm assuming that the buffer was being flushed each time and as such the wave data was being lost. I've no idea if the data is meaningful but im working on finding out! 😛

 

Thanks for the help

David

Message 5 of 5
(6,433 Views)