-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCOMVoid.py
More file actions
31 lines (25 loc) · 752 Bytes
/
COMVoid.py
File metadata and controls
31 lines (25 loc) · 752 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
import serial
from serial import SerialException
import sys
import serial.tools.list_ports
# Make sure we got 1 argument.
if len(sys.argv) != 2:
print('Did not receive expected number of Arguments.')
print('Please specify COM port.')
sys.exit()
# Make sure the argument we got is a COM port
port_name = sys.argv[1]
port_names = []
for port in serial.tools.list_ports.comports():
port_names.append(port.device)
if port_name not in port_names:
print('Did not find specified COM port!')
sys.exit()
print('OK')
with serial.Serial(port_name, timeout=1) as comport:
while True:
try:
comport.read(comport.in_waiting)
except SerialException:
print('Serial Exception!')
pass