Skip to content

Commit

Permalink
sertotcp: auto-reopen serial port
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Nov 29, 2023
1 parent 4d074e4 commit ffc6ade
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tools/sertotcp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

"""
map a serial port to an outgoing TCP connection
Expand Down Expand Up @@ -39,12 +39,27 @@ def open_socket():
while True:
gotdata = False

if serport is None:
try:
print("Reopening %s" % args.serialport)
serport = serial.Serial(args.serialport, args.baudrate, timeout=0)
except Exception:
time.sleep(1)
continue
print("Opened %s" % args.serialport)


if tcpsock is None:
open_socket()
time.sleep(0.1)
continue

n = serport.inWaiting()
try:
n = serport.inWaiting()
except Exception:
serport = None
time.sleep(1)
continue
if n > 0:
b = serport.read(n)
if b:
Expand Down

0 comments on commit ffc6ade

Please sign in to comment.