Keysight VISA.NET Help
Using Write Methods

Using Write Methods

Formatted I/O Write methods provide an easy way to format and send one item of data to an instrument.

Whereas Printf is designed to allow flexibility in formatting and sending multiple formatted items at once, Formatted I/O Write methods are designed to format one item of data in a particular format. While there are just over 20 Printf methods and overloads, there are just over 90 for Write; there is a Write method for each data type and each category of write.

In general, each Write method corresponds to a Printf method with a particular Printf format specifier and corresponding argument. For example, the Write(String) method corresponds to Printf(String, Object[]) with a format specifier of "%s". Each writes a single string supplied by a single argument, without appending a newline or END (although in both cases, an END will be appended if the argument ends in a newline and END is enabled).

Refer to the reference documentation for each Write method to see the corresponding Printf method and format specifier.

In order to understand the variety of Write methods, it is convenient to categorize them by method name. There are six method names listed in the table below, along with a description of the data types supported for each name.

Method Name

Description

Write()

Write() formats a single item of data as a string and adds it to the formatted write buffer. It does not add a newline or END, and it does not send any data to the instrument.

Write() has five overloads, one each for the types Char, String, Int64, UInt64, and Double. Values of smaller integer or real types are cast up if needed.

WriteLine()

WriteLine() performs the same tasks as Write() but does append a newline (and END, if END is enabled) to the formatted data, sends whatever is in the write buffer to the instrument, and flushes the buffer.

WriteLine() has six overloads. Five of them correspond to the Write() overloads. The sixth overload does not take a parameter; it just appends a newline to the buffer, sends data to the resource, and flushes the buffer.

WriteList()

WriteList() formats an array of data as a comma-separated list and adds it to the formatted write buffer. It does not add a newline or END, nor send any data to the instrument.

WriteList() has 20 overloads. One set of 10 overloads takes only the array to be formatted as an argument. The other set of 10 overloads takes three arguments: the array to be formatted, an index that indicates where in the array to start the formatted array, and a count that indicates how many elements to format, starting with index.

WriteList() supports 10 data types: Char, String, Int64, UInt64, Int32, UInt32, Int16, UInt16, Single, and Double. The smaller integer and real types are supported in order to avoid the performance penalty that would otherwise be incurred to upcast those types to arrays of the larger types when making the method call.

WriteLineList()

WriteLineList() performs the same tasks as WriteLine() but does append a newline (and END, if END is enabled) to the formatted data, sends whatever is in the write buffer to the instrument, and flushes the buffer.

WriteLineList() has 20 overloads, which correspond exactly to the WriteLine() overloads.

WriteBinary()

WriteBinary() formats an array of data as a raw binary array and adds it to the formatted write buffer. It does not add a newline or END, and it does not send any data to the instrument.

WriteBinary() has 20 overloads, which correspond exactly to the WriteList() overloads.

WriteLineList()

WriteBinaryAndFlush() performs the same tasks as WriteBinary() but does append a newline (and END, if END is enabled) to the formatted data, sends whatever is in the write buffer to the instrument, and flushes the buffer.

WriteBinaryAndFlush() has 20 overloads, which correspond exactly to the WriteLineList() overloads.

 

 


© Keysight Technologies 2015-2025