From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Stripping remaining characters from Receive buffer

Using the dpib32.pas library. I'm using the following in a loop to pull all data from a GPIB device buffer in 16 byte chunks until ibsta and EEND are reached.

Receive(0, iIEEE488_PrimaryAddress, buf, 16, STOPend);

I'm finding that when appending buf to my final result I of course end up with some extra characters due to the buffersize setting. Is there a method to determine what ASCii character existed at STOPEnd or the size of the last amount of info I received so I can effectively tring the extra characters from the buffered string?
0 Kudos
Message 1 of 3
(2,962 Views)
Sorry I don't know about dpib32.pas, but if you have access to the ibcntl variable then it ought to give you the length. (Does dpib32.pas give you access to the ibsta variable or do you only get a copy of it as the return value of Receive()?)

A traditional C answer is: If you don't have any other way of finding the length of data actually read, but if you know that the data don't include a NUL byte ('\0'), then memset() the entire buffer to '\0' bytes before reading.
Message 2 of 3
(2,962 Views)
dpib32.pas is simply a wrapper to the gpib dll. Works rather well. I have full access (as far as I can tell) to every aspect of the library. The ibcntl is exactly what I was looking for. I just couldn't seem to track it down through the limited code that exists to access the dll. I was previously reading for the LF of a device and stripping from there, but that's not always 100% reliable. Thanks!
0 Kudos
Message 3 of 3
(2,962 Views)