How can I NULL terminate an ASCII response from my instrument?

NI-488.2

How can I NULL terminate an ASCII response from my instrument?

If your instrument sends you ASCII data, you can convert the string that is returned from a read operation (like ibrd or Receive) to a NULL-terminated string that can be passed to string calls like printf. After a successful read operation, Ibcnt contains the number of bytes read. To create a NULL-terminated string, add a NULL byte onto the end of the string as shown in the following C/C++ code:

char ReadBuffer[101];

ibrd (handle, ReadBuffer, 100);

if (!(Ibsta() & ERR)) {

ReadBuffer[Ibcnt()] = '\0';

printf ("Read string from instrument: %s",

ReadBuffer);

}


Return to Frequently Asked Questions