Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

GPIB & VISA Read Queue

Solved!
Go to solution

I try to read binary data from the GPIB and/or VISA. Now I've the problem that I don't know how many memory I should allocate that I can read all data.

Is there any Input Queue where I can get the size of bytes to read? The problem is that the binary data can variy from 150kb up to 2.5MB.

 

Thanks for your reply.

0 Kudos
Message 1 of 8
(4,715 Views)

Do that data contain an header part with the length info? In this case you could read first only that bytes, extract the length info and than allocate your array for the left data. Otherwise I think that you have to look for a register in your instrument from which reading that info.

 

regards

CLD - Labview Certified Developer
0 Kudos
Message 2 of 8
(4,703 Views)

The instrument doesn't support this. Also no header is availible becuase sometimes it is a bitmap, jpg, png or only a variable array.

Sorry, but I need a generic interface solution like the API of Windows (Socket Receive Length, RS232 Queue Length etc).

 

Could anyone help me please? Thanks!

0 Kudos
Message 3 of 8
(4,694 Views)

If the instrument does not provide any information, then there's obviously no place to know ahead of time. For data array however, you are usually requesting x number of points or can infer that information in other ways and caclulate your requirements.

 

It would help if you provided the make and model of instrument and what language you are using.

0 Kudos
Message 4 of 8
(4,689 Views)

The instrument is a Tektronix DPO7254. This supports a File transfer without any possibility to query the size of the file.

In addition I want to use that program for different instruments too (future projects) without new devloping. I develop the program with Borland Turbo Delphi und linking your gpib.dll as well as visa32.dll

 

Is this feature really not supported by the NI VISA and NI GPIB interface API?

 

Thanks for you reply.

0 Kudos
Message 5 of 8
(4,684 Views)

It's not 'my' gpib.dll as well as visa32.dll at all. It's NI's

 

I guess you don't fully understand gpib or VISA. The only output buffer that exists is in the instrument. There is no way for any function to read the size of that buffer if the instrument vendor has not made a command available. It's different with serial because you have a buffer on the pc that the instrument has written to. You can use VISA to read the number of bytes in that buffer before you transfer the contents out. No such buffer exists for GPIB/Ethernet, etc. transfers.

 

I guess I'm spoiled by LabVIEW where I don't have to allocate memory beforehand.

0 Kudos
Message 6 of 8
(4,679 Views)

Hi, I don't find the manual of this instrument but I downloaded and read the NI driver for Labview for Continuos Waveform Acquisition and this is the procedure that NI used (they acquire a waveform with command CURVE? and then used a READ with a fixed buffer length in a while loop). Probably it is not exactly what you are looking for but it can be a good example anyway.

 

 

           Procedure Notes
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Standard Operation
Complete the following standard operation steps to transfer waveform data from an oscilloscope:
1. Select a waveform source.
2. Specify a waveform data format.
3. Specify the number of bytes per data point.
4. Specify the portion of the waveform that you want to transfer.
5. Transfer waveform preamble information.
6. Transfer waveform data from the oscilloscope.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Optimized Operation
Optimized Operation for Step 2
The waveform data in the tkdpo7k Default Instrument Setup VI is in signed integer data point format with the most significant byte transfer first. Therefore, the Fetch Waveform VI does not include this step.

Optimized Operation for Step 4
The tkdpo7k Fetch Waveform VI and the tkdpo7k Default Instrument Setup VI transfer the whole waveform from an instrument buffer. Therefore, the tkdpo7k Fetch Waveform VI does not include this step.

Other Considerations
You must have knowledge of different acquisition modes to calculate the data width for a waveform. You also must choose a method to scale raw waveform data. Therefore, this VI includes a step to specify the acquisition mode before specifying the waveform data width. You must scale the data this VI retrieves from an instrument to a format that users can understand.

After performing the above optimization, complete the following optimized operation steps to transfer waveform data from an oscilloscope:
1. Select a waveform source.
2. Query the acquisition mode.
3. Specify the number of bytes per data point.
4. Transfer waveform preamble information.
5. Transfer waveform data from the oscilloscope.
6. Scale raw waveform data.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Detailed Steps
The following steps detail the behavior of this VI:
1. Select a waveform source.
2. Query and determine the acquisition mode. A correct determination is critical to steps 3 and 6.
    -----------------------------------------------
    Acquisition Mode |  Data Width  
    -----------------------------------------------
    Normal                       |   1                     
    -----------------------------------------------
    Peak Detect               |   1                     
    -----------------------------------------------
    Hi Res                        |   2                     
    -----------------------------------------------
    Envelope                   |   1                     
    -----------------------------------------------
    Average                    |   2                     
    -----------------------------------------------
3. Specify the number of bytes per data point. For the Hi Res or Average acquisition modes, set the data width to 2. For all other acquisition modes, set the data width to 1.
4. Transfer the waveform preamble information. Necessary preamble information includes XZero, XIncrement, YMultiplier, YOffset, and YZero. This VI uses XZero and XIncrement to configure the x-axis of output waveforms and uses YMultiplier, YOffset, and YZero to scale data values. This VI then parses the return string of the preamble query in step 6.
5. Transfer waveform data from the oscilloscope.
    5.1 Perform a CURV? query.
    5.2 Determine how many digits make up the entry for the number of bytes.
    5.3 Read the data size.
    5.4 Call the VISA Read VI repeatedly with a buffer size of 10000 until you obtain as much data as the data size specifies. Use      an 8-bit array to store the raw waveform data you obtain.
    5.5 Continue reading the data remaining in the instrument buffer until the buffer is empty.
6. Scale the raw waveform data.
    6.1 Cast the waveform data to a 16-bit array if the data width is 2. Split the waveform data into a minimum and a maximum data array if the acquisition mode is Peak Detect or Envelope. This VI skips this step if the data width is 1.
    6.2 Parse the preamble information.
    6.3 Scale the waveform data according to the following formula:
          Data_Value_in_units = (Raw_Data_Value - YOffset) * YMultiplier + YZero
          The resulting waveform data has a unit of volts.
    6.4 Build a waveform graph.

CLD - Labview Certified Developer
0 Kudos
Message 7 of 8
(4,664 Views)
Solution
Accepted by topic author Steve1024

The problem is that I do not have to get the curve alone. I also need the BMP and/or PNG screen shot.

And there it is not possible to get the size of the file before. I don't want to redraw the image in my application.

 

But for now I have a solution. I just wrote my own buffer object in front of the read command and so I store all information (allocated to 10MB) in the memory of the machine and so I can ask the Buffer object about the real size. After I got the data I release the buffer object memory and so I just have the memory I need in the format I need.

 

Thanks for your all help. Have a nice day.

0 Kudos
Message 8 of 8
(4,655 Views)