Start of trail End of trail navigation bar

Table of Contents

quanser.communications.stream Class

The quanser.communications.stream class provides methods to communicate betweeen local and remote systems or devices. It provides a uniform interface for communications such as TCP/IP, UDP, shared memory, serial, SPI, I2C, etc. A communication channel is represented by a "stream", which can be a server, or listening stream, that accepts connections from clients, or a client that connects to a server or device.

To create a listening stream to act as a server, use the static quanser.communications.stream.listen method. The listen function returns an instance of the stream class whose accept method may then be used to accept a connection from a client. When the stream is no longer needed it should be closed using the close method.

To create a stream to act as a client, use the static quanser.communications.stream.connect method. The connect function returns an instance of the stream class whose methods may then be used to send and receive data from the server. When the stream is no longer needed it should be closed using the close method.

The methods of the stream class may be grouped into the following categories:

To build and run scripts involving communications in real-time on Quanser targets, refer to the Basic Procedures for Scripts.

Static Functions

The quanser.communications.stream class has the following static functions:

quanser.communications.stream.connect

Creates a stream acting as a client that connects to a server.

quanser.communications.stream.listen

Creates a listening stream to act as a server which can receive client connections.

quanser.communications.stream.close_all

Closes all open streams.

Configuration Functions

Once the board is open, the configuration functions are used to configure features of the stream, such as getting or setting the byte order or character format.

The following methods of the stream instance may be used to configure the stream:

get_character_format

Gets the character format of the stream.

set_character_format

Sets the character format of the stream.

set_byte_order

Sets the byte order used by the stream for multibyte data types.

State Functions

Once the board is open, the state functions are used to accept a client connection over a listening stream or poll the state of the stream.

The following methods of the stream instance may be used to query the state of the stream:

accept

Accepts a client connection over a listening stream.

poll

Polls the state of the stream.

Send Functions

The send functions send data over the communication channel. For multi-byte data types, the byte order configured for the stream determines the order in which the bytes of the data type are sent.

Note that the send functions store the data in the stream send buffer and the data is only sent over the communication channel when the buffer is full or the flush method is called.

The send functions are as follows:

flush

Flushes the contents of the stream send buffer to the underlying communication channel.

send_double

Sends a 64-bit floating-point number over the stream.

send_doubles

Sends an array of 64-bit floating-point numbers over the stream.

send_double_array

Sends an array of 64-bit floating-point numbers as an atomic unit over the stream.

send_single

Sends a 32-bit floating-point number over the stream.

send_singles

Sends an array of 32-bit floating-point numbers over the stream.

send_single_array

Sends an array of 32-bit floating-point numbers as an atomic unit over the stream.

send_int8

Sends an 8-bit integer over the stream.

send_int8s

Sends an array of 8-bit integers over the stream.

send_int8_array

Sends an array of 8-bit integers as an atomic unit over the stream.

send_uint8

Sends an 8-bit unsigned integer over the stream.

send_uint8s

Sends an array of 8-bit unsigned integers over the stream.

send_uint8_array

Sends an array of 8-bit unsigned integers as an atomic unit over the stream.

send_int16

Sends a 16-bit integer over the stream.

send_int16s

Sends an array of 16-bit integers over the stream.

send_int16_array

Sends an array of 16-bit integers as an atomic unit over the stream.

send_uint16

Sends a 16-bit unsigned integer over the stream.

send_uint16s

Sends an array of 16-bit unsigned integers over the stream.

send_uint16_array

Sends an array of 16-bit unsigned integers as an atomic unit over the stream.

send_int32

Sends a 32-bit integer over the stream.

send_int32s

Sends an array of 32-bit integers over the stream.

send_int32_array

Sends an array of 32-bit integers as an atomic unit over the stream.

send_uint32

Sends a 32-bit unsigned integer over the stream.

send_uint32s

Sends an array of 32-bit unsigned integers over the stream.

send_uint32_array

Sends an array of 32-bit unsigned integers as an atomic unit over the stream.

send_int64

Sends a 64-bit integer over the stream.

send_int64s

Sends an array of 64-bit integers over the stream.

send_int64_array

Sends an array of 64-bit integers as an atomic unit over the stream.

send_uint64

Sends a 64-bit unsigned integer over the stream.

send_uint64s

Sends an array of 64-bit unsigned integers over the stream.

send_uint64_array

Sends an array of 64-bit unsigned integers as an atomic unit over the stream.

print

Prints formatted text to a stream.

print_array

Prints formatted text to a stream as an atomic unit.

Receive Functions

The receive functions receive data over the communication channel. For multi-byte data types, the byte order configured for the stream determines the order in which the bytes of the data type are received.

The receive functions are as follows:

ignore

Receives bytes over the stream and ignores them.

receive_double

Receives a 64-bit floating-point number over the stream.

receive_doubles

Receives an array of 64-bit floating-point numbers over the stream.

receive_double_array

Receives an array of 64-bit floating-point numbers as an atomic unit over the stream.

receive_single

Receives a 32-bit floating-point number over the stream.

receive_singles

Receives an array of 32-bit floating-point numbers over the stream.

receive_single_array

Receives an array of 32-bit floating-point numbers as an atomic unit over the stream.

receive_int8

Receives an 8-bit integer over the stream.

receive_int8s

Receives an array of 8-bit integers over the stream.

receive_int8_array

Receives an array of 8-bit integers as an atomic unit over the stream.

receive_uint8

Receives an 8-bit unsigned integer over the stream.

receive_uint8s

Receives an array of 8-bit unsigned integers over the stream.

receive_uint8_array

Receives an array of 8-bit unsigned integers as an atomic unit over the stream.

receive_int16

Receives a 16-bit integer over the stream.

receive_int16s

Receives an array of 16-bit integers over the stream.

receive_int16_array

Receives an array of 16-bit integers as an atomic unit over the stream.

receive_uint16

Receives a 16-bit unsigned integer over the stream.

receive_uint16s

Receives an array of 16-bit unsigned integers over the stream.

receive_uint16_array

Receives an array of 16-bit unsigned integers as an atomic unit over the stream.

receive_int32

Receives a 32-bit integer over the stream.

receive_int32s

Receives an array of 32-bit integers over the stream.

receive_int32_array

Receives an array of 32-bit integers as an atomic unit over the stream.

receive_uint32

Receives a 32-bit unsigned integer over the stream.

receive_uint32s

Receives an array of 32-bit unsigned integers over the stream.

receive_uint32_array

Receives an array of 32-bit unsigned integers as an atomic unit over the stream.

receive_int64

Receives a 64-bit integer over the stream.

receive_int64s

Receives an array of 64-bit integers over the stream.

receive_int64_array

Receives an array of 64-bit integers as an atomic unit over the stream.

receive_uint64

Receives a 64-bit unsigned integer over the stream.

receive_uint64s

Receives an array of 64-bit unsigned integers over the stream.

receive_uint64_array

Receives an array of 64-bit unsigned integers as an atomic unit over the stream.

scan

Scans formatted text from a stream.

scan_array

Scans formatted text from a stream as an atomic unit.

 

navigation bar