raspihats.i2c_hats subpackage¶
raspihats.i2c_hats._frame module¶
This module contains the I2C Frame class and related classes.
-
class
raspihats.i2c_hats._frame.
Command
¶ Bases:
enum.Enum
I2C-HAT commands
-
CWDT_GET_PERIOD
= <Command.CWDT_GET_PERIOD: 21>¶
-
CWDT_SET_PERIOD
= <Command.CWDT_SET_PERIOD: 20>¶
-
CWDT_SET_STATE
= <Command.CWDT_SET_STATE: 22>¶
-
DI_GET_ALL_CHANNEL_STATES
= <Command.DI_GET_ALL_CHANNEL_STATES: 32>¶
-
DI_GET_CHANNEL_STATE
= <Command.DI_GET_CHANNEL_STATE: 33>¶
-
DI_GET_COUNTER
= <Command.DI_GET_COUNTER: 34>¶
-
DI_RESET_ALL_COUNTERS
= <Command.DI_RESET_ALL_COUNTERS: 36>¶
-
DI_RESET_COUNTER
= <Command.DI_RESET_COUNTER: 35>¶
-
DQ_GET_ALL_CHANNEL_STATES
= <Command.DQ_GET_ALL_CHANNEL_STATES: 53>¶
-
DQ_GET_CHANNEL_STATE
= <Command.DQ_GET_CHANNEL_STATE: 55>¶
-
DQ_GET_POWER_ON_VALUE
= <Command.DQ_GET_POWER_ON_VALUE: 49>¶
-
DQ_GET_SAFETY_VALUE
= <Command.DQ_GET_SAFETY_VALUE: 51>¶
-
DQ_SET_ALL_CHANNEL_STATES
= <Command.DQ_SET_ALL_CHANNEL_STATES: 52>¶
-
DQ_SET_CHANNEL_STATE
= <Command.DQ_SET_CHANNEL_STATE: 54>¶
-
DQ_SET_POWER_ON_VALUE
= <Command.DQ_SET_POWER_ON_VALUE: 48>¶
-
DQ_SET_SAFETY_VALUE
= <Command.DQ_SET_SAFETY_VALUE: 50>¶
-
GET_BOARD_NAME
= <Command.GET_BOARD_NAME: 16>¶
-
GET_FIRMWARE_VERSION
= <Command.GET_FIRMWARE_VERSION: 17>¶
-
GET_STATUS_WORD
= <Command.GET_STATUS_WORD: 18>¶
-
RESET
= <Command.RESET: 19>¶
-
-
exception
raspihats.i2c_hats._frame.
DecodeException
¶ Bases:
exceptions.Exception
Raised when I2C Frame decoding fails.
-
class
raspihats.i2c_hats._frame.
Frame
(id, cmd, data=[])¶ Bases:
object
The Frame is used for communication over the I2C bus:
# Field Size Description Id 1 Diferent from one request to another, I2C-HAT responds with the same Id byte. Command 1 Defines the action to be taken by the I2C-HAT which responds with the same Command byte. Data n Payload data. Crc 2 Modbus CRC16 for data integrity. Parameters: - id (
int
) – ID byte - cmd (
int
) – Command byte - data (
list
ofint
) – Payload data bytes
-
id
¶ int
– ID byte
-
cmd
¶ int
– Command byte
-
data
¶ list
ofint
– Payload data bytes
-
CMD_SIZE
= 1¶
-
CRC_SIZE
= 2¶
-
ID_SIZE
= 1¶
-
decode
(data)¶ Decode raw data from I2C bus. It’s used to decode the I2C-HATs response. The fields Id and Command should already be set because a valid I2C-HAT response always has the same Id and Command bytes as the request.
Parameters: data ( list
ofint
) – Raw I2C data to be decodedRaises: DecodeException
– If the response frame Crc check fails, or has an unexpected Id or Command
-
encode
()¶ Encode the frame fields: Id, Command, Data and Crc to a list of ints.
Returns: List of frame bytes, raw data that can be transmitted over the I2C bus Return type: list
ofint
- id (
raspihats.i2c_hats._base module¶
This module contains the I2CHat base class.
-
class
raspihats.i2c_hats._base.
Cwdt
(i2c_hat)¶ Bases:
raspihats.i2c_hats._base.Functionality
Provides attributes and methods for operating the I2C-HAT CommunicationWatchdogTimer module.
Parameters: i2c_hat ( raspihats.i2c_hats._base.I2CHat
) – I2CHat instance(*) - attribute value read directly from I2C-HAT
-
period
¶ float
– The CommunicationWatchdogTimer period value in seconds(*).
-
-
class
raspihats.i2c_hats._base.
Functionality
(i2c_hat, labels=None)¶ Bases:
object
I2C-HAT functionality base.
Parameters: - i2c_hat (
raspihats.i2c_hats._base.I2CHat
) – I2CHat instance - labels (
list
ofstr
or optional) – Channel labels
-
labels
¶ list
ofstr
– Channel Labels.
- i2c_hat (
-
class
raspihats.i2c_hats._base.
I2CHat
(address, base_address=None, board_name=None)¶ Bases:
object
Implements basic functionality common to all I2C-HATs.
Parameters: - address (int) – I2C bus address, valid range depends of base_address
- base_address (int) – I2C-HAT family starting address
- board_name (str) – I2C-HAT expected board name
Raises: ValueError
– If address is not in range(*) - attribute value read directly from I2C-HAT
-
address
¶ int
– I2C bus address.
-
fw_version
¶ string
– Firmware version(*).
-
name
¶ string
– Name(*).
-
reset
()¶ Sends a reset request to the I2C-HAT.
-
status
¶ StatusWord
– Status word(*).
-
transfer_time
¶ float
– Last valid transfer time stamp.
-
exception
raspihats.i2c_hats._base.
ResponseException
¶ Bases:
exceptions.Exception
Raised when there’s a problem with the I2C-HAT response.
raspihats.i2c_hats._digital module¶
-
class
raspihats.i2c_hats._digital.
DigitalInputs
(i2c_hat, labels)¶ Bases:
raspihats.i2c_hats._base.Functionality
Attributes and methods needed for operating the digital inputs channels.
Parameters: - i2c_hat (
raspihats.i2c_hats._base.I2CHat
) – I2CHat instance - labels (
list
ofstr
) – Labels of digital input channels
-
channels
¶ list
ofbool
– List like object, provides access to digital inputs channels.
-
r_counters
¶ list
ofint
– List like object, provides access to raising edge digital input counters.
-
f_counters
¶ list
ofint
– List like object, provides access to falling edge digital input counters.
-
reset_counters
()¶ Resets all digital input channel counters of all types(falling and rising edge).
Raises: raspihats.i2c_hats._base.ResponseException
– If the response hasn’t got the expected format
-
value
¶ int
– The value of all the digital inputs, 1 bit represents 1 channel.
- i2c_hat (
-
class
raspihats.i2c_hats._digital.
DigitalOutputs
(i2c_hat, labels)¶ Bases:
raspihats.i2c_hats._base.Functionality
Attributes and methods needed for operating the digital outputs channels.
Parameters: - i2c_hat (
raspihats.i2c_hats._base.I2CHat
) – I2CHat instance - labels (
list
ofstr
) – Labels of digital output channels
-
channels
¶ list
ofbool
– List like object, provides single channel access to digital outputs.
-
power_on_value
¶ int
– Power On Value, this is loaded to outputs at power on.
-
safety_value
¶ int
– Safety Value, this is loaded to outputs at Cwdt Timeout.
-
value
¶ int
– The value of all the digital outputs, 1 bit represents 1 channel.
- i2c_hat (
raspihats.i2c_hats._boards module¶
This module contains the I2C-HATs classes.
-
class
raspihats.i2c_hats._boards.
DI16ac
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the DI16ac I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x40, 0x4F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
di
¶ raspihats.i2c_hats._digital.DigitalInputs
– provides access to DigitalInputs.
-
-
class
raspihats.i2c_hats._boards.
DI6acDQ6rly
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the DI6acDQ6rly I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x60, 0x6F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
di
¶ raspihats.i2c_hats._digital.DigitalInputs
– provides access to DigitalInputs.
-
dq
¶ raspihats.i2c_hats._digital.DigitalOutputs
– provides access to DigitalOutputs.
-
-
class
raspihats.i2c_hats._boards.
DQ10rly
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the DQ10rly I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x50, 0x5F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
dq
¶ raspihats.i2c_hats._digital.DigitalOutputs
– provides access to DigitalOutputs.
-
-
class
raspihats.i2c_hats._boards.
DQ16oc
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the DQ16oc I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x50, 0x5F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
dq
¶ raspihats.i2c_hats._digital.DigitalOutputs
– provides access to DigitalOutputs.
-
-
class
raspihats.i2c_hats._boards.
Di16
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the Di16 I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x40, 0x4F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
di
¶ raspihats.i2c_hats._digital.DigitalInputs
– provides access to DigitalInputs.
-
-
class
raspihats.i2c_hats._boards.
Di6Rly6
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the Di6Rly6 I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x60, 0x6F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
di
¶ raspihats.i2c_hats._digital.DigitalInputs
– provides access to DigitalInputs.
-
dq
¶ raspihats.i2c_hats._digital.DigitalOutputs
– provides access to DigitalOutputs.
-
-
class
raspihats.i2c_hats._boards.
Rly10
(address)¶ Bases:
raspihats.i2c_hats._base.I2CHat
This class exposes all operations supported by the Rly10 I2C-HAT.
Parameters: address ( int
) – I2C bus address, valid range is [0x50, 0x5F]-
cwdt
¶ raspihats.i2c_hats._base.Cwdt
– provides access to CommunicationWatchDogTimer.
-
dq
¶ raspihats.i2c_hats._digital.DigitalOutputs
– provides access to DigitalOutputs.
-
-
raspihats.i2c_hats._boards.
set_i2c_port
(i2c_port)¶ Set the I2C port number.
Parameters: i2c_port (int) – I2C port number
raspihats.i2c_hats.robot module¶
This module facilitates the raspihats.i2c_hats package integration with robotframework. All the following functions will be loaded as keywords by robotframework.
Example:
* Settings * Documentation Test Suite using DI6acDQ6rly I2C-HAT. Library raspihats.i2c_hats.robot
* Test Cases *
- Set Global Variables
- ${i2c_hat_temp} New DI6acDQ6rly ${0x60} Set Global Variable ${i2c_hat} ${i2c_hat_temp}
- Board Name
- ${name} Get Name ${i2c_hat} Should Be Equal As Strings ${name} Di6Rly6 I2C-HAT
- Read Digital Input
- ${state} DO Get Channel ${i2c_hat} ${5} Should Be Equal As Strings ${state} ${False} Should Be Equal As Integers ${state} ${0}
-
raspihats.i2c_hats.robot.
cwdt_get_period
(i2c_hat)¶ Gets the I2C-HAT CommunicationWatchdogTimer period. The exported robotframework keyword is ‘CWDT Get Period’.
Parameters: i2c_hat (I2CHat) – board Returns: The CommunicationWatchdogTimer period Return type: int
-
raspihats.i2c_hats.robot.
cwdt_set_period
(i2c_hat, value)¶ Sets the I2C-HAT CommunicationWatchdogTimer period. The exported robotframework keyword is ‘CWDT Set Period’.
Parameters: - i2c_hat (I2CHat) – board
- value (int) – period in seconds
-
raspihats.i2c_hats.robot.
di_get_channel
(i2c_hat, index)¶ Gets the I2C-HAT digital input channel value. The exported robotframework keyword is ‘DI Get Channel’.
Parameters: - i2c_hat (I2CHat) – board
- index (int) – channel index
Returns: The value of the digital input channel
Return type: boolean
-
raspihats.i2c_hats.robot.
di_get_counter
(i2c_hat, index, counter_type)¶ Gets the I2C-HAT digital input channel counter value. The exported robotframework keyword is ‘DI Get Counter’.
Parameters: - i2c_hat (I2CHat) – board
- index (int) – channel index
- counter_type (int) – type of counter(0 - falling edge, 1 - rising edge)
Returns: The value of the digital input channel counter
Return type: int
-
raspihats.i2c_hats.robot.
di_get_labels
(i2c_hat)¶ Gets the I2C-HAT digital inputs labels. The exported robotframework keyword is ‘DI Get Labels’.
Parameters: i2c_hat (I2CHat) – board Returns: The labels of the digital inputs Return type: list[sring]
-
raspihats.i2c_hats.robot.
di_get_value
(i2c_hat)¶ Gets the I2C-HAT digital inputs value(all channels). The exported robotframework keyword is ‘DI Get Value’.
Parameters: i2c_hat (I2CHat) – board Returns: The value(all channels) of the digital inputs Return type: int
-
raspihats.i2c_hats.robot.
di_reset_all_counters
(i2c_hat)¶ Resets all the I2C-HAT digital input channel counter values. The exported robotframework keyword is ‘DI Reset All Counters’.
Parameters: i2c_hat (I2CHat) – board
-
raspihats.i2c_hats.robot.
di_reset_counter
(i2c_hat, index, counter_type)¶ Resets the I2C-HAT digital input channel counter value. The exported robotframework keyword is ‘DI Reset Counter’.
Parameters: - i2c_hat (I2CHat) – board
- index (int) – channel index
- counter_type (int) – type of counter(0 - falling edge, 1 - rising edge)
-
raspihats.i2c_hats.robot.
do_get_channel
(i2c_hat, index)¶ Gets the I2C-HAT digital output channel value. The exported robotframework keyword is ‘DO Get Channel’.
Parameters: - i2c_hat (I2CHat) – board
- index (int) – channel index
Returns: The value of the digital output channel
Return type: boolean
-
raspihats.i2c_hats.robot.
do_get_labels
(i2c_hat)¶ Gets the I2C-HAT digital outputs labels. The exported robotframework keyword is ‘DO Get Labels’.
Parameters: i2c_hat (I2CHat) – board Returns: The labels of the digital outputs Return type: list[sring]
-
raspihats.i2c_hats.robot.
do_get_power_on_value
(i2c_hat)¶ Gets the I2C-HAT digital outputs power on value. The exported robotframework keyword is ‘DO Get Power On Value’.
Parameters: i2c_hat (I2CHat) – board Returns: The power on value of the digital outputs Return type: int
-
raspihats.i2c_hats.robot.
do_get_safety_value
(i2c_hat)¶ Gets the I2C-HAT digital outputs safety value. The exported robotframework keyword is ‘DO Get Safety Value’.
Parameters: i2c_hat (I2CHat) – board Returns: The safety value of the digital outputs Return type: int
-
raspihats.i2c_hats.robot.
do_get_value
(i2c_hat)¶ Gets the I2C-HAT digital outputs value(all channels). The exported robotframework keyword is ‘DO Get Value’.
Parameters: i2c_hat (I2CHat) – board Returns: The value(all channels) of the digital outputs Return type: int
-
raspihats.i2c_hats.robot.
do_set_channel
(i2c_hat, index, value)¶ Sets the I2C-HAT digital output channel value. The exported robotframework keyword is ‘DO Set Channel’.
Parameters: - i2c_hat (I2CHat) – board
- index (int) – channel index
- value (boolean) – desired digital output value
Returns: The value of the digital output channel
Return type: boolean
-
raspihats.i2c_hats.robot.
do_set_power_on_value
(i2c_hat, value)¶ Sets the I2C-HAT digital outputs power on value. The exported robotframework keyword is ‘DO Set Power On Value’.
Parameters: - i2c_hat (I2CHat) – board
- value (int) – desired power on value
-
raspihats.i2c_hats.robot.
do_set_safety_value
(i2c_hat, value)¶ Sets the I2C-HAT digital outputs safety value. The exported robotframework keyword is ‘DO Set Safety Value’.
Parameters: - i2c_hat (I2CHat) – board
- value (int) – desired safety value
-
raspihats.i2c_hats.robot.
do_set_value
(i2c_hat, value)¶ Sets the I2C-HAT digital outputs value(all channels). The exported robotframework keyword is ‘DO Set Value’.
Parameters: - i2c_hat (I2CHat) – board
- value (int) – desired digital outputs value(all channels)
-
raspihats.i2c_hats.robot.
get_name
(i2c_hat)¶ Gets the I2C-HAT name. The exported robotframework keyword is ‘Get Name’.
Parameters: i2c_hat (I2CHat) – board Returns: The name of the board Return type: string
-
raspihats.i2c_hats.robot.
get_status
(i2c_hat)¶ Gets the I2C-HAT status word. The exported robotframework keyword is ‘Get Status’.
Parameters: i2c_hat (I2CHat) – board Returns: The status word Return type: int
-
raspihats.i2c_hats.robot.
new_DI16ac
(adr)¶ New instance of class DI16ac. The exported robotframework keyword is ‘New DI16ac’.
Parameters: adr (int) – i2c address Returns: A new instance of DI16ac Return type: DI16ac
-
raspihats.i2c_hats.robot.
new_DI6acDQ6rly
(adr)¶ New instance of class DI6acDQ6rly. The exported robotframework keyword is ‘New DI6acDQ6rly’.
Parameters: adr (int) – i2c address Returns: A new instance of DI6acDQ6rly Return type: DI6acDQ6rly
-
raspihats.i2c_hats.robot.
new_DQ10rly
(adr)¶ New instance of class DQ10rly. The exported robotframework keyword is ‘New DQ10rly’.
Parameters: adr (int) – i2c address Returns: A new instance of DQ10rly Return type: DQ10rly
-
raspihats.i2c_hats.robot.
new_DQ16oc
(adr)¶ New instance of class DQ16oc. The exported robotframework keyword is ‘New DQ16oc’.
Parameters: adr (int) – i2c address Returns: A new instance of DQ16oc Return type: DQ16oc
-
raspihats.i2c_hats.robot.
new_Di16
(adr)¶ New instance of class Di16. The exported robotframework keyword is ‘New Di16’.
Parameters: adr (int) – i2c address Returns: A new instance of Di16 Return type: Di16
-
raspihats.i2c_hats.robot.
new_Di6Rly6
(adr)¶ New instance of class Di6Rly6. The exported robotframework keyword is ‘New Di6Rly6’.
Parameters: adr (int) – i2c address Returns: A new instance of Di6Rly6 Return type: Di6Rly6
-
raspihats.i2c_hats.robot.
new_Rly10
(adr)¶ New instance of class Rly10. The exported robotframework keyword is ‘New Rly10’.
Parameters: adr (int) – i2c address Returns: A new instance of Rly10 Return type: Rly10
-
raspihats.i2c_hats.robot.
reset
(i2c_hat)¶ Resets the I2C-HAT. The exported robotframework keyword is ‘Reset’.