Hardware Client
Abstract class to establish a simple connection to a remote hardware device (client).
Protocol is based on a set of commands and attributes (loosely related to Tango commands and attributes). An attribute is a property which can be read and optionally written. A command is an action performed by the client, optionally using paramenters. Both commands and attribute requests always return a response, in a form of a JSON encoded structure. This in turn is translated to a dictionary and returned to the request initiator.
The client implements a fixed set of commands and attributes. An attribute is read-only or read-write, in a fixed way.
Commands may be synchronous or asynchronous. Synchronous commands complete the required operation and return in a short time (typ less than 1 second). Asynchronous commands start a separate thread. All requests to the device fail if the command is still active, except the “abort_command” command, which aborts it and the “command_completed” command, which returns the completion status as a Bool value.
- Response dictionary for commands:
status: OK, ERROR, or STARTED (for async commands)
info: textual description of the command result/error
command: the command name
retvalue: returned value, if any
Attributes can be read and written. Write to a read-only attribute fails. All attribute operations are synchronous.
- Response dictionary for attributes:
status: OK, ERROR
info: textual description of the operation result/error
attribute: the attribute name
value: returned value, if any
Commands “list_commands” and “list_attributes” are always implemented, and return a list of the available command/attribute names.
- class AttributeResponseType
- class CommandResponseType
- class HardwareClient(ip_address, port=80)
An abstract client to establish a connection to hardware.
This must be subclassed to establish the actual network protocol.
- __init__(ip_address, port=80)
Create a new instance.
- connect()
Check if connected and establish a connection with the client.
If this is not possible, returns None.
None if no connection available, True if connection OK
- execute_command(command, parameters='')
Execute the command.
- Parameters:
- Return type:
- Returns:
dictionary with execute_command result
- get_attribute(attribute)
Get the attribute from the device.
- Parameters:
attribute (
str
) – Name of attribute to get- Return type:
- Returns:
dictionary with get_attribute method result
- set_attribute(attribute, value)
Set the attribute value.
- Parameters:
- Return type:
- Returns:
dictionary with set_attribute method result
- class WebHardwareClient(ip_address, port=80)
Implementation of the HardwareClient protocol using a HTTP-based interface.
- connect()
Nominally establish a connection with the client.
However this implementation is based on HTTP, which is connectionless, so this method is essentially unimplemented. It always returned True.
- Return type:
- Returns:
True
- disconnect()
Nominally, disconnect from the client.
However this implementation is based on HTTP, which is connectionless, so this method is implemented to do nothing.
- Return type:
- execute_command(command, parameters='')
Execute a named command, with or without parameters.
- Parameters:
- Return type:
- Returns:
dictionary with command result
- get_attribute(attribute)
Read the value associated to a named attribute.
- Parameters:
attribute (
str
) – Name of attribute to be read- Return type:
- Returns:
result of the attribute command
- set_attribute(attribute, value)
Set the value associated to a named attribute.
- Parameters:
- Return type:
- Returns:
result of the attribute command