Skip to content

Commit

Permalink
fix(esp_rfc2217): Fixed keyboard interrupt on Windows and added info …
Browse files Browse the repository at this point in the history
…for command
  • Loading branch information
jakub-kocka committed Nov 12, 2024
1 parent ab2e0bf commit 5569aa5
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions esp_rfc2217_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,28 @@ def main():
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(("", args.localport))
srv.listen(1)
logging.info(" TCP/IP port: {}".format(args.localport))
logging.info(f" TCP/IP port: {args.localport}")

host_ip = socket.gethostbyname(socket.gethostname())
logging.info(
f"Waiting for connection ... use the 'rfc2217://{host_ip}:{args.localport}?ign_set_control' as a PORT"
)

while True:
srv.settimeout(5)
client_socket = None
try:
while client_socket is None:
try:
client_socket, addr = srv.accept()
except TimeoutError:
print(".", end="", flush=True)
except KeyboardInterrupt:
print("") # resetting inline print
logging.info("Exited with keyboard interrupt")
break
try:
client_socket, addr = srv.accept()
logging.info("Connected by {}:{}".format(addr[0], addr[1]))
logging.info(f" Connected by {addr[0]}:{addr[1]}")
client_socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
ser.rts = True
ser.dtr = True
Expand All @@ -103,7 +120,7 @@ def main():
try:
r.shortcircuit()
finally:
logging.info("Disconnected")
logging.info(" Disconnected")
r.stop()
client_socket.close()
ser.dtr = False
Expand All @@ -117,7 +134,7 @@ def main():
except socket.error as msg:
logging.error(str(msg))

logging.info("--- exit ---")
logging.info(" --- exit ---")


if __name__ == "__main__":
Expand Down

0 comments on commit 5569aa5

Please sign in to comment.