Skip to content

Commit cc12707

Browse files
committed
CLI: Add a function to set the serial config
Signed-off-by: Samuel Cabrero <[email protected]>
1 parent 9a2e201 commit cc12707

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cli.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@
1616
sys.path.append(f"{os.path.dirname(__file__)}/src")
1717
from pyairios.client import AsyncAiriosModbusRtuClient
1818

19-
from pyairios.brdg_02r13 import BRDG02R13, DEFAULT_SLAVE_ID as BRDG02R13_DEFAULT_SLAVE_ID
19+
from pyairios.brdg_02r13 import (
20+
BRDG02R13,
21+
DEFAULT_SLAVE_ID as BRDG02R13_DEFAULT_SLAVE_ID,
22+
SerialConfig,
23+
)
2024
from pyairios.constants import (
25+
Baudrate,
26+
Parity,
2127
ProductId,
2228
ResetMode,
29+
StopBits,
2330
VMDBypassMode,
2431
VMDRequestedVentilationSpeed,
2532
VMDVentilationSpeed,
@@ -340,6 +347,17 @@ async def do_serial_config(self) -> None:
340347
res = await self.bridge.serial_config()
341348
print(f"Serial Config: {res}")
342349

350+
async def do_set_serial_config(self, baudrate: int, parity: str, stop_bits: int) -> None:
351+
"""Set the serial configuration.
352+
353+
The bridge must be reset to make new settings effective."""
354+
b = Baudrate.parse(baudrate)
355+
p = Parity.parse(parity)
356+
s = StopBits.parse(stop_bits)
357+
config = SerialConfig(b, p, s)
358+
if await self.bridge.set_serial_config(config):
359+
print("Reset the bridge with `reset` command to make new settings effective.")
360+
343361
async def do_uptime(self) -> None:
344362
"""Print the device uptime."""
345363
res = await self.bridge.power_on_time()

0 commit comments

Comments
 (0)