Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

String Buffer Safety in VISA

I'm about to call viGetAttribute for VI_ATTR_RSRC_NAME in my program, and I'm not sure how big to make the buffer for the result.  I'll probably choose something very large, but I was wondering if the exact buffer size needed for return strings is documented anywhere for this attribute or any string attribute in VISA?  Looking at the NI types in visatype.h, the stringy stuff resolves to char* which could point to any length buffer.
 
With VS2005 complaining to me all year about my unsecure C string functions in all the code I've ever written, it's been too much for my self-esteem.  🙂  I'm glad VISA doesn't complain much.
0 Kudos
Message 1 of 2
(3,078 Views)

I took a look into the VISA spec, but I could not find descriptions about max string length for VI_ATTR_RSRC_NAME and viGetAttribute().  However, the attribute VI_ATTR_RSRC_NAME returns a VISA address string, therefore you can consider how many bytes are enough for containg it.  As I know, the longest address string is of USBTMC device such as:

USB0::0x1234::0x1234::1234567890::1::INSTR

Although the S/N part may have different length depending on the instrument, I believe 64 byte buffer is enough in most cases for receiving it.

 

0 Kudos
Message 2 of 2
(3,070 Views)