parlay.protocols¶
parlay.protocols.base_protocol¶
-
class
parlay.protocols.base_protocol.
BaseProtocol
[source]¶ Bases:
object
This the base protocol that all parlay protocols must inherit from. Subclass this to make custom protocols to talk to 3rd party equipment.
-
close
()[source]¶ Override this with a generic method that will close the protocol.
e.g. @classmethod def close():
-
get_discovery
()[source]¶ This will get called when a discovery message is sent out. Return a deferred that will be called back with all attached: item types, message types, and connected item instances
-
classmethod
get_open_params
()[source]¶ Returns the params for the cls.open() class method. Feel free to overwrite this in a sub-class if this default implementation doesn’t fit your protocol’s needs. :return: A list of parameter names :rtype: list
-
classmethod
get_open_params_defaults
()[source]¶ return the defaults for parameters to the cls.open() using inspect. Feel free to overwrite this in a sub-class if this default implementation doesn’t fit your protocol’s needs. :return: A dictionary of parameter names -> default values. :rtype: dict
-
get_protocol_discovery_meta_info
()[source]¶ This will return protocol meta-info that will be returned with every discovery message. This is a good place to store things like enuemrations or protocol status to pass to the UI
-
got_new_data
(*args, **kwargs)[source]¶ Call this when you have new data and want to pass it to any waiting Items
-
classmethod
open
(adapter)[source]¶ Override this with a generic method that will open the protocol. The first argument must be the broker, the rest will be parameters that the user can set. Default arguments will be sent to the UI and can be overwritten bu the user It must return the built protocol (subclass of Protocol) that will be registered with the Broker Be sure to decorate it with @classmethod
e.g. @classmethod def open(cls, adapter, ip, port=8080):
return protocol(ip,port)
-
-
class
parlay.protocols.base_protocol.
WaitHandler
(deferred)[source]¶ Bases:
object
An Object used to do safe cross thread waits on deferreds
-
wait
(*args, **kwargs)[source]¶ Call this to wait until there is data from the protocol. If threaded: Will block. Return value is serial line data If Async : Will not block. Return value is Deferred that will be called back with data :param timeout_secs : Timeout if you don’t get data in time. None if no timeout :type timeout_secs : int|None
-
parlay.protocols.local_item¶
The Local Item protocol lets you open arbitrary items that have been registered as local
-
class
parlay.protocols.local_item.
LocalItemProtocol
(item)[source]¶ Bases:
parlay.protocols.base_protocol.BaseProtocol
-
ID
= 0¶
-
-
parlay.protocols.local_item.
local_item
(auto_connect=False)[source]¶ A class decorator for python Items that are not part of an external protocol.
Local items are self-contained, and do not communicate over external protocols, for example a serial port. They are typically used for simulators or pure python computation items.
Parameters: auto_connect – whether to automatically connect to the Parlay broker when the item is created. Returns: decorator function Example usage of local_item decorator:
# motor_sim.py @local_item() class MotorSimulator(ParlayCommandItem): def __init__(self, item_id, item_name): ...
Example usage of defined local item:
import parlay from motor_sim import MotorSimulator MotorSimulator("motor1", "motor 1") # motor1 will be discoverable parlay.start()
parlay.protocols.meta_protocol¶
Define the base Protocol classes and meta-classes.
For documentation on broker and common message types see parlay.protocols:
.. py:exception:: InvalidProtocolDeclaration
module: parlay.protocols.meta_protocol Bases:
exceptions.Exception
Raised when there was a problem with your protocol declaration
-
class
parlay.protocols.meta_protocol.
ProtocolMeta
(name, bases, dct)[source]¶ Bases:
type
Meta-Class that will keep track of all message types declared Also builds the message field lookups from the Django-model-style message class definitions
-
protocol_registry
= {'LocalItemProtocol': <class 'parlay.protocols.local_item.LocalItemProtocol'>, 'BaseProtocol': <class 'parlay.protocols.base_protocol.BaseProtocol'>}¶
-
parlay.protocols.serial_line¶
-
class
parlay.protocols.serial_line.
ASCIILineProtocol
(port)[source]¶ Bases:
parlay.protocols.base_protocol.BaseProtocol
,twisted.protocols.basic.LineReceiver
When a client connects over a serial, this is the protocol that will handle the communication. The messages are encoded as a JSON string
-
broker
= <parlay.server.broker.Broker object>¶
-
classmethod
get_open_params_defaults
()[source]¶ Override base class function to show dropdowns for defaults
-
classmethod
open
(broker, port='/dev/tty.usbserial-FTAJOUB2', baudrate=57600, delimiter='\n')[source]¶ This will be called bvy the system to construct and open a new SSCOM_Serial protocol :param cls : The class object (supplied by system) :param broker: current broker insatnce (supplied by system) :param port: the serial port device to use. On linux, something like “/dev/ttyUSB0”. On windows something like “COM0” :param baudrate: baudrate of serial connection :param delimiter:
-
open_ports
= set([])¶
-
parlay.protocols.utils¶
Generic utilities and helper functions that help make protocol development easier
-
class
parlay.protocols.utils.
MessageQueue
(callback)[source]¶ Bases:
object
A basic message queue for messages that need to be acknowledged
-
class
parlay.protocols.utils.
PrivateDeferred
(canceller=None)[source]¶ Bases:
twisted.internet.defer.Deferred
A Private Deferred is like a normal deferred, except that it can be passed around and callbacks can be attached by anone, but callback() and errback() have been overridden to throw an exception. the private _callback() and _errback() must be used
This ensures that only a user that ‘knows what their doing’ can issue the callback
-
exception
parlay.protocols.utils.
TimeoutError
[source]¶ Bases:
exceptions.Exception
parlay.protocols.websocket¶
-
class
parlay.protocols.websocket.
WebSocketServerAdapter
(broker=None)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerProtocol
,parlay.server.adapter.Adapter
When a client connects over a websocket, this is the protocol that will handle the communication. The messages are encoded as a JSON string
-
broker
= <parlay.server.broker.Broker object>¶
-