srne-mqtt/misc/test_serial.py

30 lines
701 B
Python
Raw Permalink Normal View History

2023-04-07 19:13:32 +00:00
# -*- coding: utf-8 -*-
import os
import sys
from time import sleep
from serial import Serial
print(sys.path)
sys.path.insert(1, os.path.dirname(os.path.dirname(sys.argv[0])))
# from srnemqtt.constants import MAC
# from srnemqtt.lib.feasycom_ble import BTLEUart
from srnemqtt.protocol import construct_request, write # noqa: E402
for rate in [1200, 2400, 4800, 9600, 115200]:
print(rate)
with Serial("/dev/ttyUSB0", baudrate=rate, timeout=2) as x:
sleep(2)
print(x)
write(x, construct_request(0x0E, words=3))
print(x.read(3))
print(x.read(6))
print(x.read(2))
# x.timeout = 2
# print(x.read())
# print(x.read(1))