-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhanPrinter.py
More file actions
29 lines (27 loc) · 931 Bytes
/
hanPrinter.py
File metadata and controls
29 lines (27 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from HAN import hexprint, readHan
import serial
import json
import datetime
def default_serializer(o):
if type(o) is datetime.date or type(o) is datetime.datetime:
return o.isoformat()
buff = {}
with serial.Serial('/dev/ttyUSB0', 2400, timeout=5,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
) as ser:
try:
while True:
han = readHan(ser)
for item in han.data:
buff[item] = han.data[item]
print("\033[H\033[J")
print(json.dumps(buff,
indent=4,
sort_keys=True,
default=default_serializer))
except EOFError as e:
# We are on serial.. EOF meens no data, but it might come? :)
print("EOF")
pass