Rules for Completing Read and Write Operations over TCP/IP and UDP

The rules for completing synchronous and asynchronous read and write operations are described here.

For a general overview about writing and reading data, as well as a list of all associated functions and properties, refer to Communicating with Your Instrument.

Completing Write Operations

A write operation using fprintf or fwrite completes when one of these conditions is satisfied:

  • The specified data is written.

  • The time specified by the Timeout property passes.

In addition to these rules, you can stop an asynchronous write operation at any time with the stopasync function.

A text command is processed by the instrument only when it receives the required terminator. For TCP/IP and UDP objects, each occurrence of \n in the ASCII command is replaced with the Terminator property value. Because the default format for fprintf is %s\n, all commands written to the instrument will end with the Terminator value. The default value of Terminator is the line feed character. The terminator required by your instrument will be described in its documentation.

Completing Read Operations

A read operation with fgetl, fgets, fscanf, or readasync completes when one of these conditions is satisfied:

  • The terminator specified by the Terminator property is read. For UDP objects, DatagramTerminateMode must be off.

  • The time specified by the Timeout property passes.

  • The input buffer is filled.

  • The specified number of values is read (fscanf and readasync only). For UDP objects, DatagramTerminateMode must be off.

  • A datagram is received (for UDP objects, only when DatagramTerminateMode is on).

A read operation with fread completes when one of these conditions is satisfied:

  • The time specified by the Timeout property passes.

  • The input buffer is filled.

  • The specified number of values is read. For UDP objects, DatagramTerminateMode must be off.

  • A datagram is received (for UDP objects, only when DatagramTerminateMode is on).

Note

Set the terminator property to '' (null), if appropriate, to ensure efficient throughput of binary data.

In addition to these rules, you can stop an asynchronous read operation at any time with the stopasync function.