pydhsfw package

Submodules

pydhsfw.automl module

class pydhsfw.automl.AutoMLClientConnection(connection_name: str, url: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = {})

Bases: pydhsfw.connection.ConnectionBase

Overrides ConnectionBase and creates a GCP AutoML connection

class pydhsfw.automl.AutoMLClientTransport(connection_name: str, url: str, config: dict = {})

Bases: pydhsfw.http.HttpClientTransport

Overrides HttpClientTransport and handles message reading and writing

class pydhsfw.automl.AutoMLMessageFactory

Bases: pydhsfw.messages.MessageFactory

class pydhsfw.automl.AutoMLPredictRequest(key: str, image: bytes)

Bases: pydhsfw.http.PostJsonRequestMessage

Formats a json data package and sends to the GCP AutoML server for prediction.

class pydhsfw.automl.AutoMLPredictResponse(response)

Bases: pydhsfw.http.JsonResponseMessage

Parses the response json file and stores various values the top hit in class properties.

property bb_maxX
property bb_maxY
property bb_minX
property bb_minY
get_score(n: int) → float

Returns the AutoML inference score for the Nth object in a sorted results list

property image_key
property top_bb

Object bounding box returned from AutoML minY, minX, maxY, maxX

origin in upper left corner of image.

(0,0)———————-> (1,0) X-axis | | | | v (0,1) Y-axis

property top_classification
property top_score

pydhsfw.axis module

class pydhsfw.axis.AxisClientConnection(connection_name: str, url: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = {})

Bases: pydhsfw.connection.ConnectionBase

Overrides ConnectionBase and creates an HTTP Axis connection

class pydhsfw.axis.AxisClientTransport(connection_name: str, url: str, config: dict = {})

Bases: pydhsfw.http.HttpClientTransport

Overrides HttpClientTransport and handles message reading and writing

class pydhsfw.axis.AxisImageRequestMessage(camera: str)

Bases: pydhsfw.http.GetRequestMessage

class pydhsfw.axis.AxisImageResponseMessage(response)

Bases: pydhsfw.http.FileResponseMessage

class pydhsfw.axis.AxisMessageFactory

Bases: pydhsfw.messages.MessageFactory

pydhsfw.connection module

class pydhsfw.connection.Connection(connection_name: str, url: str, config: dict = {})

Bases: object

connect()
disconnect()
send(msg: pydhsfw.messages.MessageOut)

DO docstrings show stuff in MS VSCODE When I hover over the command?

shutdown()
wait()
class pydhsfw.connection.ConnectionBase(connection_name: str, url: str, transport: pydhsfw.transport.Transport, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, message_factory: pydhsfw.messages.MessageFactory, config: dict = {})

Bases: pydhsfw.connection.Connection

connect()
disconnect()
send(msg: pydhsfw.messages.MessageOut)

DO docstrings show stuff in MS VSCODE When I hover over the command?

shutdown()
wait()
class pydhsfw.connection.ConnectionConnectedMessage(msg)

Bases: pydhsfw.connection.ConnectionMessage

class pydhsfw.connection.ConnectionDisconnectedMessage(msg)

Bases: pydhsfw.connection.ConnectionMessage

class pydhsfw.connection.ConnectionMessage(msg)

Bases: pydhsfw.messages.MessageIn

get_msg()
class pydhsfw.connection.ConnectionReadWorker(connection_name: str, transport: pydhsfw.transport.Transport, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, message_factory: pydhsfw.messages.MessageFactory, config: dict = {})

Bases: pydhsfw.threads.AbortableThread

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class pydhsfw.connection.ConnectionRegistry

Bases: object

class pydhsfw.connection.ConnectionShutdownMessage(msg)

Bases: pydhsfw.connection.ConnectionMessage

class pydhsfw.connection.ConnectionWriteWorker(connection_name: str, transport: pydhsfw.transport.Transport, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = {})

Bases: pydhsfw.threads.AbortableThread

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class pydhsfw.connection.MessageReader

Bases: object

read()
pydhsfw.connection.register_connection(connection_scheme: str)

pydhsfw.connectionmanager module

class pydhsfw.connectionmanager.ConnectionFactory

Bases: object

create_connection(connection_name: str, scheme: str, url: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = None)pydhsfw.connection.Connection
class pydhsfw.connectionmanager.ConnectionManager

Bases: object

create_connection(name: str, scheme: str, url: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = {})pydhsfw.connection.Connection

Create a connection connection that has been registered.

Create a connection that has been registered with @register_connection

name - Name of the connection instance. This must be unique to each connection that is created. The name is used to retrieve the connection instance using get_connection().

scheme - Type of connection to create. The available connection schemes are based on all connections that were registered using @register_connection

url - Url that the connection will used when connecting to a resource.

get_connection(name: str)pydhsfw.connection.Connection
load_registry()
shutdown_connections()
start_connections()
wait_connections()

pydhsfw.dcss module

class pydhsfw.dcss.DcssActiveOperation(operation_name: str, operation_handle: str, start_operation_message: pydhsfw.dcss.DcssStoHStartOperation)

Bases: object

Storage class for active operations.

Active operations that are currently underway have information stored in this class. It stores the operation name, operation handle, start operation message, and a DHS implementation placeholder property called state that implementer can use to store whatever they need for the duration of the operation.

This class is created and stored in the active operations list when a dcss stoh_start_operation message is received. It is removed, along with state allocations mentioned above, when the DHS responds with the htos_operation_completed message. After the call, the active operation and state is no longer available.

property operation_handle
property operation_name
property operation_state
property start_operation_message
class pydhsfw.dcss.DcssActiveOperations

Bases: object

Stores a list of active operations that are currently in progress

add_operation(operation: pydhsfw.dcss.DcssActiveOperation)
get_operations(operation_name: str = None, operation_handle=None)
remove_operation(operation: pydhsfw.dcss.DcssActiveOperation)
remove_operations(operations: list)
class pydhsfw.dcss.DcssClientConnection(connection_name: str, url: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = {})

