Serial Device Handler
Execute commands on a device via serial port.
Installing
Install using pip
pip install serialdevicehandler
or install it from PyPi
Example
from serialdevicehandler import *
device = serialdevicehandler(port="COM10", baudrate="115200")
output = device.execute("help")
print(output)
SerialDeviceHandler()
SerialDeviceHandler()
is the core class within the library.
Syntax:
device = SerialDeviceHandler(port, baudrate, timeout)
argument | description | expected type | default value |
---|---|---|---|
port |
Specifies the device port | str |
COM1 |
baudrate |
Specifies the device baudrate | str |
9600 |
timeout |
Specifies the command timeout | int |
0.2s |
There are some attributes for statistical and other purposes.
attribute | description | expected type | default value |
---|---|---|---|
is_open |
Indicates whether the serial port is open | bool |
False |
eol_delimiter |
defines the end-of-line separator for line reading | str |
\n |
total_rx |
stores the total bytes received | int |
0 |
total_tx |
stores the total bytes transmitted | int |
0 |
SerialDeviceHandler.execute()
Use the execute()
function to run a command.
Syntax:
device.execute(command, <optional arguments>)
argument | description | expected type | default value |
---|---|---|---|
command |
Defines the command to be executed | str |
n/a |
stdout |
Live output while the command is running | bool |
False |
read_only |
read only execution | bool | False |
write_only |
write only execution | bool | False |