Keysight VISA.NET Help
Using Printf

Using Printf

This section explains the details of formatting messages with the Formatted I/O Printf methods, including details of format string syntax. This section contains a large number of code samples (snippets) that you can adapt for use in your programs.

In This Section

The documentation in this section applies to all overloads of PrintfPrintfAndFlushPrintfArray, and PrintArrayAndFlush that are defined in the IMessageBasedFormattedIO interface.

Printf Overloads

There are four varieties of Printf overloads:

PrintfArray and PrintfArrayAndFlush are meant to directly support passing arrays with pointers. While this behavior results in unsafe .NET code, it may have better performance because arrays are not copied for marshalling between VISA.NET and the underlying VISA C implementation. You should use PrintfArray or PrintfArrayAndFlush with large binary arrays if performance is critical; otherwise use Printf or PrintfAndFlush.

The difference between Printf and PrintfAndFlush is more subtle, and depends on the configuration of the termination character and END in message-based sessions. Assuming an IEEE-488.2 instrument, consider the behavior of the following examples. Assume that the io variable is a valid reference to IMessageBasedFormattedIO.

      io.Printf("*IDN?");

The statement above adds *IDN? to the Formatted I/O write buffer, but does not send anything to the instrument.

	io.Printf("*IDN?\n");

This statement adds *IDN?\n to the Formatted I/O write buffer. Since '\n' is the termination character for IEEE-488.2 instruments, and since SendEndEnabled is true for IEEE-488.2 instruments, the '\n' tells Printf to send the buffer to the instrument with an END on the last character of the message ('\n'), and then to flush the Formatted I/O write buffer.

	io.PrintfAndFlush("*IDN?");

This statement adds *IDN? to the Formatted I/O write buffer, and then sends the buffer to the instrument with an END on the last character of the message ('?'), and then flushes the formatted I/O write buffer. Note that a termination character is not automatically added. This is only recommended for non-IEEE 488.2 instruments that require special features.

	io.PrintfAndFlush("*IDN?\n");

This statement does exactly the same thing as io.Printf("*IDN?\n") for IEEE 488.2 instruments.

 

 


© Keysight Technologies 2015-2025