Bases: pydhsfw.connection.ConnectionBase

class pydhsfw.dcss.DcssClientTransport(connection_name: str, url: str, config: dict = {})

Bases: pydhsfw.tcpip.TcpipClientTransport

class pydhsfw.dcss.DcssContext(active_operations: pydhsfw.dcss.DcssActiveOperations)

Bases: pydhsfw.processors.Context

get_active_operation_names()
get_active_operations(operation_name: str = None, operation_handle=None)pydhsfw.dcss.DcssActiveOperation

Retrieve active operations that match the name and/or handle.

operation_name - Get all active operations that match that name. None acts as a wildcard. operation_handle - Get all active operations that match that handle. None acts as a wildcard.

Note: To get active operations pas in None for name and handle. To be specific you can match both name and handle.

class pydhsfw.dcss.DcssDhsV1MessageReader

Bases: pydhsfw.transport.MessageStreamReader

Class for reading a dcs version 1 message.

The dcs version 1 messages are always exactly 200 bytes long. When a DHS initially connects to DCSS the first messaeg received is always version 1.

read_msg(stream_reader: pydhsfw.transport.StreamReader) → bytes

Read the raw bytes of an entire message from a stream.

The underlying message packets may be a fixed length, or end in a delimeter, or have a message header that describes size. The derived class is responsible for implementing the specific requirements for message decoding.

class pydhsfw.dcss.DcssDhsV1MessageWriter

Bases: pydhsfw.transport.MessageStreamWriter

Class for writing a DCS version 1 message.

The DCS version 1 messages are always exactly 200 bytes long. When a DHS initially connects to DCSS the first messaeg received is always version 1. It is expected that the first message sent back will also be version 1 message.

write_msg(stream_writer: pydhsfw.transport.StreamWriter, msg: bytes)

Write the message to the stream writer.

The message packets may need to be padded to a fixed length, or require a delimeter to be added, or may require packing in a message header that includes the message size. The derived class is responsible for the particulars of the message encoding.

class pydhsfw.dcss.DcssDhsV2MessageReaderWriter

Bases: pydhsfw.transport.MessageStreamReader, pydhsfw.transport.MessageStreamWriter

Class to read and write DCS version 2 messages.

The DCS version 2 messages can be any length. Each DCS message must start with 26 bytes of text message. These 26 bytes must contain a 2 numbers is ASCII format. The two numbers indicate the size of the text section (in bytes) and binary section (in bytes). The text message must contain a terminating 0 at the end of the two numbers. This allows a library to simply use the scanf function to obtain the two numbers. An example header may look like this:

1

2

3

5

2

3

2

5

0x00

The first number in this example indicates that there are 1235 bytes of text following the header. The second number in this string indicates that there are 2325 bytes of binary data following the 1235 bytes of text. The 0x00 terminates the header.

DCSS does not currently support the binary portion of the DCS message completely. In other words, the binary message should always be 0 for messages passed from DHS to DCSS.

The binary portion of the message is currently only used for sending the authentication key to Blu-Ice during the authentication stage made during the initial connection of Blu-Ice to DCSS.

read_msg(stream_reader: pydhsfw.transport.StreamReader) → bytes

Read the raw bytes of an entire message from a stream.

The underlying message packets may be a fixed length, or end in a delimeter, or have a message header that describes size. The derived class is responsible for implementing the specific requirements for message decoding.

write_msg(stream_writer: pydhsfw.transport.StreamWriter, msg: bytes)

Write the message to the stream writer.

The message packets may need to be padded to a fixed length, or require a delimeter to be added, or may require packing in a message header that includes the message size. The derived class is responsible for the particulars of the message encoding.

