msl.equipment.vxi11 module

Implementation of the VXI-11 protocol.

VXI-11 is a client-service model to send messages through a network. The messages are formatted using the Remote Procedure Call protocol [RFC-1057] and are encoded/decoded using the eXternal Data Representation standard [RFC-1014].

References

  • VXI-11TCP/IP Instrument Protocol Specification (Revision 1.0), VXIbus Consortium, July 1995.

  • RFC-1057RPC: Remote Procedure Call Protocol Specification (Version 2), Sun Microsystems, June 1988.

  • RFC-1014XDR: External Data Representation Standard, Sun Microsystems, June 1987.

class msl.equipment.vxi11.OperationFlag(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

VXI-11: Additional information concerning how a request is carried out.

NULL = 0
WAITLOCK = 1
END = 8
TERMCHRSET = 128
class msl.equipment.vxi11.MessageType(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

RPC: The message type.

CALL = 0
REPLY = 1
class msl.equipment.vxi11.ReplyStatus(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

RPC: Message reply status.

MSG_ACCEPTED = 0
MSG_DENIED = 1
class msl.equipment.vxi11.AcceptStatus(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

RPC: Message accepted status.

SUCCESS = 0
PROG_UNAVAIL = 1
PROG_MISMATCH = 2
PROC_UNAVAIL = 3
GARBAGE_ARGS = 4
class msl.equipment.vxi11.RejectStatus(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

RPC: Message rejected status.

RPC_MISMATCH = 0
AUTH_ERROR = 1
class msl.equipment.vxi11.AuthStatus(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

RPC: Authorization status.

AUTH_BADCRED = 1
AUTH_REJECTEDCRED = 2
AUTH_BADVERF = 3
AUTH_REJECTEDVERF = 4
AUTH_TOOWEAK = 5
class msl.equipment.vxi11.RPCClient(host)[source]

Bases: object

Remote Procedure Call implementation for a client.

Parameters:

host (str) – The hostname or IP address of the remote device.

append(data)[source]

Append data to the body of the current RPC message.

Parameters:

data (bytes or memoryview) – The data to append.

append_opaque(text)[source]

Append a variable-length string to the body of the current RPC message.

Parameters:

text (memoryview, bytes or str) – The data to append.

property chunk_size

The maximum number of bytes to receive at a time from the socket.

Type:

int

close()[source]

Close the RPC socket, if one is open.

connect(port, timeout=10)[source]

Connect to a specific port on the device.

Parameters:
  • port (int) – The port number to connect to.

  • timeout (float or None, optional) – The maximum number of seconds to wait for the connection to be established.

get_buffer()[source]

Get the data in the buffer.

Returns:

bytearray – The data in the current RPC message.

get_port(prog, vers, prot, timeout=10)[source]

Call the Port Mapper procedure to determine which port to use for a program.

This method will automatically open and close the socket connection.

Parameters:
  • prog (int) – The program number to get the port number of.

  • vers (int) – The version number of prog.

  • prot (int) – The socket protocol family type to use when sending requests to prog (IPPROTO_TCP or IPPROTO_UDP).

  • timeout (float or None, optional) – The maximum number of seconds to wait to get the port value.

Returns:

int – The port number that corresponds to prog.

init(prog, vers, proc)[source]

Construct a new RPC message.

Parameters:
  • prog (int) – The program number.

  • vers (int) – The version number of program.

  • proc (int) – The procedure number within the program to be called.

interrupt_handler()[source]

Override this method to be notified of a service interrupt.

This method gets called if an interrupt is received during a read(). It does not continuously poll the device.

read()[source]

Read an RPC message, check for errors, and return the procedure-specific data.

Returns:

memoryview – The procedure-specific data.

set_timeout(timeout)[source]

Set the socket timeout value.

Parameters:

timeout (float) – The timeout, in seconds, to use for the socket.

property socket

The reference to the socket.

Type:

socket

static unpack_opaque(data)[source]

Unpack and return a variable-length string.

Parameters:

data (bytes, bytearray or memoryview) – The data to unpack.

Returns:

bytes, bytearray or memoryview – The unpacked data.

write()[source]

Write the RPC message that is in the buffer.

check_reply(message)[source]

Checks the message for errors and returns the procedure-specific data.

Parameters:

message (memoryview) – The reply from an RPC message.

Returns:

memoryview or None – The reply or None if the transaction id does not match the value that was used in the corresponding write() call.

class msl.equipment.vxi11.VXIClient(host)[source]

Bases: RPCClient

Base class for a VXI-11 program.

Parameters:

host (str) – The hostname or IP address of the remote device.

read_reply()[source]

Check the RPC message for an error and return the remaining data.

Returns:

memoryview – The reply data.

class msl.equipment.vxi11.CoreClient(host)[source]

Bases: VXIClient

Communicate with the Device Core program on the remote device.

Parameters:

host (str) – The hostname or IP address of the remote device.

Create a link.

Parameters:
  • device (bytes or str) – Name of the device to link with.

  • lock_device (bool) – Whether to attempt to lock the device.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

Returns:

device_write(lid, io_timeout, lock_timeout, flags, data)[source]

Write data to the specified device.

Parameters:
  • lid (int) – Link id from create_link().

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • flags (int or OperationFlag) – Operation flags to use.

  • data (memoryview, bytes or str) – The data to write.

Returns:

int – The number of bytes written.

device_read(lid, request_size, io_timeout, lock_timeout, flags, term_char)[source]

Read data from the device.

Parameters:
  • lid (int) – Link id from create_link().

  • request_size (int) – The number of bytes requested.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • flags (int or OperationFlag) – Operation flags to use.

  • term_char (int) – The termination character. Valid only if flags is TERMCHRSET.

Returns:

  • int – The reason(s) the read completed.

  • memoryview – A view of the data (the RPC header is removed).

device_readstb(lid, flags, lock_timeout, io_timeout)[source]

Read the status byte from the device.

Parameters:
  • lid (int) – Link id from create_link().

  • flags (int or OperationFlag) – Operation flags to use.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

Returns:

int – The status byte.

device_trigger(lid, flags, lock_timeout, io_timeout)[source]

Send a trigger to the device.

Parameters:
  • lid (int) – Link id from create_link().

  • flags (int or OperationFlag) – Operation flags to use.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

device_clear(lid, flags, lock_timeout, io_timeout)[source]

Send the clear command to the device.

Parameters:
  • lid (int) – Link id from create_link().

  • flags (int or OperationFlag) – Operation flags to use.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

device_remote(lid, flags, lock_timeout, io_timeout)[source]

Place the device in a remote state wherein all programmable local controls are disabled.

Parameters:
  • lid (int) – Link id from create_link().

  • flags (int or OperationFlag) – Operation flags to use.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

device_local(lid, flags, lock_timeout, io_timeout)[source]

Place the device in a local state wherein all programmable local controls are enabled.

Parameters:
  • lid (int) – Link id from create_link().

  • flags (int or OperationFlag) – Operation flags to use.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

device_lock(lid, flags, lock_timeout)[source]

Acquire a device’s lock.

Parameters:
device_unlock(lid)[source]

Release a lock acquired by device_lock().

Parameters:

lid (int) – Link id from create_link().

device_enable_srq(lid, enable, handle)[source]

Enable or disable the sending of device_intr_srq RPCs by the network instrument server.

Parameters:
  • lid (int) – Link id from create_link().

  • enable (bool) – Whether to enable or disable interrupts.

  • handle (bytes) – Host specific data (maximum length is 40 characters).

device_docmd(lid, flags, io_timeout, lock_timeout, cmd, network_order, datasize, data_in)[source]

Allows for a variety of operations to be executed.

Parameters:
  • lid (int) – Link id from create_link().

  • flags (int or OperationFlag) – Operation flags to use.

  • io_timeout (int) – Time, in milliseconds, to wait for I/O to complete.

  • lock_timeout (int) – Time, in milliseconds, to wait on a lock.

  • cmd (int) – Which command to execute.

  • network_order (bool) – Client’s byte order.

  • datasize (int) – Size of individual data elements.

  • data_in (bytes or str) – Data input parameters.

Returns:

bytes – The results defined by cmd.

Destroy the link.

Parameters:

lid (int) – Link id from create_link().

create_intr_chan(host_addr, host_port, prog_num, prog_vers, prog_family)[source]

Inform the network instrument server to establish an interrupt channel.

Parameters:
  • host_addr (int) – Host servicing the interrupt.

  • host_port (int) – Valid port number on the client.

  • prog_num (int) – Program number.

  • prog_vers (int) – Program version number.

  • prog_family (int) – The underlying socket protocol family type (IPPROTO_TCP or IPPROTO_UDP).

destroy_intr_chan()[source]

Inform the network instrument server to close its interrupt channel.

class msl.equipment.vxi11.AsyncClient(host)[source]

Bases: VXIClient

Communicate with the Device Async program on the remote device.

Parameters:

host (str) – The hostname or IP address of the remote device.

device_abort(lid)[source]

Stops an in-progress call.

Parameters:

lid (int) – Link id from create_link().

msl.equipment.vxi11.find_vxi11(*, ip: list[str] | None = None, timeout: float = 1) dict[str, dict[str, str | list[str]]][source]

Find all VXI-11 devices that are on the network.

The RPC port-mapper protocol (RFC-1057, Appendix A) broadcasts a message via UDP to port 111 for VXI-11 device discovery.

Parameters:
  • ip – The IP address(es) on the local computer to use to broadcast the discovery message. If not specified, broadcast on all network interfaces.

  • timeout – The maximum number of seconds to wait for a reply.

Returns:

The information about the VXI-11 devices that were found.