psychos.triggers.BaseTrigger#
- class psychos.triggers.BaseTrigger(port: BasePort, mapping: Dict[str, int | bytes] | None = None)[source]#
Bases:
objectAbstract base class for trigger implementations.
This class provides a common interface for sending triggers through a communication port. It includes functionality to resolve trigger values using an optional mapping and to manage the port connection.
- mapping#
An optional dictionary mapping trigger names to their corresponding values.
- __init__(port: BasePort, mapping: Dict[str, int | bytes] | None = None)[source]#
Initialize a BaseTrigger instance.
Methods
__init__(port[, mapping])Initialize a BaseTrigger instance.
close()Close the trigger by closing the associated communication port.
resolve_value(value)Resolve the trigger value using the provided mapping.
send(value)Send a trigger value through the communication port.
- close()[source]#
Close the trigger by closing the associated communication port.
After closing, the port reference is set to None.
- resolve_value(value: str | int | bytes) int | bytes[source]#
Resolve the trigger value using the provided mapping.
If the value is a string, it is used as a key to retrieve the corresponding trigger value from the mapping. If no mapping exists for the string, a ValueError is raised.
- send(value: str | int | bytes)[source]#
Send a trigger value through the communication port.
This method should be implemented by subclasses.
- Parameters:
value – The trigger value to send. Its type (string, integer, or bytes) will be resolved appropriately by the subclass.
- Raises:
NotImplementedError – Always, as this is an abstract method.