Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create dynamic read buffersize in Delphi?

I am using the dpib32.pas library in Delphi 5, creating a generic send and receive application for a host of instruments over IEEE. In the library I have access to the Receive function Receive(0, dev, buf, 100, STOPend); but it requires a length to be stated for the size of the buffer. This perplexes me a little as the user will not always know how large the data returned will be. I could allow functions for the user to change the buffersize before their calls but I would rather find a way to dynamically increase the buffer or read from it in a loop so this does not have to occur. I've looked at using ibrd() instead but am having a little trouble figuring out how/if I should error trap the receive while the loop is runnin
g. Has anyone implemented, or can explain, how to handle the buffersize issue when you aren't sure how much data will be returned?
0 Kudos
Message 1 of 5
(4,066 Views)
Hi,

You can use the END condition on ibsta to detect if the talker has completed the message transmission. This way you can use the ibrd or receive function to read chunks of data. If the END bit is not set, it means that the talker did not finish sending the message, and you can call the function again. The ibrd will return a timeout error, but you can ignore it.

There is no way for the function to handle the buffer allocation.

DiegoF
National Instruments.
0 Kudos
Message 2 of 5
(4,066 Views)
Actually, the read will not return a timeout error if all of the data byte were consumed. Essentially, you would keep calling either ibrd or Receive in a loop until you get END. The data from each read will be appended to the end of the previous read.
0 Kudos
Message 3 of 5
(4,066 Views)
Thank you both for the immediate replies. I understand where this is going and here is going to be the next question I'll be coming back with so I'll just ask it now. Do I need to worry about any kind of read errors during the loop? Basically... what could possibly go wrong in the loop that I should be aware of for detection? I know for my first attempts at this last week that a stuck loop, even on a Win2k machine, resulted in an unexpected hard reboot on ending the application task. Not sure if that's a GPIB driver issue or what, but my first thought is making sure I can dive out of that loop on any errors to prevent it.
0 Kudos
Message 4 of 5
(4,066 Views)
Hi,

The GPIB functions should indicate any errors by setting the ERR bit (bit 15) of ibsta. The error code is obtained from the iberr variable. That is the only way the GPIB functions indicate errors. The application shouldn't terminate.

btw, GPIB Guru is right. The ibrd function won't return a timeout error when all the bytes are read. I had another situation in mind. My mistake.

DiegoF
National Instruments.
0 Kudos
Message 5 of 5
(4,066 Views)