parallel64

parallel64

Functionality fo interfacing with a parallel port

  • Author(s): Alec Delaney

Submodules

Package Contents

Classes

StandardPort

The class for representing the SPP port

ExtendedPort

The class for representing the ECP port. Currently, this class only works

EnhancedPort

The class for representing the EPP port. It is an extension of the

GPIOPort

The class for representing GPIO-like functionality of the port, useful for

class parallel64.StandardPort(spp_base_address: int, windll_location: Optional[str] = None, reset_control: bool = True)

Bases: _BasePort

The class for representing the SPP port

Parameters
  • spp_base_address (int) – The base address for the port, representing the SPP port data register

  • windll_location (str|None) – (optional) The location of the DLL required to use the parallel port, default is to use the one included in this package

  • reset_control (bool) – (optional) Whether the control register should be reset upon initialization, default is to reset it (True)

classmethod from_json(cls, json_filepath: str) StandardPort

Factory method for creating and instance of StandardPort from a JSON file containing the necessary information

Parameters

json_filepath (str) – Filepath to the JSON

Returns

An instance of StandardPort

Return type

StandardPort

property direction(self) constants.Direction

Get the current direction of the port

property is_bidirectional(self) bool

Returns whether the port is bidirectional, based on the test performed during __init__()

write_data_register(self, data_byte: int) None

Writes to the Data register

Parameters

data_byte (int) – A byte of data

read_data_register(self) int

Reads from the data register

Returns

The information in the Data register

Return type

int

Raises

OSError – If the port is not bidirectional

write_control_register(self, control_byte: int) None

Writes to the Control register

Parameters

control_byte (int) – A byte of data

read_control_register(self) int

Reads from the Control register

Returns

The information in the Control register

Return type

int

read_status_register(self) int

Reads from the Status register

Returns

The information in the Status register

Return type

int

write_spp_data(self, data: int, hold_while_busy: bool = True) None

Writes data via SPP

Parameters
  • data (int) – The data to be transmitted

  • hold_while_busy (bool) – Whether code should be blocked until the Busy line communicates the device is done receiving the data, default behavior is blocking (True)

Raises

OSError – If the port is busy

read_spp_data(self) int

Reads data on the SPP data register, while managing the SPP handshake resources similar to a write operation

Returns

The data on the Data pins

Return type

int

Raises

OSError – If the port is not bidirectional

spp_handshake_control_reset(self) None

Resets the Control register for the SPP handshake

class parallel64.ExtendedPort(ecp_base_address: int, windll_location: Optional[str] = None)

Bases: _BasePort

The class for representing the ECP port. Currently, this class only works with the Extended Capabilities Register as opposed to the ECP port.

Parameters
  • ecp_base_address (int) – The base address for the port, representing the ECP port data register

  • windll_location (str|None) – (optional) The location of the DLL required to use the parallel port, default is to use the one included in this package

classmethod from_json(cls, json_filepath: str) ExtendedPort

Factory method for creating and instance of ExtendedPort from a JSON file containing the necessary information

Parameters

json_filepath (str) – Filepath to the JSON

Returns

An instance of ExtendedPort

Return type

ExtendedPort

property comm_mode(self) constants.CommMode

The communication mode in the ECR

write_ecr_register(self, data: int) None

Write data to the Extended Capabilities Register (ECR)

Parameters

data (int) – The data to write to the register

read_ecr_register(self) int

Read data in the Extended Capabilities Register (ECR)

Returns

The data in the register

Return type

int

class parallel64.EnhancedPort(spp_base_address: int, windll_location: Optional[str] = None)

Bases: StandardPort

The class for representing the EPP port. It is an extension of the StandardPort (SPP), so its methods can be used as well.

Parameters
  • spp_base_address (int) – The base address for the port, representing the SPP port data register

  • windll_location (str|None) – (optional) The location of the DLL required to use the parallel port, default is to use the one included in this package

write_epp_address(self, address: int) None

Write data to the EPP Address register (Address Write Cycle)

Parameters

address (int) – The information to write

read_epp_address(self) int

Read data from the EPP Address register (Address Read Cycle)

Returns

The information read

Return type

int

write_epp_data(self, data: int) None

Write data to the EPP Data register (Data Write Cycle)

Parameters

data (int) – The information to write

read_epp_data(self) int

Read data from the EPP Data register (Data Read Cycle)

Returns

The information read

Return type

int

class parallel64.GPIOPort(spp_base_address: int, windll_location: Optional[str] = None, clear_gpio: bool = True, reset_control: bool = False)

Bases: StandardPort

The class for representing GPIO-like functionality of the port, useful for interacting with connected devices in ways outside of established parallel port communication protocols. It inherits from the StandardPort class, however, so those methods are available as well.

Parameters
  • spp_base_address (int) – The base address for the port, representing the SPP port data register

  • windll_location (str|None) – (optional) The location of the DLL required to use the parallel port, default is to use the one included in this package

  • clear_gpio (bool) – (optional) Whether to clear pins and reset to low upon initialization, default is to reset pins (True)

  • reset_control (bool) – (optional) Whether to reset the control register (according to SPP handshake protocol) upon initialization, default is not to reset the register (False). Note this takes place BEFORE clearing the pins via the clear_gpio argument.

read_pin(self, pin: pins.Pin) bool

Read the state of the given pin

Parameters

pin (Pin) – The pin to read

Returns

The state of the pin

Return type

bool

Raises

OSError – If the pin is output-only

write_pin(self, pin: pins.Pin, value: bool) None

Set the state of the given pin

Parameters
  • pin (Pin) – The pin to set

  • value (bool) – The state to set the pin

Raises

OSError – If the pin is input-only

reset_data_pins(self) None

Reset the data pins (to low)

reset_control_pins(self) None

Reset the control pins (to low)