serial_api module
The serial_api module provides classes to connect and communicate with serial modules that implement the OIF serial communication protocol.
The main class in the module is SerialModule. It represents the connection with a serial device and provides functions to send read/write commands.
- Device connection:
Use
SerialModule.get_serial_ports()to get a list of the available serial communication ports on the PC.Create a SerialModule object by instantiating the class:
device = SerialModule(com_port="COM1", baud_rate=SerialBaudRates.Baud_115200).Use
SerialModule.connect()to open the serial connection with the device andSerialModule.disconnect()to close it.
- Register-specific read/write command functions:
Use functions
SerialModule.read_reg_<REG NAME>()andSerialModule.write_reg_<REG NAME>()to read and write data from/to the device internal registers, as defined in the device firmware user guide.These functions provide a customized interface for every register, with specific data types, error handling, automatic multibyte transfers when necessary, and additional features like waiting for pending commands to complete.
- Low-level register read/write commands:
Use
SerialModule.read_register()andSerialModule.write_register()to read and write raw data from/to individual device internal registers.Use
SerialModule.read_bytes()andSerialModule.write_bytes()to read and write raw data from/to device registers that require multibyte data transfers (AEA).Use
SerialModule.read_string()andSerialModule.write_string()to read and write raw strings from/to device registers that require multibyte data transfers (AEA).
The serial_api module also defines some enumerations, custom exceptions, and helper classes.
- Registers Enumerations:
- Exceptions:
- Helper Enumerations:
- class serial_api.SerialBaudRates(value)
Bases:
EnumBaud rates supported by the serial module. Each baud rate is represented by a binary code (as required by the module) and the actual baud rate.
- Baud_9600 = (0, 9600)
- Baud_19200 = (1, 19200)
- Baud_38400 = (2, 38400)
- Baud_57600 = (3, 57600)
- Baud_115200 = (4, 115200)
- Baud_230400 = (5, 230400)
- Baud_460800 = (6, 460800)
- Baud_921600 = (7, 921600)
- static from_code(code)
Returns the
SerialBaudRatesenum value corresponding to the given baud rate binary code.
- static from_baud_rate(baud_rate)
Returns the
SerialBaudRatesenum value corresponding to the given baud rate.
- class serial_api.SerialPacketStatus(value)
Bases:
IntEnumStatus codes returned by the serial module in response to a command.
- OK = 0
Normal return status
- XE = 1
Execution error
- AEA = 2
Automatic extended addressing result being returned or ready to write
- CP = 3
Command not complete, pending
- conjugate()
Returns self, the complex conjugate of any int.
- bit_length()
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- bit_count()
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- to_bytes(length, byteorder, *, signed=False)
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- from_bytes(byteorder, *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Indicates whether two’s complement is used to represent the integer.
- as_integer_ratio()
Return integer ratio.
Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- real
the real part of a complex number
- imag
the imaginary part of a complex number
- numerator
the numerator of a rational number in lowest terms
- denominator
the denominator of a rational number in lowest terms
- class serial_api.SerialErrorCodes(value)
Bases:
IntEnumError codes returned by the serial module in response to the NOP command.
- OK = 0
OK, no errors.
- RNI = 1
The addressed register is not implemented.
- RNW = 2
Register not write-able; register cannot be written (read only).
- RVE = 3
Register value range error; writing register contents causes value range error; contents unchanged.
- CIP = 4
Command ignored due to pending operation.
- CII = 5
Command ignored while module is initializing, warming up, or contains an invalid configuration.
- ERE = 6
Extended address range error (address invalid).
- ERO = 7
Extended address is read only.
- EXF = 8
Execution general failure.
- CIE = 9
Command ignored while module’s optical output is enabled (carrying traffic).
- IVC = 10
Invalid configuration, command ignored.
- U0B = 11
Undefined error code.
- U0C = 12
Undefined error code.
- U0D = 13
Undefined error code.
- U0E = 14
Undefined error code.
- VSE = 15
Vendor specific error.
- conjugate()
Returns self, the complex conjugate of any int.
- bit_length()
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- bit_count()
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- to_bytes(length, byteorder, *, signed=False)
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- from_bytes(byteorder, *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Indicates whether two’s complement is used to represent the integer.
- as_integer_ratio()
Return integer ratio.
Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- real
the real part of a complex number
- imag
the imaginary part of a complex number
- numerator
the numerator of a rational number in lowest terms
- denominator
the denominator of a rational number in lowest terms
- class serial_api.SerialRegisters(value)
Bases:
IntEnumAbstract base Enum for the register codes of the serial module’s firmware commands.
- static get_composed_enum(*enum_classes: Type[SerialRegisters]) Type[SerialRegisters]
Return an Enum for the combined list of all the register codes supported by a specific device.
- Parameters:
*enum_classes (Type[SerialRegisters]) – Enum classes to combine.
- Returns:
A new Enum class combining all the provided Enum classes.
- Return type:
Type[SerialRegisters]
- conjugate()
Returns self, the complex conjugate of any int.
- bit_length()
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- bit_count()
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- to_bytes(length, byteorder, *, signed=False)
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- from_bytes(byteorder, *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Indicates whether two’s complement is used to represent the integer.
- as_integer_ratio()
Return integer ratio.
Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- real
the real part of a complex number
- imag
the imaginary part of a complex number
- numerator
the numerator of a rational number in lowest terms
- denominator
the denominator of a rational number in lowest terms
- class serial_api.SerialRegistersGeneral(value)
Bases:
SerialRegistersRegister codes for firmware commands in the “General” category.
- NOP = 0
No operation register
- DevTyp = 1
Device type string
- MFGR = 2
Manufacturer string
- Model = 3
Model string
- SerNo = 4
Serial number string
- MFGDate = 5
Manufacturing date string
- Release = 6
Release string
- RelBack = 7
Release backwards compatibility string
- GenCfg = 8
General configuration
- AEA_EAC = 9
Automatic Extended Addressing - Configuration
- AEA_EA = 10
Automatic Extended Addressing - Address
- AEA_EAR = 11
Automatic Extended Addressing - Data Register
- IOCap = 13
I/O capabilities
- LstResp = 19
Last response
- static get_composed_enum(*enum_classes: Type[SerialRegisters]) Type[SerialRegisters]
Return an Enum for the combined list of all the register codes supported by a specific device.
- Parameters:
*enum_classes (Type[SerialRegisters]) – Enum classes to combine.
- Returns:
A new Enum class combining all the provided Enum classes.
- Return type:
Type[SerialRegisters]
- conjugate()
Returns self, the complex conjugate of any int.
- bit_length()
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- bit_count()
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- to_bytes(length, byteorder, *, signed=False)
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- from_bytes(byteorder, *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value.
- signed
Indicates whether two’s complement is used to represent the integer.
- as_integer_ratio()
Return integer ratio.
Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- real
the real part of a complex number
- imag
the imaginary part of a complex number
- numerator
the numerator of a rational number in lowest terms
- denominator
the denominator of a rational number in lowest terms
- exception serial_api.SerialConnectionError
Bases:
ExceptionException raised when there is an error in establishing or maintaining a connection with a serial module.
- exception serial_api.SerialCommunicationError(host_to_module: bool = False, module_to_host: bool = False)
Bases:
ExceptionException raised when there is a communication error with the serial module.
Check the host_to_module and module_to_host flags to determine the direction of the communication error.
- exception serial_api.SerialResponseError(write: bool, register: ~serial_api.SerialRegisters, resp_register: int | None = None, resp_status: int | None = None, expected_responses: ~typing.Set[~serial_api.SerialPacketStatus] | None = None, device_registers_enum: ~typing.Type[~serial_api.SerialRegisters] | None = <enum 'SerialRegisters'>)
Bases:
ExceptionException raised when there is an error in the response received from the serial module.
- Check class attributes to determine the cause of the error:
register: the register that was read or written
write: True if the error occurred during a write operation, False if it occurred during a read operation
resp_register: the register code that was returned by the module in response to the command
resp_status: the status code that was returned by the module in response to the command
expected_responses: the set of status codes that were expected in response to the command
- exception serial_api.SerialCommandError(write: bool, register: SerialRegisters, error_code: SerialErrorCodes | None = None)
Bases:
ExceptionException raised when the serial module signal an execution error in response to a command.
- Check class attributes to determine the cause of the error:
register: the register that was read or written
write: True if the error occurred during a write operation, False if it occurred during a read operation
error_code: the error code that was returned by the module in response to a NOP sent just after the error occurred
- exception serial_api.SerialPendingTimeoutError
Bases:
ExceptionException raised when a pending command does not complete within the specified timeout.
- class serial_api.SerialModule(com_port: str = '', baud_rate: SerialBaudRates = SerialBaudRates.Baud_9600, serial_timeout: float = 0.2, cmd_retry: int = 5, pending_timeout: float = 20, auto_nop_on_cmd_error: bool = True)
Bases:
objectThe
SerialModuleclass represents the connection with a serial device and provides functions to send read/write commands.- Device connection:
Use
SerialModule.get_serial_ports()to get a list of the available serial communication ports on the PC.Create a SerialModule object by instantiating the class:
device = SerialModule(com_port="COM1", baud_rate=SerialBaudRates.Baud_115200).Use
SerialModule.connect()to open the serial connection with the device andSerialModule.disconnect()to close it.
- Register-specific read/write command functions:
Use functions
SerialModule.read_reg_<REG NAME>()andSerialModule.write_reg_<REG NAME>()to read and write data from/to the device internal registers, as defined in the device firmware user guide.These functions provide a customized interface for every register, with specific data types, error handling, automatic multibyte transfers when necessary, and additional features like waiting for pending commands to complete.
- Low-level register read/write commands:
Use
SerialModule.read_register()andSerialModule.write_register()to read and write raw data from/to individual device internal registers.Use
SerialModule.read_bytes()andSerialModule.write_bytes()to read and write raw data from/to device registers that require multibyte data transfers (AEA).Use
SerialModule.read_string()andSerialModule.write_string()to read and write raw strings from/to device registers that require multibyte data transfers (AEA).
- static get_device_serial_registers() Type[SerialRegisters]
Returns the Enum class representing the combined list of all the register codes supported by the device.
- static get_serial_ports(filter_name: str = '', filter_manufacturer: str = '')
Get a list of available serial ports.
- connect(com_port: str | None = None, baud_rate: SerialBaudRates | None = None, serial_timeout: float | None = None, cmd_retry: int | None = None, auto_baud: bool = True)
Connects to the serial module.
- Parameters:
com_port (Optional[str]) – The serial port to connect to. If None, uses the com_port provided during initialization. Defaults to None.
baud_rate (Optional[SerialBaudRates]) – The baud rate for the serial communication. If None, uses the baud_rate provided during initialization. Defaults to None.
serial_timeout (Optional[float]) – The timeout for reading from the serial port in seconds. If None, uses the serial_timeout provided during initialization. Defaults to None.
cmd_retry (Optional[int]) – The number of times to retry to send a command when a communication error is detected. If None, uses the cmd_retry provided during initialization. Defaults to None.
auto_baud (bool) – Whether to automatically try with the default baud if the specified one doesn’t work. Defaults to True.
- Raises:
SerialModuleConnectionError – If there is an error in establishing the connection.
- disconnect()
Disconnects from the serial module.
- is_connected(check_response: bool = True)
Checks if the module is connected correctly.
- Parameters:
check_response (bool) – Whether to check only for the status of the serial port (False) or to check also if the module responds to a NOP command (True). Defaults to True.
- Returns:
True if the module is connected, False otherwise.
- send_command(register: SerialRegisters = SerialRegistersGeneral.NOP, data: int = 0, write: bool = False, allow_ok: bool = True, allow_aea: bool = False, allow_cp: bool = False, check_response_reg: bool = True, cmd_retry: int | None = None, wait_pending: bool = True, auto_nop_on_cmd_error: bool | None = None) Tuple[SerialPacketStatus, int]
Sends a command to the serial module and retrieves the response.
- Parameters:
register (SerialRegisters) – The register code. 8 bits.
data (int) – The data associated with the command. 16 bits.
write (bool) – Indicates if the command is a write command.
allow_ok (bool) – Indicates if the command is allowed to return OK status.
allow_aea (bool) – Indicates if the command is allowed to return AEA status.
allow_cp (bool) – Indicates if the command is allowed to return CP status.
check_response_reg (bool) – Indicates if the response register address should be checked against the sent one.
cmd_retry (int) – The number of retries to perform if the command fails. If not None, this value overrides the one provided at initialization or at connection.
wait_pending (bool) – Indicates if the function should poll the NOP register until the pending flags are cleared, when the command response status is SerialModulePacketStatus.CP.
auto_nop_on_cmd_error (bool) – If not None, this value overrides the one provided at initialization. If True, automatically sends a NOP read command to retrieve the error cause when the command returns XE status code.
- Returns:
A tuple containing the response status and response data as a 16-bits int.
- Return type:
tuple[SerialPacketStatus, int]
- Raises:
SerialModuleConnectionError – If there is an error in the serial connection.
SerialModuleCommunicationError – If there is a communication error with the serial module, in either direction.
SerialModuleResponseError – If there is an error in the response received from the serial module.
SerialCommandError – If the command response status is SerialModulePacketStatus.XE.
- read_register(register: SerialRegisters, data: int = 0) int
Read a register from the serial module.
- Parameters:
register (SerialRegisters) – The register to read.
data (int) – Optional data to include in the read command, if required to customize the module response.
- Returns:
The data read from the register as a 16-bits int.
- Return type:
int
- write_register(register: SerialRegisters, data: int = 0, allow_pending: bool = True, wait_pending: bool = True) Tuple[SerialPacketStatus, int]
Write a register in the serial module.
- Parameters:
register (SerialRegisters) – The register to write.
data (int) – The data to write in the register.
allow_pending (bool) – If True, allows the command to return CP status without raising an exception, indicating that the command is continuing execution after the response.
wait_pending (bool) – If True, automatically waits for the pending flags in the NOP register to clear before returning from the function.
- Returns:
The execution status and the pending flags if CP status is returned and wait_pending is False.
- Return type:
Tuple[SerialPacketStatus, int]
- read_bytes(register: SerialRegisters, data: int = 0) bytearray
Read a register from the serial module, returning the data as a bytearray. If the register requires AEA multibyte reads, the function will automatically read the required amount of bytes.
- Parameters:
register (SerialRegisters) – The register to read.
data (int) – Optional data to include in the read command, if required to customize the module response.
- Returns:
The data read from the register as a bytearray.
- Return type:
bytearray
- write_bytes(register: SerialRegisters, data: bytearray, not_aea: bool = False, allow_pending: bool = True, wait_pending: bool = True) Tuple[SerialPacketStatus, int]
Write multiple bytes to a register in the serial module that supports AEA multibyte writes. The function also supports writing to command registers that do not support AEA multibyte writes, by setting the not_aea parameter to True and by passing a data array with only 2 elements.
- Parameters:
register (SerialRegisters) – The register to write.
data (bytearray) – The data to write in the register as a bytearray.
not_aea (bool) – If True, forces the function to write the data as a single 16-bits int, without using AEA multibyte writes.
allow_pending (bool) – If True, allows the command to return CP status without raising an exception, indicating that the command is continuing execution after the response.
wait_pending (bool) – If True, automatically waits for the pending flags in the NOP register to clear before returning from the function.
- Returns:
The execution status and the pending flags if CP status is returned and wait_pending is False.
- Return type:
Tuple[SerialPacketStatus, int]
- wait_pending(pending_mask: int = 255, pending_timeout: float | None = None)
Waits for pending commands to complete.
- Parameters:
pending_mask (int) – The mask for the pending flags to wait for. Defaults to 0xFF, which waits for all pending flags to clear.
pending_timeout (Optional[float]) – The timeout for waiting for pending commands to complete in seconds. If None, uses the pending_timeout provided during initialization. Defaults to None.
- Raises:
SerialPendingTimeoutError – If the pending commands do not complete within the specified timeout.
- read_string(register: SerialRegisters, remove_null_terminator=True) str
Reads a string from the specified register with AEA.
- Parameters:
register (SerialRegisters) – The register to read the string from.
remove_null_terminator (bool) – Whether to remove the null terminator character (’') from the end of the string. Defaults to True.
- Returns:
The string read from the register.
- Return type:
str
- write_string(register: SerialRegisters, data_string: str, max_length: int = 80, allow_pending: bool = True, wait_pending: bool = True) Tuple[SerialPacketStatus, int]
Write a string to the specified register with AEA.
- Parameters:
register (SerialRegisters) – The register to write the string to.
data_string (str) – The string to write to the register.
max_length (int) – The maximum length of the string, including the null terminator character (’'). Defaults to 80.
allow_pending (bool) – Whether to allow the command to return a pending status. Defaults to True.
wait_pending (bool) – Whether to wait for pending commands to complete after writing the string. Defaults to True.
- Returns:
The execution status and the pending flags if CP status is returned and wait_pending is False.
- Return type:
Tuple[SerialPacketStatus, int]
- read_reg_nop() Tuple[SerialErrorCodes, bool, int]
Reads the NOP register.
- Returns:
Last command execution error, module ready flag, pending flags.
- Return type:
Tuple[SerialErrorCodes, bool, int]
- write_reg_nop(data: int) int
Writes the NOP register.
- Parameters:
data (int) – The data to write to the NOP register.
- Returns:
The data returned by the device. Should be the same as the data written, if the module is working correctly.
- Return type:
int
- read_reg_dev_typ() str
Reads the DevTyp register.
- Returns:
The device type string.
- Return type:
str
- read_reg_mfgr() str
Reads the MFGR register.
- Returns:
The manufacturer string.
- Return type:
str
- read_reg_model() str
Reads the Model register.
- Returns:
The model string.
- Return type:
str
- read_reg_ser_no() str
Reads the SerNo register.
- Returns:
The serial number string.
- Return type:
str
- read_reg_mfg_date() str
Reads the MFGDate register.
- Returns:
The manufacturing date string.
- Return type:
str
- read_reg_release() str
Reads the Release register.
- Returns:
The release string.
- Return type:
str
- read_reg_rel_back() str
Reads the RelBack register.
- Returns:
The release backwards compatibility string.
- Return type:
str
- read_reg_gen_cfg() int
Reads the GenCfg register.
- Returns:
The data returned by the device, always 0.
- Return type:
int
- write_reg_gen_cfg(wait_pending: bool = True) int
Writes the GenCfg register with the required value to force the device to store non-volatile configuration into flash memory.
- Parameters:
wait_pending (bool) – If True, the function will wait for the device to finish writing the configuration into flash memory.
- Returns:
The pending flags returned by the device. 0 if operation already completed.
- Return type:
int
- Raises:
SerialCommandError – If the device returns an error.
SerialPendingTimeoutError – If waiting for the device to finish writing the configuration into flash memory times out.
- read_reg_aea_eac() int
Reads the AEA_EAC register.
- Returns:
The content of the AEA_EAC register.
- Return type:
int
- write_reg_aea_eac(data: int, wait_pending: bool = True) int
Writes the AEA_EAC register.
- Parameters:
data (int) – The data to write to the AEA_EAC register.
wait_pending (bool) – If True and response status is CP, the function will wait for the command to complete.
- Returns:
The pending flags returned by the device. 0 if operation already completed.
- Return type:
int
- read_reg_aea_ea() int
Reads the AEA_EA register.
- Returns:
The content of the AEA_EA register.
- Return type:
int
- write_reg_aea_ea(data: int, wait_pending: bool = True) int
Writes the AEA_EA register.
- Parameters:
data (int) – The data to write to the AEA_EA register.
wait_pending (bool) – If True and response status is CP, the function will wait for the command to complete.
- Returns:
The pending flags returned by the device. 0 if operation already completed.
- Return type:
int
- read_reg_aea_ear() int
Reads the AEA_EAR register.
- Returns:
The content of the AEA_EAR register.
- Return type:
int
- write_reg_aea_ear(data: int, wait_pending: bool = True) int
Writes the AEA_EAR register.
- Parameters:
data (int) – The data to write to the AEA_EAR register.
wait_pending (bool) – If True and response status is CP, the function will wait for the command to complete.
- Returns:
The pending flags returned by the device. 0 if operation already completed.
- Return type:
int
- Raises:
SerialCommandError – If the device returns an error.
SerialPendingTimeoutError – If waiting for the device to finish the pending operation times out.
- read_reg_io_cap() Tuple[SerialBaudRates, SerialBaudRates]
Reads the IOCap register.
- Returns:
Current baud rate and maximum baud rate supported by the connected module.
- Return type:
Tuple[SerialBaudRates, SerialBaudRates]
- write_reg_io_cap(baud_rate: SerialBaudRates, auto_switch_baud: bool = True)
Writes the IOCap register.
- Parameters:
baud_rate (SerialBaudRates) – The baud rate to set.
auto_switch_baud (bool) – If True and device response is positive, the connection will automatically switch to the new baud rate. If False, the connection will remain at the current baud.
- read_reg_lst_resp() Tuple[int, int, int]
Reads the LstResp register.
- Returns:
The status, register and data of the last response sent by the module.
- Return type:
Tuple[int, int, int]