Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Use VISA to Query Spectrum Analyzer trace info in integer 32 format

got error User Buffer trying to use viVQuery
0 Kudos
Message 1 of 7
(5,949 Views)
Please make sure you are calling viQueryf not viVQueryf. The second version is really intended for internal use.

For viQueryf and viScanf, the VI_ERROR_USER_BUF means that you probably passed the value 0 or VI_NULL as an argument (possibly a variable whose default value may be 0). You must pass the *address* of your arguments so that the VISA driver can write back into them.

If you have NI-VISA 2.6, please see the formatted I/O examples in chapter 5 of the NI-VISA User Manual, located in the Start menu.

Dan Mondrik
Senior Software Engineer, NI-VISA
National Instruments
0 Kudos
Message 2 of 7
(5,949 Views)
Somehow the fact that I'm using Visual Basic got lost in the shuffle. Your VISA documentation expressly forbids the use of viQueryf in Visual Basic because "it accepts a variable number of parms". In fact, viQueryf is NOT in the NI_VISA module for VB that I am using.
0 Kudos
Message 3 of 7
(5,949 Views)
That's right, formatted I/O in VB really doesn't work well. If you need formatted I/O, you have 3 choices:

1) Buy and use our Tools for Visual Basic (formerly known as ComponentWorks). This has wonderful data formatting capabilities in an ActiveX control.

2) Make your own wrappers for viVScanf or viVQueryf for each type of data formatting you need. For example, to read in 1 long integer it might be:

Declare Function myVScanfSingleLong Lib "VISA32.DLL" Alias "#280" (ByVal vi As Long, ByVal readFmt As String, singleNumericParam As Long) As Long

Admittedly, our documentation does say that these functions are available from VB, and while it is possible if you do it this way, we probably shouldn't claim that these functions "work".


3) Write a separate DLL in C and have it do the formatting part, and let it export a well-known API with data types acceptable to VB.

Sorry, but that's just a technical shortcoming of VB.

Dan Mondrik
0 Kudos
Message 4 of 7
(5,949 Views)
Since the final parameter in the viVQueryf function is declared using the 'Any' data type, and because of the way the viV commands are structured in C, you have to pass a pointer to your variable (unless you are passing a string).
As you know VB doesn't really like pointers, so use the undocumented funtion VarPtr(). Basically your call will look something like:
dim lngArray(0 to 400) as long 'dimension array appropriately
viVQueryf vi, "TRAC:DATA? TRACE1" & vblf, "%,401ld", VarPtr(lngArray(0)) ' Adjust the ,401 portion for your array size


I just tested this with an agilent power supply and it worked correctly.
0 Kudos
Message 5 of 7
(5,949 Views)
Looked good, hopes were high, but alas, a no go.

Here's my call

lRet = viVQueryf(m_SessionID, "TRAC? TRACE1" & vbLf, "%,601ld", VarPtr(RawData(0)))

I now get "Invalid Format"

The Agilent E4440A is set to output format Int,32 (i.e. Long). The data stream coming from the instrument has a header "#42404". That header Tells me that the actual data portion is 2404 bytes (601 x 4) long. Maybe I have to avoid the header somehow.
0 Kudos
Message 6 of 7
(5,949 Views)
sorry I didn't realize you were reading back a binary block. Usually for that I read a string back, strip the header and save the rest to a binary file, then read the array from the binary file.
The documentation for viScanf says that the numbers to read back are expected in IEEE488.2 or format (which is ASCII with or without a decimal), and the elements of the array should be comma seperated.
There is one format specifier that looks promising, and that is "%b".
You may have to deal with the header with a seperate viScanf call. Basically I'm thinking something like:

IRet = viVQueryf(m_SessionID, "TRAC? TRACE1" & vblf, "%6c", strHeader)

IRet = viVScanf(m_SessionID, "%601lb", VarPtr(RawData(0)))


My Ag
ilent SpecAn is in our lab across the street right now, so I can't check on it right now. But the code I posted will work if your data is sent back as ASCII instead of Binary.
0 Kudos
Message 7 of 7
(5,949 Views)