instrumentserver.client.proxy#

Created on Sat Apr 18 16:13:40 2020

@author: Chao

Classes

Client([host, port, connect, timeout, ...])

Client with common server requests as convenience functions.

ClientStation([host, port, connect, ...])

ProxyInstrument

alias of ProxyInstrumentModule

ProxyInstrumentModule(name, *args[, cli, ...])

Construct a proxy module using the given blueprint.

ProxyMixin(*args[, cli, host, port, ...])

A simple mixin class for proxy objects.

ProxyParameter(name, *args[, cli, host, ...])

Proxy for parameters.

QtClient([parent, host, port, connect, ...])

SubClient([instruments, sub_host, sub_port])

Specific subscription client used for real-time parameter updates.

class instrumentserver.client.proxy.Client(host='localhost', port=5555, connect=True, timeout=20, raise_exceptions=True)[source]#

Bases: BaseClient

Client with common server requests as convenience functions.

call(target, *args, **kwargs)[source]#
close_instrument(instrument_name: str)[source]#
find_or_create_instrument(name: str, instrument_class: str | None = None, *args: Any, **kwargs: Any) ProxyInstrumentModule[source]#

Looks for an instrument in the server. If it cannot find it, create a new instrument on the server. Returns a proxy for either the found or the new instrument.

Parameters:
  • name – Name of the new instrument.

  • instrument_class – Class of the instrument to create or a string of of the class.

  • args – Positional arguments for new instrument instantiation.

  • kwargs – Keyword arguments for new instrument instantiation.

Returns:

A new virtual instrument.

getBluePrint(path)[source]#

get blueprint from server :param path: :return:

getParamDict(instrument: str | None = None, attrs: List[str] = ['value'], *args, **kwargs)[source]#
get_instrument(name)[source]#
get_snapshot(instrument: str | None = None, *args, **kwargs)[source]#
invalidateBlueprint(path=None)[source]#

invalidate a parameter in the blueprint cache :param path: :return:

list_instruments() Dict[str, str][source]#

Get the existing instruments on the server.

paramsFromFile(filePath: str, instruments: List[str] | None = None)[source]#
paramsToFile(filePath: str, instruments: List[str] | None = None, *args, **kwargs)[source]#
setParameters(parameters: Dict[str, Any])[source]#
class instrumentserver.client.proxy.ClientStation(host='localhost', port=5555, connect=True, timeout=20, raise_exceptions=True, config_path: str | None = None, param_path: str | None = None)[source]#

Bases: object

close_instrument(instrument_name: str)[source]#
find_or_create_instrument(name: str, instrument_class: str | None = None, *args: Any, **kwargs: Any) ProxyInstrumentModule[source]#

Looks for an instrument in the server. If it cannot find it, create a new instrument on the server. Returns a proxy for either the found or the new instrument.

Parameters:
  • name – Name of the new instrument.

  • instrument_class – Class of the instrument to create or a string of of the class.

  • args – Positional arguments for new instrument instantiation.

  • kwargs – Keyword arguments for new instrument instantiation.

Returns:

A new virtual instrument.

get_instrument(name: str) ProxyInstrumentModule[source]#
get_parameters(*args, **kwargs)[source]#
load_parameters(*args, **kwargs)[source]#
save_parameters(*args, **kwargs)[source]#
set_parameters(*args, **kwargs)[source]#
instrumentserver.client.proxy.ProxyInstrument#

alias of ProxyInstrumentModule

class instrumentserver.client.proxy.ProxyInstrumentModule(name: str, *args, cli: Client | None = None, host: str | None = 'localhost', port: int | None = 5555, remotePath: str | None = None, bluePrint: InstrumentModuleBluePrint | None = None, **kwargs)[source]#

Bases: ProxyMixin, InstrumentBase

Construct a proxy module using the given blueprint. Each proxy instantiation represents a virtual module (instrument of submodule of instrument).

Parameters:
  • bluePrint – The blueprint that the describes the module.

  • host – The name of the host where the server lives.

  • port – The port number of the server.

add_parameter(name: str, *arg, **kw)[source]#

Add a parameter to the proxy instrument.

If a parameter of that name already exists in the server-side instrument, we only add the proxy parameter. If not, we first add the parameter to the server-side instrument, and then the proxy here.

initKwargsFromBluePrint(bp)[source]#
remove_parameter(name: str, *arg, **kw)[source]#

Removes parameter from the proxy instrument.

Checking whether the paremeter exists or not is left to the instrument in the server. This is to avoid having to check on every submodule for the parameter manager.

set_parameters(**param_dict: dict)[source]#

Set instrument parameters in batch with a dict, keyed by parameter names.

update()[source]#
class instrumentserver.client.proxy.ProxyMixin(*args, cli: Client | None = None, host: str | None = 'localhost', port: int | None = 5555, remotePath: str | None = None, bluePrint: ParameterBluePrint | InstrumentModuleBluePrint | MethodBluePrint | None = None, **kwargs)[source]#

Bases: object

A simple mixin class for proxy objects.

askServer(message: ServerInstruction)[source]#
get_snapshot(*args, **kwargs)[source]#
initKwargsFromBluePrint(bp)[source]#
class instrumentserver.client.proxy.ProxyParameter(name: str, *args, cli: Client | None = None, host: str | None = 'localhost', port: int | None = 5555, remotePath: str | None = None, bluePrint: ParameterBluePrint | None = None, setpoints_instrument: Instrument | None = None, **kwargs)[source]#

Bases: ProxyMixin, Parameter

Proxy for parameters.

Parameters:
  • cli – Instance of Client.

  • name – The parameter name.

  • host – The name of the host where the server lives.

  • port – The port number of the server.

  • remotePath – Path of the remote object on the server.

  • bluePrint – The blue print to construct the proxy parameter. If remotePath and bluePrint are both supplied, the blue print takes priority.

initKwargsFromBluePrint(bp)[source]#
class instrumentserver.client.proxy.QtClient(parent=None, host='localhost', port=5555, connect=True, timeout=5, raise_exceptions=True)[source]#

Bases: _QtAdapter, Client

class instrumentserver.client.proxy.SubClient(instruments: List[str] | None = None, sub_host: str = 'localhost', sub_port: int = 5556)[source]#

Bases: QObject

Specific subscription client used for real-time parameter updates.

connect()[source]#

Connects the subscription client with the broadcast and runs an infinite loop to check for updates.

It should always be run on a separate thread or the program will get stuck in the loop.

disconnect()[source]#

Alias for stop() for backwards compatibility.

finished#

Signal emitted when the listener finishes (for proper cleanup)

stop()[source]#

Stops the listener gracefully.

update#

Signal(ParameterBroadcastBluePrint) – emitted when the server broadcast either a new parameter or an update to an existing one.