5. API - GPIO
5.1. Regular Classes
The following classes are intended for general use with the devices they represent. All classes in this section are concrete (not abstract).
5.1.1. GPIO
- class lannerpsp.GPIO(check_platform: bool = False)[source]
General Purpose Input/Output.
- Parameters:
check_platform (bool) – Set to
True
to check if the platform supports this feature. Defaults toFalse
for better compatibility.- Raises:
PSPNotSupport – This function is not supported (when
check_platform
is set toTrue
).NotImplementedError – It has not been verified to run on this platform (when
check_platform
is set toTrue
).
- get_info() GPIOInfoModel [source]
Get the GPIO information supported by this platform.
Example:
>>> gpio = GPIO() >>> gpio_info = gpio.get_info() >>> gpio_info GPIOInfoModel(number_of_di_pins=8, number_of_do_pins=4) >>> gpio_info.number_of_di_pins 8 >>> gpio_info.number_of_do_pins 4 >>> gpio_info.to_dict() {'number_of_di_pins': 8, 'number_of_do_pins': 4}
- Returns:
The GPIO information.
- Return type:
- Raises:
PSPNotSupport – This function is not supported.
PSPNotOpened – Device port is not opened yet.
PSPError – General PSP functional error.
- get_digital_in() int [source]
Get the GPI/DI status.
Example:
>>> gpio = GPIO() >>> gpio.get_digital_in() 12
- Returns:
GPI/DI status in decimal. When converted to binary, the LSB represents DI_0.
- Return type:
- Raises:
PSPNotSupport – This function is not supported.
PSPNotOpened – Device port is not opened yet.
PSPError – General PSP functional error.
- get_digital_out() int [source]
Get the GPO/DO status.
Example:
>>> gpio = GPIO() >>> gpio.get_digital_out() 3
- Returns:
GPO/DO status in decimal. When converted to binary, the LSB represents DO_0.
- Return type:
- Raises:
PSPNotSupport – This function is not supported.
PSPNotOpened – Device port is not opened yet.
PSPError – General PSP functional error.
- set_digital_out(status: int) None [source]
Set the GPO/DO status.
Example:
>>> gpio = GPIO() >>> gpio.set_digital_out(0x0A)
- Parameters:
status (int) – GPO/DO status. This value can be binary, octal, decimal or hexadecimal with type
int
. For example, to write the[high, low, high, low]
signal from DO_3 to DO_0, just set this parameter to0b1010
,0o12
,0x0A
or10
.- Raises:
PSPNotSupport – This function is not supported.
PSPNotOpened – Device port is not opened yet.
PSPError – General PSP functional error.
5.2. Models
The following models are used to store data for data modeling.
5.2.1. GPIOInfoModel
5.3. Supported Platforms
The following platforms have been verified and confirmed to be supported: