Add serial test scripts

This commit is contained in:
Odd Stråbø 2023-04-07 21:13:32 +02:00
parent fa9d5d73c4
commit 7ab0b1ce62
3 changed files with 37 additions and 0 deletions

29
misc/test_serial.py Normal file
View file

@ -0,0 +1,29 @@
# -*- 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))

View file

@ -0,0 +1,7 @@
# -*- coding: utf-8 -*-
from serial import Serial
with Serial("/dev/ttyUSB0", baudrate=9600, timeout=2) as x:
x.write(b"Hello, World!")
print(x.read(13))
print(x.read(13))

View file

@ -3,3 +3,4 @@ rrdtool
bluepy
libscrc
paho-mqtt
pyserial