The tcp module

This is a bus module (cmd_tcp) intended to communicate through TCP sockets.

See documentation of buses for details of its behavior.

API

cmd_tcp.init_tcp(tcp_id, conf_string)[source]

Initialize a TCP link.

conf_string must include:

  • host: hostname or IP address of the remote device
  • port: port on the remote device

optionally:

  • timeout: default timeout in seconds for this link. Can be float
cmd_tcp.deinit_tcp(tcp_id)[source]

Deinitialize and deregister TCP link tcp_id.

cmd_tcp.config_tcp(tcp_id)[source]

Configure tcp link tcp_id.

cmd_tcp.inval_tcp(tcp_id)[source]

Invalidate configuration of tcp link tcp_id.

cmd_tcp.write_tcp(tcp_id, data)[source]

Write data to TCP link tcp_id.

cmd_tcp.write_bin_tcp(tcp_id, data)[source]

Write binary data to TCP link tcp_id. data is a string where each character represents 4 bits in hexadecimal base. Little endian for each group of 8 bits.

cmd_tcp.read_tcp(tcp_id, bytes_to_read, timeout='undef')[source]

Read up to bytes_to_read bytes from TCP link tcp_id

cmd_tcp.read_bin_tcp(tcp_id, bytes_to_read, timeout='undef')[source]

Read up to bytes_to_read bytes from TCP link tcp_id in binary format. The data read is encoded by blocks of 8 bits with two hexadecimal characters little endian.

cmd_tcp.read_until_tcp(tcp_id, eot, timeout='undef')[source]

Read from TCP link tcp_id until a character from eot comma-separated list is found

cmd_tcp.read_bin_until_tcp(tcp_id, eot, timeout='undef')[source]

Read from TCP link tcp_id until a character from eot comma-separated list is found. The data read is encoded by blocks of 8 bits with two hexadecimal characters little endian.

cmd_tcp.wrnrd_tcp(tcp_id, data, bytes_to_read, timeout='undef')[source]

Write and read data to and from TCP link tcp_id

cmd_tcp.wrnrd_bin_tcp(tcp_id, data, bytes_to_read, timeout='undef')[source]

Write and read binary data to and from TCP link tcp_id. data is a string where each character represents 4 bits in hexadecimal base. Little endian for each group of 8 bits.

cmd_tcp.wrnrd_until_tcp(tcp_id, data, eot, timeout='undef')[source]

Write and read data to and from TCP link tcp_id until a character from comma-separated list eot is found

cmd_tcp.wrnrd_bin_until_tcp(tcp_id, data, eot, timeout='undef')[source]

Write and read data to and from TCP link tcp_id until a character from comma-separated list eot is found. data is a string where each character represents 4 bits in hexadecimal base. Little endian for each group of 8 bits. Read data is return in the same format.

cmd_tcp.expect_tcp(tcp_id, pattern, timeout='undef')[source]

Read data from TCP link tcp_id until pattern is found or timeout.