Add serial test scripts
This commit is contained in:
parent
fa9d5d73c4
commit
7ab0b1ce62
3 changed files with 37 additions and 0 deletions
29
misc/test_serial.py
Normal file
29
misc/test_serial.py
Normal 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))
|
7
misc/test_serial_loopback.py
Normal file
7
misc/test_serial_loopback.py
Normal 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))
|
|
@ -3,3 +3,4 @@ rrdtool
|
|||
bluepy
|
||||
libscrc
|
||||
paho-mqtt
|
||||
pyserial
|
||||
|
|
Loading…
Reference in a new issue