class pydhsfw.dcss.DcssHtoSClientIsHardware(dhs_name: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Client Is Hardware

This should be sent by all hardware servers in response to stoc_send_client_type message from DCSS.

The format of the message is:

htos_client_is_hardware dhs_name
Parameters

dhs_name (str) – The name of a hardware server listed within the database.dat file as described in DHS entry definition

class pydhsfw.dcss.DcssHtoSConfigureDevice(device_name: str, device_settings: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Configure Device

This is the message received from DCSS requesting the DHS to configure a specific motor or pseudo motor. The format of the message can take one of two forms:

1. gtos_configure_device motorName position upperLimit lowerLimit lowerLimitOn upperLimitOn motorLockOn units
2. gtos_configure_device motorName position upperLimit lowerLimit scaleFactor speed acceleration backlash lowerLimitOn upperLimitOn motorLockOn backlashOn reverseOn

For the first form which is used to configure a pseudo motor the arguments are:

Parameters
  • motorName – is the name of the motor to configure.

  • position – is the scaled position of the motor.

  • upperLimit – is the upper limit for the motor in scaled units.

  • lowerLimit – is the lower limit for the motor in scaled units.

  • lowerLimitOn – is a boolean (0 or 1) indicating if the lower limit is enabled.

  • upperLimitOn – is a boolean (0 or 1) indicating if the upper limit is enabled.

  • motorLockOn – is a boolean (0 or 1) indicating if the motor is software locked.

For the second form which is used to configure a real motor the arguments are:

Parameters
  • motor – is the name of the motor to configure

  • position – is the scaled position of the motor

  • upperLimit – is the upper limit for the motor in scaled units

  • lowerLimit – is the lower limit for the motor in scaled units

  • scaleFactor – is the scale factor relating scaled units to steps for the motor

  • speed – is the slew rate for the motor in steps/sec

  • acceleration – is the acceleration time for the motor in seconds

  • backlash – is the backlash amount for the motor in steps

  • lowerLimitOn – is a boolean (0 or 1) indicating if the lower limit is enabled

  • upperLimitOn – is a boolean (0 or 1) indicating if the upper limit is enabled

  • motorLockOn – is a boolean (0 or 1) indicating if the motor is software locked

  • backlashOn – is a boolean (0 or 1) indicating if backlash correction is enabled

  • reverseOn – is a boolean (0 or 1) indicating if the motor direction is reversed

This command requests that the configuration of a real motor be changed. DCSS updates the device configuration in its internal database (database.dat) and forwards the message to the appropriate hardware server.

Note

WARNING! UNTESTED! This message should probably be two separate messages gtos_configure_real_motor and gtos_configure_pseudo_motor.

class pydhsfw.dcss.DcssHtoSGetEncoderCompleted(encoder_name: str, new_position: float, status: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Get Encoder Completed

class pydhsfw.dcss.DcssHtoSLimitHit(state: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Limit Hit

class pydhsfw.dcss.DcssHtoSLog(log_message: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Log

Parameters

log_message (str) – Message to log to DCSS

class pydhsfw.dcss.DcssHtoSMessage

Bases: pydhsfw.dcss.DcssMessageOut

class pydhsfw.dcss.DcssHtoSMotorCorrectStarted(state: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Motor Correct Started

Note

Not Implemented Yet!

class pydhsfw.dcss.DcssHtoSMotorMoveCompleted(motor_name: str, new_position: float, state: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Motor Move Completed

Indicates that the move on the specified motor is now complete. DCSS forwards this message to all GUI clients as a stog_motor_move_completed message.

The format of the message is:

htos_motor_move_completed motor_name new_position state
Parameters
  • motor_name (str) – The name of the motor that finished the move.

  • new_position (float) – The final position of the motor.

  • state (str) –

    The status of the motor with values as shown below.

    • normal indicates that the motor finished its commanded move successfully.

    • aborted indicates that the motor move was aborted.

    • moving indicates that the motor was already moving.

    • cw_hw_limit indicates that the motor hit the clockwise hardware limit.

    • ccw_hw_limit indicates that the motor hit the counter-clockwise hardware limit.

    • both_hw_limits indicates that the motor cable may be disconnected.

    • unknown indicates that the motor completed abnormally.

class pydhsfw.dcss.DcssHtoSMotorMoveStarted(motor_name: str, new_position: float)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Motor Move Started

This message indicates that the requested move of a motor has begun. This message is forwarded by DCSS to all GUI clients as a stog_motor_move_started message.

The format of the message is:

htos_motor_move_started motor_name new_position
Parameters
  • motor_name (str) – The name of the motor.

  • new_position (float) – The destination move of the motor.

class pydhsfw.dcss.DcssHtoSNote(note_message: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Note

Parameters

note_message (str) – Note to send to DCSS

class pydhsfw.dcss.DcssHtoSOperationCompleted(operation_name: str, operation_handle: float, operation_status: str, operation_args: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Operation Completed

The message is used to indicate that an operation has been completed by this hardware server.

The format of the message is:

htos_operation_completed operation_name operation_handle operation_status operation_args

Note

It is recommended that list of return arguments adhere to the overall DCS protocol (space separated tokens), but this can only be enforced by the writer of the operation handle.

Parameters
  • operation_name (str) – The name of the operation that completed.

  • operation_handle (float) – The unique value that indicates which instance of the operation completed.

  • operation_status (str) – Anything other than a normal in this field will indicate to DCSS and BLU-ICE that the operation failed, and this token will become the reason of failure.

  • operation_args (str) – This is a list of return values.

class pydhsfw.dcss.DcssHtoSOperationUpdate(operation_name: str, operation_handle: float, operation_args: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Operation Update

This message can be used to send small pieces of data to the GUI clients as progress is made on the operation. It can also be used to indicate to a calling GUI client that the operation cannot continue until the caller performs another task.

The message format is as follows:

htos_operation_update operation_name operation_handle operation_args
Parameters
  • operation_name (str) – The name of the operation that completed.

  • operation_handle (float) – The unique value that indicates which instance of the operation completed.

  • operation_args (str) – This is a list of return values.

Note

It is recommended that list of return arguments adhere to the overall DCS protocol (space separated tokens), but this can only be enforced by the writer of the operation handle.

class pydhsfw.dcss.DcssHtoSReportIonChamber(ion_chamber_time: float, ion_chamber_name: str, ion_chamber_counts: int)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Report Ion Chamber

This message reports the results of counting on one or more ion chambers in response to the stog_read_ion_chamber message. The first three arguments are mandatory. Additional ion chambers are reported by adding additional arguments. DCSS forwards this message to all GUI clients as stog_report_ion_chambers message.

The format of the message is:

htos_report_ion_chambers ion_chamber_time ion_chamber_name ion_chamber_counts [ion_chamber_name2 counts2 [ion_chamber_nameN ion_chamber_countsN]]
Parameters
  • ion_chamber_time (float) – The time in seconds over which counts were integrated.

  • ion_chamber_name (str) – The name of the first ion chamber read.

  • ion_chamber_counts (int) – The counts from the first ion chamber.

Note

This is untested.

class pydhsfw.dcss.DcssHtoSReportShutterState(shutter_name: str, shutter_state: str, result: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Report Shutter State

This message reports a change in the state of a shutter. This may occur as a result of handling the stoh_set_shutter_state command or during a timed exposure with automated shutter handling. DCSS forwards this message to all GUI clients as a stog_report_shutter_state message.

The format of the message is:

htos_report_shutter_state shutter_name state
Parameters
  • shutter_name (str) – The name of the shutter.

  • shutter_state (str) – The new state (open or closed).

  • result (str) – No idea?

class pydhsfw.dcss.DcssHtoSSendConfiguration(device_name: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Send Configuration

This message requests that the configuration of the specified device (as remembered by DCSS) be returned to this DHS. DCSS will respond with a stoh_configure_device message for the device. This message is not forwarded to the GUI clients.

The format of the message is:

htos_send_configuration device_name
Parameters

device_name (str) – The name of the device for which the configuration information is needed.

class pydhsfw.dcss.DcssHtoSSetEncoderCompleted(encoder_name: str, new_position: int, status: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Set Encoder Completed

class pydhsfw.dcss.DcssHtoSSetMotorMessage(motor_name: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Set Motor Message

class pydhsfw.dcss.DcssHtoSSetStringCompleted(string_name: str, string_status: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Set String Completed

Parameters
  • string_name (str) – The name of the string

  • string_status (str) – status?

class pydhsfw.dcss.DcssHtoSSimulatingDevice(state: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Simulating Device

Note

Not Implemented Yet!

class pydhsfw.dcss.DcssHtoSStartOperation(operation_name: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Start Operation

Parameters

operation_name (str) – The name of the operation this DHS is requesting DCSS to start.

class pydhsfw.dcss.DcssHtoSUpdateMotorPosition(motor_name: str, new_position: float, status: str)

Bases: pydhsfw.dcss.DcssHtoSMessage

Hardware To Server Update Motor Position

Update DCSS with current position of a motor.

Parameters
  • motor_name (str) – The name of the motor.

  • new_position (float) – The current position of the motor

  • status (str) –

    The status of the motor with values as shown below.

    • normal indicates that the motor finished its commanded move successfully.

    • aborted indicates that the motor move was aborted.

    • moving indicates that the motor was already moving.

    • cw_hw_limit indicates that the motor hit the clockwise hardware limit.

    • ccw_hw_limit indicates that the motor hit the counter-clockwise hardware limit.

    • both_hw_limits indicates that the motor cable may be disconnected.

    • unknown indicates that the motor completed abnormally.

class pydhsfw.dcss.DcssMessageFactory

Bases: pydhsfw.messages.MessageFactory

Class for parsing the messages from DCSS.

class pydhsfw.dcss.DcssMessageIn(split)

Bases: object

property args

DCSS command args

Type

str

property command

DCSS command name

Type

str

static parse_type_id(buffer: bytes)
class pydhsfw.dcss.DcssMessageOut

Bases: pydhsfw.messages.MessageOut

write() → bytes
class pydhsfw.dcss.DcssMessageQueueDispatcher(name: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, context: pydhsfw.processors.Context, active_operations: pydhsfw.dcss.DcssActiveOperations, config: dict = {})

Bases: pydhsfw.processors.MessageQueueDispatcher

process_message(message: pydhsfw.messages.MessageIn)
process_message_now(message: pydhsfw.messages.MessageIn)
start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class pydhsfw.dcss.DcssOperationHandlerRegistry

Bases: object

class pydhsfw.dcss.DcssOutgoingMessageQueue(active_operations: pydhsfw.dcss.DcssActiveOperations)

Bases: pydhsfw.messages.OutgoingMessageQueue

queue(message: pydhsfw.messages.MessageOut)
class pydhsfw.dcss.DcssStoCMessage(split)

Bases: pydhsfw.messages.MessageIn, pydhsfw.dcss.DcssMessageIn

classmethod parse(buffer: bytes)
class pydhsfw.dcss.DcssStoCSendClientType(split)

Bases: pydhsfw.dcss.DcssStoCMessage

The initial command received from DCSS.

The new DHS opens a socket connection to the hardware listening port on DCSS. DHS begins reading and handling messages sent from DCSS. DCSS will send a stoc_send_client_type to the DHS. The DHS has 1 second to respond with the following message:

htos_client_is_hardware dhsName

At this point DCSS will disconnect a DHS for the following reasons:

The DHS does not respond within 1 second. The DHS does not respond with the name of a DHS listed within the database.dat file. There is already a DHS connected with the same name as the DHS that is currently trying to connect.

class pydhsfw.dcss.DcssStoHAbortAll(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Abort All

This message requests that all operations either cease immediately or halt as soon as possible.

All motors are stopped and data collection begins shutting down and stopping detector activity. A single argument specifies how motors should be aborted. A value of hard indicates that motors should stop without decelerating. A value of soft indicates that motors should decelerate properly before stopping.

property abort_arg

Either ‘hard’ or ‘soft’ e.g. htos_abort_all [hard | soft]

class pydhsfw.dcss.DcssStoHConfigurePseudoMotor(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Configure Pseudo Motor

This message is sent from DCSS to configure a pseudo motor.

property motor_lowerLimit

The lower limit for the motor in scaled units.

property motor_lowerLimitOn

A boolean (0 or 1) indicating if the lower limit is enabled.

property motor_motorLockOn

A boolean (0 or 1) indicating if the motor is software locked.

property motor_name

The name of the motor to configure.

property motor_position

The scaled position of the motor.

property motor_upperLimit

The upper limit for the motor in scaled units.

property motor_upperLimitOn

A boolean (0 or 1) indicating if the upper limit is enabled.

class pydhsfw.dcss.DcssStoHConfigureRealMotor(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Configure Real Motor

This message is sent from DCSS to configure a real motor.

property motor_acceleration

The acceleration time for the motor in seconds.

property motor_backlash

The backlash amount for the motor in steps.

property motor_backlashOn

A boolean (0 or 1) indicating if backlash correction is enabled.

property motor_lowerLimit

The lower limit for the motor in scaled units.

property motor_lowerLimitOn

A boolean (0 or 1) indicating if the lower limit is enabled.

property motor_motorLockOn

A boolean (0 or 1) indicating if the motor is software locked.

property motor_name

The name of the motor to configure.

property motor_position

The scaled position of the motor.

property motor_reverseOn

A boolean (0 or 1) indicating if the motor direction is reversed.

property motor_scaleFactor

The scale factor relating scaled units to steps for the motor.

property motor_speed

The slew rate for the motor in steps/sec.

property motor_upperLimit

The upper limit for the motor in scaled units.

property motor_upperLimitOn

A boolean (0 or 1) indicating if the upper limit is enabled.

class pydhsfw.dcss.DcssStoHCorrectMotorPosition(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Correct Motor Position

Requests that the position of the specified motor be adjusted by the specified correction. This is used to support the circle parameter for motors (i.e., modulo 360 behavior for a phi axis).

property motor_correction

The correction to be applied to the motor position.

property motor_name

The name of the motor.

class pydhsfw.dcss.DcssStoHRegisterEncoder(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register Encoder

This message is received from DCSS to tell the DHS which encoder(s) it is responsible for.

property encoder_hardwareName

The name of the encoder as it is known in the DHS code.

property encoder_name

The name of the encoder as it is known in the DCSS database.

class pydhsfw.dcss.DcssStoHRegisterIonChamber(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register Ion Chamber

This message is received from DCSS to tell the DHS which ion chamber(s) it is responsible for.

property ion_chamber_counterChannel

Ion chamber counter channel.

property ion_chamber_hardwareName

The name of the ion chamber as it is known in the DHS code.

property ion_chamber_name

The name of the ion chamber as it is known in the DCSS database..

property ion_chamber_timer

Ion chamber timer.

property ion_chamber_timerType

Ion chamber timer type.

class pydhsfw.dcss.DcssStoHRegisterObject(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server to Hardware Register Object

Not sure if this is used or what it is used for.

property object_hardwareName

The name of the object as it is known in the DHS code.

property object_name

The name of the object as it is known in the DCSS database.

class pydhsfw.dcss.DcssStoHRegisterOperation(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register Operation

This message is received from DCSS to tell the DHS which operations it is responsible for.

property operation_hardwareName

The name of the operation as it is known in the DHS code.

property operation_name

The name of the operation as it is known in the DCSS database.

class pydhsfw.dcss.DcssStoHRegisterPseudoMotor(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register Pseudo Motor

This message is received from DCSS to tell the DHS which pseudo motor(s) it is responsible for.

get_pseudo_motor_hardwareName()

The name of the motor as it is known in the DHS code.

get_pseudo_motor_name()

The name of the motor as it is known in the DCSS database.

class pydhsfw.dcss.DcssStoHRegisterRealMotor(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register Real Motor

This message is received from DCSS to tell the DHS which real motor(s) it is responsible for.

property motor_hardwareName

The name of the motor as it is known in the DHS code.

property motor_name

The name of the motor as it is known in the DCSS database.

class pydhsfw.dcss.DcssStoHRegisterShutter(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register Shutter

This message is received from DCSS to tell the DHS which shutters(s) it is responsible for.

property shutter_hardwareName

The name of the shutter as it is known in the DHS code.

property shutter_name

The name of the shutter as it is known in the DCSS database.

property shutter_status

The state of the shutter (desired state or actual state?).

class pydhsfw.dcss.DcssStoHRegisterString(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Register String

This message is received from DCSS to tell the DHS which string(s) it is responsible for.

property string_hardwareName

The name of the motor as it is known in the DHS code.

property string_name

The name of the motor as it is known in the DCSS database.

class pydhsfw.dcss.DcssStoHSetMotorChildren(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Set Motor Children

property motor_children

The name(s) of the child motors.

property motor_name

The name of the parent motor.

class pydhsfw.dcss.DcssStoHSetMotorDependency(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Set Motor Dependency

property motor_dependencies

The name(s) of the dependent motors.

property motor_name

The name of the motor.

class pydhsfw.dcss.DcssStoHSetMotorPosition(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Set Motor Position

This message requests that the position of the specified motor be set to specified scaled value.

property motor_name

The name of the motor to configure.

property motor_position

The new scaled position of the motor.

class pydhsfw.dcss.DcssStoHSetShutterState(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Set Shutter State

This message requests that the state of the specified shutter or filter be changed to a particular state.

property shutter_name

The name of the shutter.

property shutter_state

The desired state of the shutter (open or closed).

class pydhsfw.dcss.DcssStoHStartMotorMove(split)

Bases: pydhsfw.dcss.DcssStoCMessage

This is a command to start a motor move.

This message requests that the specified motor be moved to the specified scaled position.

property motor_name

The name of the motor to move.

property motor_position

The scaled destination of the motor.

class pydhsfw.dcss.DcssStoHStartOperation(split)

Bases: pydhsfw.dcss.DcssStoCMessage

Server To Hardware Start Operation

This message requests that the DHS start an operation.

property operation_args

The operation arguments. It is recommended that the list of arguments continue to follow the general format of the DCS message structure (space separated tokens). However, this requirement can only be enforced by the writer of the operation handlers.

property operation_handle

The operation handle. A unique handle currently constructed by calling the create_operation_handle procedure in BLU-ICE. This currently creates a handle in the following format:

clientNumber.operationCounter

where clientNumber is a unique number provided by DCSS for each connected GUI or Hardware client. DCSS will reject an operation message if the clientNumber does not match the client. The operationCounter is a number that the client should increment with each new operation that is started.

property operation_name

The name of the operation.

pydhsfw.dcss.register_dcss_start_operation_handler(operation_name: str, dispatcher_name: str = None)

Registers a function to handle a dcss start operation message.

operation_name - Start operations that match this operation name will be dispatched to this function.

dispatcher_name - Name of the message dispatcher that will be routing the messages to this message handler. Each message dispatcher will run in it’s own thread and in the future there may be a requirement to have multiple dispatchers. For now, there is only one dispatcher, so leave this blank or set it to None.

The function signature must match:

def handler(message:DcssStoHStartOperation, context:DcssContext)

pydhsfw.dhs module

class pydhsfw.dhs.Dhs(config: dict = {})

Bases: object

Main DHS class

shutdown()

Shuts down the DHS

start()

Starts the DHS context and reads in the arg parser

wait(signal_set: set = None)

Waits indefinitely for the dhs.shutdown() signal or for an interrupt signal from the OS.

Parameters:

signal_set: List of signals as defined in the signals module that will trigger the shutdown.

class pydhsfw.dhs.DhsContext(active_operations: pydhsfw.dcss.DcssActiveOperations, connection_mgr: pydhsfw.connectionmanager.ConnectionManager, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue)

Bases: pydhsfw.dcss.DcssContext

property config

This property should be set by the DHS author in the dhs_init message handler. It is intended to store DHS specific configuration information. It can be any type of object to include a dictionary or a unique class.

create_connection(connection_name: str, scheme: str, url: str, config: dict = {})pydhsfw.connection.Connection
get_connection(connection_name: str)pydhsfw.connection.Connection
property state

This property should be set by the DHS author in the dhs_init message handler. It is intended to store DHS specific state information. It can be any type of object to include a dictionary or a unique class.

class pydhsfw.dhs.DhsInit(parser, args)

Bases: pydhsfw.messages.MessageIn

property args

The args property getter

property parser

The parser property getter

class pydhsfw.dhs.DhsStart

Bases: pydhsfw.messages.MessageIn

pydhsfw.http module

class pydhsfw.http.ContentType(value)

Bases: enum.Enum

An enumeration.

JPEG = 'image/jpeg'
PNG = 'image/png'
class pydhsfw.http.FileResponseMessage(response)

Bases: pydhsfw.http.ResponseMessage

property file
property file_length
class pydhsfw.http.FileServerRequestMessage(request)

Bases: pydhsfw.http.ServerRequestMessage

property file
class pydhsfw.http.GetRequestMessage(path: str, params: dict = None)

Bases: pydhsfw.messages.MessageOut

write() → requests.models.Request
class pydhsfw.http.Headers(value)

Bases: enum.Enum

An enumeration.

CONTENT_LENGTH = 'Content-Length'
CONTENT_TYPE = 'Content-Type'
DHS_REQUEST_TYPE_ID = 'DHS-Request-Type-Id'
DHS_RESPONSE_TYPE_ID = 'DHS-Response-Type-Id'
class pydhsfw.http.HttpClientTransport(connection_name: str, url: str, message_reader: pydhsfw.http.MessageResponseReader, message_writer: pydhsfw.http.MessageRequestWriter, config: dict = {})

Bases: pydhsfw.transport.Transport

Http client transport

connect()

Connects to the specified resource and maintains a persistent connection.

disconnect()

Disconnects from a resource.

receive() → requests.models.Response

Receive the raw bytes of an entire message.

This is a blocking call and will wait for a message to arrive or until the timeout duration is reached.

Raises TimeoutError if there are no messages to read but the timeout duration has been reached. Note: Most implementations can only set the timeout during initialization of the Transport object so this is will be a requirement for all implementations.

reconnect()

Disconnects from a resource, then reconnects.

This may be required when an existing connection is interrupted and must be re-established by completely disconnecting and reconnecting.

send(msg: requests.models.Request)

Send the raw bytes of an entire message.

shutdown()

Shutdown the connection.

Many Transports require a worker thread to maintain the connection and/or process messages. This will shutdown the worker threads and cleanup any resources.

Once the Transport has been shutdown it cannot be used again.

start()

Start any transport workers.

Many Transports require a worker thread to maintain the connection and/or process messages. This will start the worker threads and initialize any resources.

wait()

Waits for the connection to shutdown.

This is a blocking call.

class pydhsfw.http.HttpClientTransportConnectionWorker(connection_name: str, url: str, config: dict = {})

Bases: pydhsfw.threads.AbortableThread

connect()
disconnect()
reconnect()
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

property state
class pydhsfw.http.JsonResponseMessage(response)

Bases: pydhsfw.http.ResponseMessage

property json
class pydhsfw.http.MessageRequestWriter

Bases: object

write_request(request: requests.models.Request) → requests.models.Request

Create an http request out of a message bytes.

class pydhsfw.http.MessageResponseReader

Bases: object

read_response(response: requests.models.Response) → requests.models.Response

Read the http response and convert it into an object that the message factory can read and convert to a message.

class pydhsfw.http.PostFormRequestMessage(path: str, data: dict)

Bases: pydhsfw.http.PostRequestMessage

class pydhsfw.http.PostJsonRequestMessage(path: str, json: dict)

Bases: pydhsfw.http.PostRequestMessage

class pydhsfw.http.PostRequestMessage(path: str, json: dict = None, data: dict = None)

Bases: pydhsfw.messages.MessageOut

write() → bytes
class pydhsfw.http.RequestQueue

Bases: pydhsfw.messages.BlockingQueue

class pydhsfw.http.RequestVerb(value)

Bases: enum.Enum

An enumeration.

GET = 'GET'
POST = 'POST'
class pydhsfw.http.ResponseMessage(response)

Bases: pydhsfw.messages.MessageIn

classmethod parse(response: requests.models.Response) → Any
static parse_type_id(response: requests.models.Response)
class pydhsfw.http.ResponseQueue

Bases: pydhsfw.messages.BlockingQueue

class pydhsfw.http.ServerMessageRequestReader

Bases: object

read_request(request: requests.models.Request) → requests.models.Request

Read the http request and convert it into an object that the message factory can read and convert to a message.

class pydhsfw.http.ServerRequestMessage(request)

Bases: pydhsfw.messages.MessageIn

classmethod parse(request: requests.models.Request) → Any
static parse_type_id(request: requests.models.Request)

pydhsfw.jpeg_receiver module

class pydhsfw.jpeg_receiver.HttpAbortableServer(server_address, RequestHandlerClass, bind_and_activate=True)

Bases: http.server.HTTPServer

serve_forever(poll_interval=0.5)

Handle one request at a time until shutdown.

Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.

shutdown()

Stops the serve_forever loop.

Blocks until the loop has finished. This must be called while serve_forever() is running in another thread, or it will deadlock.

shutdown_trigger()
class pydhsfw.jpeg_receiver.JpegReceiverImagePostRequestMessage(request)

Bases: pydhsfw.http.FileServerRequestMessage

class pydhsfw.jpeg_receiver.JpegReceiverMessageRequestReader

Bases: pydhsfw.http.ServerMessageRequestReader

read_request(request: requests.models.Request) → requests.models.Request

Read the http request and convert it into an object that the message factory can read and convert to a message.

class pydhsfw.jpeg_receiver.JpegReceiverRequestHandler(request_queue: pydhsfw.http.RequestQueue, *args, **kwargs)

Bases: http.server.BaseHTTPRequestHandler

do_POST()
handle_expect_100()

Decide what to do with an “Expect: 100-continue” header.

If the client is expecting a 100 Continue response, we must respond with either a 100 Continue or a final response before waiting for the request body. The default is to always respond with a 100 Continue. You can behave differently (for example, reject unauthorized requests) by overriding this method.

This method should either return True (possibly after sending a 100 Continue response) or send an error response and return False.

log_error(format: str, *args: Any) → None

Log an error.

This is called when a request cannot be fulfilled. By default it passes the message on to log_message().

Arguments are the same as for log_message().

XXX This should go to the separate error log.

log_message(format: str, *args: Any) → None

Log an arbitrary message.

This is used by all other logging functions. Override it if you have specific logging wishes.

The first argument, FORMAT, is a format string for the message to be logged. If the format string contains any % escapes requiring parameters, they should be specified as subsequent arguments (it’s just like printf!).

The client ip and current date/time are prefixed to every message.

protocol_version = 'HTTP/1.1'
timeout = 5
class pydhsfw.jpeg_receiver.JpegReceiverServerConnection(connection_name: str, url: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, outgoing_message_queue: pydhsfw.messages.OutgoingMessageQueue, config: dict = {})

Bases: pydhsfw.connection.ConnectionBase

class pydhsfw.jpeg_receiver.JpegReceiverServerMessageFactory

Bases: pydhsfw.messages.MessageFactory

class pydhsfw.jpeg_receiver.JpegReceiverServerTransport(connection_name: str, url: str, config: dict = {})

Bases: pydhsfw.jpeg_receiver.JpegReceiverServerTransport

class pydhsfw.jpeg_receiver.JpegReceiverTransportConnectionWorker(connection_name: str, url: str, request_queue: pydhsfw.http.RequestQueue, config: dict = {})

Bases: pydhsfw.threads.AbortableThread

connect()
disconnect()
reconnect()
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

pydhsfw.messages module

class pydhsfw.messages.BlockingQueue

Bases: pydhsfw.messages.Queue

clear()
fetch(timeout=None) → T
queue(item: T)
class pydhsfw.messages.IncomingMessageQueue

Bases: pydhsfw.messages.BlockingQueue

class pydhsfw.messages.MessageFactory(name: str = None)

Bases: object

create_message(raw_msg: bytes)pydhsfw.messages.MessageIn

Convert a raw message to a MessageIn subclass

property name
class pydhsfw.messages.MessageIn

Bases: object

classmethod get_type_id()
classmethod parse(buffer: Any)
static parse_type_id(cls, buffer: Any) → Any
class pydhsfw.messages.MessageOut

Bases: object

classmethod get_type_id()
write() → Any
class pydhsfw.messages.MessageRegistry

Bases: object

class pydhsfw.messages.OutgoingMessageQueue

Bases: pydhsfw.messages.BlockingQueue

class pydhsfw.messages.Queue

Bases: typing.Generic

clear()
fetch(timeout=None) → T
queue(item: T)
pydhsfw.messages.register_message(msg_type_id: str, factory_name: str = None)

Registers a MessageIn class with a message factory and assigns it a message type id..

msg_type_id - The message type id that uniquely identifies this message class. This decorator adds the message type id to the class definition.

factory_name - The name of the message factory that will convert this message type id’s raw messages in to the message instances.

pydhsfw.processors module

class pydhsfw.processors.Context

Bases: object

create_connection(connection_name: str, url: str)pydhsfw.connection.Connection
get_connection(connection_name: str)pydhsfw.connection.Connection
class pydhsfw.processors.MessageHandlerRegistry

Bases: object

class pydhsfw.processors.MessageQueueDispatcher(name: str, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, context: pydhsfw.processors.Context, config: dict = {})

Bases: pydhsfw.processors.MessageQueueWorker

process_message(message: pydhsfw.messages.MessageIn)
start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class pydhsfw.processors.MessageQueueWorker(name, incoming_message_queue: pydhsfw.messages.IncomingMessageQueue, config: dict = {})

Bases: pydhsfw.threads.AbortableThread

process_message(message: pydhsfw.messages.MessageIn)
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

pydhsfw.processors.register_message_handler(msg_type_id: str, dispatcher_name: str = None)

Registers a function to handle message instances of the specified type id.

msg_type_id - This message handler will receive all messages that are of this message type.

dispatcher_name - Name of the message dispatcher that will be routing the messages to the handler. Each message dispatcher will run in it’s own thread and in the future there may be a requirement to have multiple dispatchers. For now, there is only one dispatcher, so leave this blank or set it to None.

The function signature must match:

def handler(message:MessageIn, context:Context)

To register a dcss server to client send client type message:

@register_message_handler(‘stoc_send_client_type’)

def send_client_type_handler(message:DcssStoCSendClientType, context:Context)

pydhsfw.tcpip module

class pydhsfw.tcpip.SocketStreamReader(config: dict = {})

Bases: pydhsfw.transport.StreamReader

read(msglen: int) → bytes

Reads a chunk of bytes from the stream.

This is a blocking call and the wait timeout is determine by the implementation and generally by the stream it wraps.

Raises a TimeoutError if the is nothing to read from the stream and the timeout has been reached. Raises a ConnectionAbortedError if the stream has been unusually aborted or disconnected.

property socket
class pydhsfw.tcpip.SocketStreamWriter(config: dict = {})

Bases: pydhsfw.transport.StreamWriter

property socket
write(buffer: bytes)

Writes a chunk of bytes to the stream.

Raises a ConnectionAbortedError if the stream has been unusually aborted or disconnected.

class pydhsfw.tcpip.TcpipClientTransport(connection_name: str, url: str, message_reader: pydhsfw.transport.MessageStreamReader, message_writer: pydhsfw.transport.MessageStreamWriter, config: dict = {})

Bases: pydhsfw.tcpip.TcpipTransport

Tcpip client transport

connect()

Connects to the specified resource and maintains a persistent connection.

disconnect()

Disconnects from a resource.

reconnect()

Disconnects from a resource, then reconnects.

This may be required when an existing connection is interrupted and must be re-established by completely disconnecting and reconnecting.

shutdown()

Shutdown the connection.

Many Transports require a worker thread to maintain the connection and/or process messages. This will shutdown the worker threads and cleanup any resources.

Once the Transport has been shutdown it cannot be used again.

start()

Start any transport workers.

Many Transports require a worker thread to maintain the connection and/or process messages. This will start the worker threads and initialize any resources.

wait()

Waits for the connection to shutdown.

This is a blocking call.

class pydhsfw.tcpip.TcpipClientTransportConnectionWorker(connection_name: str, url: str, socket_stream_reader: pydhsfw.tcpip.SocketStreamReader, socket_stream_writer: pydhsfw.tcpip.SocketStreamWriter, config: dict = {})

Bases: pydhsfw.threads.AbortableThread

connect()
disconnect()
reconnect()
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

property state
class pydhsfw.tcpip.TcpipTransport(connection_name: str, url: str, message_reader: pydhsfw.transport.MessageStreamReader, message_writer: pydhsfw.transport.MessageStreamWriter, config: dict = {})

Bases: pydhsfw.transport.TransportStream

Tcpip transport base

pydhsfw.threads module

class pydhsfw.threads.AbortableThread(group=None, target=None, name=None, args=(), config: dict = {}, kwargs=None, *, daemon=None)

Bases: threading.Thread

THREAD_BLOCKING_TIMEOUT = 'thread_blocking_timeout'
THREAD_BLOCKING_TIMEOUT_DEFAULT = 5.0
abort()

pydhsfw.transport module

class pydhsfw.transport.MessageStreamReader

Bases: object

read_msg(stream_reader: pydhsfw.transport.StreamReader) → bytes

Read the raw bytes of an entire message from a stream.

The underlying message packets may be a fixed length, or end in a delimeter, or have a message header that describes size. The derived class is responsible for implementing the specific requirements for message decoding.

class pydhsfw.transport.MessageStreamWriter

Bases: object

write_msg(stream_writer: pydhsfw.transport.StreamWriter, msg: bytes)

Write the message to the stream writer.

The message packets may need to be padded to a fixed length, or require a delimeter to be added, or may require packing in a message header that includes the message size. The derived class is responsible for the particulars of the message encoding.

class pydhsfw.transport.StreamReader

Bases: object

read(msglen: int) → bytes

Reads a chunk of bytes from the stream.

This is a blocking call and the wait timeout is determine by the implementation and generally by the stream it wraps.

Raises a TimeoutError if the is nothing to read from the stream and the timeout has been reached. Raises a ConnectionAbortedError if the stream has been unusually aborted or disconnected.

class pydhsfw.transport.StreamWriter

Bases: object

write(buffer: bytes)

Writes a chunk of bytes to the stream.

Raises a ConnectionAbortedError if the stream has been unusually aborted or disconnected.

class pydhsfw.transport.Transport(connection_name: str, url: str, config: dict = {})

Bases: object

Underlying bass class that all transports must derive from.

connect()

Connects to the specified resource and maintains a persistent connection.

disconnect()

Disconnects from a resource.

receive() → bytes

Receive the raw bytes of an entire message.

This is a blocking call and will wait for a message to arrive or until the timeout duration is reached.

Raises TimeoutError if there are no messages to read but the timeout duration has been reached. Note: Most implementations can only set the timeout during initialization of the Transport object so this is will be a requirement for all implementations.

reconnect()

Disconnects from a resource, then reconnects.

This may be required when an existing connection is interrupted and must be re-established by completely disconnecting and reconnecting.

send(msg: bytes)

Send the raw bytes of an entire message.

shutdown()

Shutdown the connection.

Many Transports require a worker thread to maintain the connection and/or process messages. This will shutdown the worker threads and cleanup any resources.

Once the Transport has been shutdown it cannot be used again.

start()

Start any transport workers.

Many Transports require a worker thread to maintain the connection and/or process messages. This will start the worker threads and initialize any resources.

wait()

Waits for the connection to shutdown.

This is a blocking call.

class pydhsfw.transport.TransportState(value)

Bases: enum.Enum

An enumeration.

CONNECTED = 3
CONNECTING = 2
DISCONNECTED = 1
DISCONNECTING = 4
RECONNECTED = 5
RECONNECTING = 6
class pydhsfw.transport.TransportStream(connection_name: str, url: str, message_reader: pydhsfw.transport.MessageStreamReader, messsage_writer: pydhsfw.transport.MessageStreamWriter, config: dict = None)

Bases: pydhsfw.transport.Transport

Abstract class for transports that use streams and implementations of MessageStreamReader and MessageStreamWriter.

Derived classes will need to implement a MessageStreamReader/Writer for the specific stream. They will also need to implement transport connection and thread management.

receive()

Receive the raw bytes of an entire message.

This is a blocking call and will wait for a message to arrive or until the timeout duration is reached.

Raises TimeoutError if there are no messages to read but the timeout duration has been reached. Note: Most implementations can only set the timeout during initialization of the Transport object so this is will be a requirement for all implementations.

send(msg: bytes)

Send the raw bytes of an entire message.

Module contents