Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

sertotcp: auto-reopen serial port #879

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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