nspyre.instrument.server

This module provides a wrapper around an RPyC server. Clients may connect and access devices, or command the server to add, remove, or restart devices.

Module Contents

Classes

InstrumentServer

RPyC service that loads devices and exposes them to the client.

Attributes

INSTRUMENT_SERVER_DEFAULT_PORT

Default instrument server port.

RPYC_SYNC_TIMEOUT

RPyC send/receive timeout in seconds (don't set to None).

nspyre.instrument.server.INSTRUMENT_SERVER_DEFAULT_PORT = 42068

Default instrument server port.

nspyre.instrument.server.RPYC_SYNC_TIMEOUT = 30

RPyC send/receive timeout in seconds (don’t set to None).

exception nspyre.instrument.server.InstrumentServerError(*args, **kwargs)

Raised for failures related to the InstrumentServer.

Parameters:
  • args – Arguments to pass to super class Exception().

  • kwargs – Keyword arguments to pass to super class Exception().

exception nspyre.instrument.server.InstrumentServerDeviceExistsError(*args, **kwargs)

Raised if attempting to add a device that already exists to the InstrumentServer.

Parameters:
  • args – Arguments to pass to super class Exception().

  • kwargs – Keyword arguments to pass to super class Exception().

class nspyre.instrument.server.InstrumentServer(port=INSTRUMENT_SERVER_DEFAULT_PORT, sync_timeout=RPYC_SYNC_TIMEOUT)

RPyC service that loads devices and exposes them to the client.

The RPyC service starts a new thread running an RPyC server. Clients may connect and access devices or command the server to add, remove, or restart devices (through the InstrumentGateway).

Parameters:
  • port (int) – Port number to use for the RPyC server.

  • sync_timeout (float) – Time to wait for requests / function calls to finish.

add(name, class_path, class_name, args=None, kwargs=None, import_or_file='file', local_args=False)

Create an instance of the specified class and add it to the instrument server.

Parameters:
  • name (str) – Alias for the device.

  • class_path (str) – If import_or_file is 'file', path to the file on the filesystem containing the class, e.g. '~/drivers/rohde_schwarz/hmp4040.py'. If import_or_file is 'import', python module containing the class, e.g. 'nspyre_drivers.rohde_schwarz.hmp4040.hmp4040'.

  • class_name (str) – Name of the class to create an instance of, e.g. 'HMP4040'.

  • args (Optional[list]) – Arguments to pass to class_name.__init__.

  • kwargs (Optional[Dict]) – Keyword arguments to pass to class_name.__init__..

  • import_or_file (str) – 'file' for creating the device object from a file on the filesystem, 'import' for creating the device object from a python module.

  • local_args (bool) – If True, all arguments to this method are assumed to be local variables not passed through an InstrumentGateway. In this case, the arguments will be taken as-is. If False, all arguments will be retrieved using rpyc.utils.classic.obtain in order to ensure they are not netrefs.

Raises:
remove(name)

Remove a device from the instrument server.

Parameters:

name (str) – Alias for the device.

Raises:

InstrumentServerError – Deleting the device failed.

restart(name)

Restart the specified device by deleting it and creating a new instance.

Parameters:

name (str) – Alias for the device.

Raises:

InstrumentServerError – Deleting the device failed.

restart_all()

Restart all devices on the server.

Raises:

InstrumentServerError – Deleting a device failed.

start()

Start the RPyC server.

Raises:

InstrumentServerError – The server was already running.

stop()

Stop the RPyC server.

Raises:

InstrumentServerError – The server wasn’t running.

devs()

Return all of the devices on the InstrumentSever.

Returns:

The device names as keys and device objects as values.

Return type:

dict

on_connect(conn)

Called when a client connects to the RPyC server.

Parameters:

conn (rpyc.core.protocol.Connection) –

on_disconnect(conn)

Called when a client disconnects from the RPyC server.

Parameters:

conn (rpyc.core.protocol.Connection) –