Server Control#
Establishing a connection#
The communication with the server is done through a websocket. One can call connect()
and disconnect()
. It is also possible to use connect()
in a with
block
- ScrutinyClient.connect(hostname, port, wait_status=True)[source]#
Connect to a Scrutiny server through a TCP socket.
- Parameters:
hostname (str) – The hostname or ip address of the server
port (int) – The listening port of the server
wait_status (bool) – Wait for a server status update after the socket connection is established. Ensure that a value is available when calling
get_server_status()
- Raises:
ConnectionError – In case of failure
- Return type:
Example#
with client.connect('localhost', 1234):
pass # Do something
# disconnect automatically called
Getting the server status#
Upon establishing a connection with a client, and at regular intervals thereafter, the server broadcasts a status. This status is a data structure that encapsulates all the pertinent information about what is happening at the other end of the websocket. It includes:
The type of connection used by the device
Details about the device if one is connected
The state of the datalogger within the device
The loaded SFD and its metadata if any
etc.
- ScrutinyClient.get_server_status()[source]#
- Returns an immutable structure of data containing the latest server status that has been broadcast.
It contains everything going on the server side
- Raises:
ConnectionError – If the connection to the server is lost
InvalidValueError – If the server status is not available (never received it).
- Return type:
- ScrutinyClient.wait_server_status_update(timeout=2.5)[source]#
Wait for the server to broadcast a status update. Happens periodically
- Parameters:
timeout (float) – Amount of time to wait for the update
- Raises:
TypeError – Given parameter not of the expected type
ValueError – Given parameter has an invalid value
TimeoutException – Server status update did not occurred within the timeout time
- Return type:
None
- ScrutinyClient.wait_device_ready(timeout)[source]#
Wait for a device to be connected to the server and have finished its handshake.
- Parameters:
timeout (float) – Amount of time to wait for the device
- Raises:
TypeError – Given parameter not of the expected type
ValueError – Given parameter has an invalid value
InvalidValueError – If the watchable becomes invalid while waiting
TimeoutException – If the device does not become ready within the required timeout
- Return type:
None
- class scrutiny.sdk.ServerInfo[source]#
(Immutable struct) A summary of everything going on on the server side. Status broadcast by the server to every client.
- device_comm_state: DeviceCommState#
Status of the communication between the server and the device
- device_session_id: str | None#
A unique ID created each time a communication with the device is established.
None
when no communication with a device.
- device: DeviceInfo | None#
Information about the connected device.
None
if no device is connected
- datalogging: DataloggingInfo#
Datalogging state
- sfd: SFDInfo | None#
The Scrutiny Firmware Description file actually loaded on the server.
None
if none is loaded
- device_link: DeviceLinkInfo#
Communication channel presently used to communicate with the device
- class scrutiny.sdk.DeviceCommState[source]#
(Enum) The state of the connection with the device
- Disconnected = 1#
No device connected
- Connecting = 2#
Handshake in progress between the server and the device
- ConnectedReady = 3#
A device is connected and ready to respond to queries.
- class scrutiny.sdk.DeviceInfo[source]#
(Immutable struct) Information about the device connected to the server
- device_id: str#
A unique ID identifying the device and its software (Firmware ID).
- display_name: str#
The display name broadcast by the device
- max_tx_data_size: int#
Maximum payload size that the device can send
- max_rx_data_size: int#
Maximum payload size that the device can receive
- max_bitrate_bps: int | None#
Maximum bitrate between the device and the server. Requested by the device.
None
if no throttling is requested
- rx_timeout_us: int#
Amount of time without data being received that the device will wait to restart its reception state machine (new frame)
- heartbeat_timeout: float#
Timeout value without heartbeat message response to consider that the communication is broken
- address_size_bits: Literal[8, 16, 32, 64, 128]#
Address size in the device
- protocol_major: int#
Device communication protocol version (major number)
- protocol_minor: int#
Device communication protocol version (minor number)
- supported_features: SupportedFeatureMap#
Features supported by the device
- forbidden_memory_regions: List[MemoryRegion]#
List of memory region that cannot be access
- readonly_memory_regions: List[MemoryRegion]#
List of memory region that are read-only
- class scrutiny.sdk.DeviceLinkInfo[source]#
(Immutable struct) Represent a communication link between the server and a device
- type: DeviceLinkType#
Type of communication channel between the server and the device
- config: UDPLinkConfig | TCPLinkConfig | SerialLinkConfig | None#
A channel type specific configuration
- class scrutiny.sdk.SupportedFeatureMap[source]#
(Immutable struct) Represent the list of features that the connected device supports
- memory_write: bool#
Indicates if the device allows write to memory
- datalogging: bool#
Indicates if the device is able of doing datalogging
- user_command: bool#
Indicates if the device has a callback set for the user command
- sixtyfour_bits: bool#
Indicates if the device supports 64bits element. 64bits RPV and datalogging of 64bits elements (variable or RPV) are not possible if False. Watching 64 bits variables does not depends on the device and is therefore always possible
- class scrutiny.sdk.MemoryRegion[source]#
(Immutable struct) Represent a memory region spanning from
start
tostart+size-1
- start: int#
Start address of the region
- size: int#
Size in bytes of the region
- class scrutiny.sdk.DataloggingInfo[source]#
(Immutable struct) Information about the datalogger that are volatile
- state: DataloggerState#
The state of the datalogger in the device
- completion_ratio: float | None#
The completion ratio of the actually running acquisition.
None
if no acquisition being captured
- class scrutiny.sdk.DataloggerState[source]#
(Enum) The state in which the C++ datalogger inside the device firmware actually is
- NA = 0#
The state is not available
- Standby = 1#
The datalogger is doing nothing
- WaitForTrigger = 2#
The datalogger is logging and actively monitor for the trigger condition to end the acquisition
- Acquiring = 3#
The datalogger is actively logging and the acquisition is ending since the trigger event has been fired
- DataReady = 4#
The datalogger has finished logging and data is ready to be read
- Error = 5#
The datalogger has encountered a problem and is not operational
Configuring the device link#
The device link is the communication channel between the server and the device.
This link can be configured by the client. If a device is present, the server will automatically connect to it. If no device is found, the server will simply report that no device is connected
- ScrutinyClient.configure_device_link(link_type, link_config)[source]#
Configure the communication link between the Scrutiny server and the device remote device. If the link is configured in a way that a Scrutiny device is accessible, the server will automatically connect to it and inform the client about it. The client.server.server_state.device_comm_state will reflect this.
- Parameters:
link_type (DeviceLinkType) – Type of communication link to use. Serial, UDP, TCP, etc.
link_config (BaseLinkConfig | None) – A configuration object that matches the link type.
UDP
:UDPLinkConfig
/TCP
:TCPLinkConfig
/Serial
:SerialLinkConfig
- Raises:
ValueError – Bad parameter value
TypeError – Given parameter not of the expected type
OperationFailure – If the request to the server fails
- Return type:
None
- class scrutiny.sdk.DeviceLinkType[source]#
(Enum) The type of communication link used between the server and the device
- UDP = 1#
UDP/IP socket
- TCP = 2#
TCP/IP Socket
- Serial = 3#
Serial port
- class scrutiny.sdk.TCPLinkConfig[source]#
(Immutable struct)The configuration structure for a device link of type
TCP
- host: str#
Target device hostname
- port: int#
Device TCP port number
- class scrutiny.sdk.UDPLinkConfig[source]#
(Immutable struct) The configuration structure for a device link of type
UDP
- host: str#
Target device hostname
- port: int#
Device UDP port number
- class scrutiny.sdk.SerialLinkConfig[source]#
(Immutable struct) The configuration structure for a device link of type
Serial
- baudrate: int#
Communication speed in baud/sec
- databits: Literal[5, 6, 7, 8] = 8#
Number of data bits. 5, 6, 7, 8
- parity: Literal['none', 'even', 'odd', 'mark', 'space'] = 'none'#
Serial communication parity bits
- port: str#
Port name on the machine. COMX on Windows. /dev/xxx on posix platforms
- stopbits: Literal['1', '1.5', '2'] = '1'#
Number of stop bits. 1, 1.5, 2