-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserial_barcode.py
More file actions
38 lines (30 loc) · 887 Bytes
/
serial_barcode.py
File metadata and controls
38 lines (30 loc) · 887 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
30
31
32
33
34
35
36
import time, serial
import fcntl
SERIALPORT = "/dev/ttyUSB0"
BAUDRATE = 1200
ser = serial.Serial(SERIALPORT, BAUDRATE) # Constructor already opens device !
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.stopbits = serial.STOPBITS_ONE
ser.timeout = None
print('[+] Starting Up Serial Monitor')
## DROPPED: Contructor already opened device ! ##
#try:
# ser.open()
#except Exception as e:
# print("[!] error open serial port: " + str(e))
# exit()
if ser.isOpen():
try:
response = ""
while True:
byte = ser.read()
response += byte.decode("utf-8")
if byte == b'\r':
break
print("[+] read data is: " + str(response))
ser.close()
except Exception as e:
print("[!] communication error: " + str(e))
else:
print("[!] cannot open serial port; aborting...")