psychos.triggers.ParallelPort#

class psychos.triggers.ParallelPort(address: str, reset_value: int = 0, log: bool = True, **kwargs)[source]#

Bases: BasePort

Parallel port implementation using pyparallel.

This class provides an implementation for sending triggers via a parallel port using the pyparallel library. It supports sending data as either integers or as bytes. If an integer is provided, it is converted to a single byte using big-endian byte order. For multi-byte values, send the data as bytes directly.

Note

This class is based on pyparallel and requires it to be installed. You can install it via pip:

pip install pyparallel

Examples

Using a typical PC parallel port address: >>> pp = ParallelPort(address=’0x378’) >>> pp.send(128) # Converts 128 to a single byte and sends it. >>> pp.send(b’€’) # Sends the byte directly. >>> pp.reset() # Resets the port (sets data to 0).

Using an alternative port address: >>> pp2 = ParallelPort(address=’0x3BC’) >>> pp2.send(255)

__init__(address: str, reset_value: int = 0, log: bool = True, **kwargs)[source]#

Initialize the ParallelPort instance.

Parameters:
  • address (str) – The address of the parallel port (e.g., ‘0x378’ is a common base address on x86 systems).

  • **kwargs – Additional keyword arguments for compatibility with pyparallel.

Methods

__init__(address[, reset_value, log])

Initialize the ParallelPort instance.

close()

Close the parallel port connection.

encode(value)

Encode a value as bytes.

reset()

Reset the parallel port by setting its data register to 0.

send(value)

Send a value over the parallel port.

close()[source]#

Close the parallel port connection.

For pyparallel, there is no explicit close method; this method is provided for interface consistency.

encode(value: int | bytes)[source]#

Encode a value as bytes.

reset()[source]#

Reset the parallel port by setting its data register to 0.

This method returns the port to a known, idle state.

send(value: int | bytes)[source]#

Send a value over the parallel port.

If an integer is provided, it is converted to a single byte using big-endian byte order. If a different byte size is required, send the data as bytes directly.

Parameters:

value (Union[int, bytes]) – The value to send. If an integer is provided, it will be converted to a single byte. For multi-byte values, provide the data as bytes.

Examples

>>> pp = ParallelPort(address='0x378')
>>> pp.send(128)         # Converts 128 to a single byte and sends it.
>>> pp.send(b'€')     # Sends the byte directly.