Quantcast
Channel: Instrument Control (GPIB, Serial, VISA, IVI) topics
Viewing all articles
Browse latest Browse all 5625

VISA viRead dropping bytes (Mac OS X, NI VISA 15.5)

$
0
0

I'm writing a command-line tool (Mac OS X, NI VISA 15.5) to pipe arbitrary data in and out of a GPIB device via an NI GPIB-USB-HS+ controller.

 

It seems to be working fine if I read the entire buffer at one time, but I'd like to make it more flexible and repeatedly read in smaller chunks until the read gets an end-of-transmission. When I do this, the last byte seems to be getting lost. If I do a 1-byte-at-a-time loop (as a proof-of-concept), every other byte is lost.

 

 

        ViUInt32 read_bytes;
 
        do
        {
            vi_status = viRead(device_session, s_data_buf, sizeof(s_data_buf), &read_bytes);
 
            if( vi_status != VI_SUCCESS && vi_status != VI_SUCCESS_MAX_CNT )
            {
                fprintf(stderr, "viRead returned error: 0x%08x\n", vi_status);
                return;
            }
 
            printf("%*s", read_bytes, s_data_buf);
        } while( vi_status == VI_SUCCESS_MAX_CNT );
                
        puts("");

 

If sizeof(s_data_buf) == 64, I get the following response to my *IDN? query:

 

ICS Electronics, 4867, S/N 1603049, Rev X0.00 Ver 11.08.16

 

If sizeof(s_data_buf) == 1, I get this response:

 

ISEetois 87 / 634,RvX.0Vr1.81

 

Stepping through the code and watching the status on the GPIB device, it looks like the GPIB device is only queried once, and the result is buffered in the GPIB-USB-HS+. Each call to viRead pulls data from the buffer. Is there an extra pointer increment going on somewhere in the VISA/488.2 chain?


Viewing all articles
Browse latest Browse all 5625

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>