dwfpy.protocols.Protocols

class Protocols(device)[source]

Bases: object

Digital Protocols module.

Methods

Attributes

can

Gets the CAN protocol unit.

i2c

Gets the I2C protocol unit.

spi

Gets the SPI protocol unit.

uart

Gets the UART protocol unit.

class CAN(device)[source]

Bases: object

CAN protocol.

property inverted: bool

Gets or sets the polarity.

Return type

bool

property pin_rx: int

Gets or sets the DIO channel to use for reception.

Return type

int

property pin_tx: int

Gets or sets the DIO channel to use for transmission.

Return type

int

property rate: float

Gets or sets the data rate.

Return type

float

read()[source]

Returns the received CAN frames since the last call.

Return type

Tuple[bytes, int, int, int, int]

reset()[source]

Resets the CAN configuration to default value.

Return type

None

setup(pin_rx=None, pin_tx=None, rate=None, inverted=False)[source]

Sets up the CAN configuration.

Return type

None

write(frame_id, extended, remote, buffer)[source]

Performs a CAN transmission.

Return type

None

class I2C(device)[source]

Bases: object

I2C protocol.

clear()[source]

Verifies and tries to solve eventual bus lockup. Returns true, if the bus is free.

Return type

bool

property pin_scl: int

Gets or sets the DIO channel to use for I2C clock.

Return type

int

property pin_sda: int

Gets or sets the DIO channel to use for I2C data.

Return type

int

property rate: float

Gets or sets the data rate.

Return type

float

read(address, bytes_to_read)[source]

Performs an I2C read. Returns (rx_buffer, nak_index).

Return type

Tuple[bytes, int]

property read_nak: bool

Gets or sets a value indicating if the last read byte should be acknowledged or not.

Return type

bool

reset()[source]

Resets the I2C configuration to default value.

Return type

None

setup(pin_scl, pin_sda, rate=None, timeout=None, read_nak=None, stretch=None)[source]

Sets up the I2C configuration.

Return type

None

property stretch: bool

Enables or disables clock stretching.

Return type

bool

property timeout: float

Gets or sets the time-out.

Return type

float

write(address, buffer)[source]

Performs an I2C write.

Return type

None

write_one(address, data)[source]

Performs an I2C write of a single byte.

Return type

None

write_read(address, buffer, bytes_to_read)[source]

Performs an I2C write/read. Returns (rx_buffer, nak_index).

Return type

Tuple[bytes, int]

class Spi(device)[source]

Bases: object

SPI protocol.

property frequency: float

Gets or sets the DIO channel to use for SPI data.

Return type

float

property mode: int

Gets or sets the SPI mode.

Return type

int

property msb_first: bool

Gets or sets the bit order for SPI data.

Return type

bool

property pin_clock: int

Gets or sets the DIO channel to use for SPI clock.

Return type

int

property pin_dq0: int

Gets or sets the DIO channel to use for SPI data.

Return type

int

property pin_dq1: int

Gets or sets the DIO channel to use for SPI data.

Return type

int

property pin_dq2: int

Gets or sets the DIO channel to use for SPI data.

Return type

int

property pin_dq3: int

Gets or sets the DIO channel to use for SPI data.

Return type

int

property pin_select: int

Gets or sets the DIO channel to use for SPI clock.

Return type

int

read(words_to_receive, dq_mode=None, bits_per_word=8)[source]

Performs a SPI read.

Return type

Union[bytes, array]

read_one(dq_mode=None, bits_per_word=8)[source]

Performs a SPI reception of up to 32 bits.

Return type

None

reset()[source]

Resets the SPI configuration to default value.

Return type

None

select(level, pin_select=None)[source]

Control the SPI chip select.

Return type

None

set_idle(pin, idle)[source]

Specifies the DQ signal idle output state. DQ2 and DQ3 may be used for alternative purpose like for write protect (should be driven low) or for hold (should be in high impendance).

Return type

None

setup(pin_clock, pin_mosi, pin_miso=None, pin_select=None, frequency=None, mode=0, msb_first=True)[source]

Sets up the SPI pin configuration in standard mode.

Return type

None

setup_dual(pin_clock, pin_dq0, pin_dq1, pin_select=None, frequency=None, mode=0, msb_first=True)[source]

Sets up the SPI pin configuration in Dual mode.

Return type

None

setup_quad(pin_clock, pin_dq0, pin_dq1, pin_dq2, pin_dq3, pin_select=None, frequency=None, mode=0, msb_first=True)[source]

Sets up the SPI pin configuration in Quad mode.

Return type

None

setup_three_wire(pin_clock, pin_siso, pin_select=None, frequency=None, mode=0, msb_first=True)[source]

Sets up the SPI pin configuration in Three-wire mode.

Return type

None

write(buffer, dq_mode=None, bits_per_word=8)[source]

Performs a SPI write.

Return type

None

write_one(data, dq_mode=None, bits_per_word=8)[source]

Performs a SPI transmit of up to 32 bits.

Return type

None

write_read(buffer, words_to_receive, dq_mode=None, bits_per_word=8)[source]

Performs a SPI write/read.

Return type

Union[bytes, array]

class Uart(device)[source]

Bases: object

UART protocol.

property data_bits: Optional[int]

Gets or sets the number of data bits.

Return type

Optional[int]

property inverted: bool

Gets or sets the polarity.

Return type

bool

property parity: str

Gets or sets the parity.

Return type

str

property pin_rx: Optional[int]

Gets or sets the DIO channel to use for reception.

Return type

Optional[int]

property pin_tx: Optional[int]

Gets or sets the DIO channel to use for transmission.

Return type

Optional[int]

property rate: float

Gets or sets the baud rate.

Return type

float

read(buffer_size=8192)[source]

Returns the received characters since the last call. Returns (rx_buffer, parity).

Return type

Tuple[bytes, int]

reset()[source]

Resets the UART configuration to default value.

Return type

None

setup(pin_rx=None, pin_tx=None, rate=9600, data_bits=8, stop_bits=1, parity='n', inverted=False)[source]

Sets up the UART configuration.

Return type

None

property stop_bits: float

Gets or sets the number of stop bits.

Return type

float

write(buffer)[source]

Transmits the specified characters.

Return type

None

property can: CAN

Gets the CAN protocol unit.

Return type

CAN

property i2c: I2C

Gets the I2C protocol unit.

Return type

I2C

property spi: Spi

Gets the SPI protocol unit.

Return type

Spi

property uart: Uart

Gets the UART protocol unit.

Return type

Uart