From 9eda198d22455abab77bb008cb1c4255708f2389 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Mon, 4 Mar 2019 16:43:01 +1100 Subject: [PATCH 1/2] Close serial port fd when piksi disconnects When a piksi is connected to a host via USB cable it will create 3 virtual serial ports which appear on linux systems as /dev/ttyACM*. When Piksi resets or the USB cable is disconnected the kernel will remove these device nodes automatically. When console connects to Piksi via one of these ports is will detect the disconnect event and raise a message in the log. However it will not close the file descriptor. The kernel will be unable to fully remove the device since a FD is still open. When the Piksi reboots and tries to recreate its virtual ports the linux kernel will be unable to reuse the same device number as before so long as the previous console process is still running. Solution - When console detects the piksi disconnect event it should close the handle. This allows the kernel to reuse the previous device node as soon as piksi reboots. --- python/sbp/client/drivers/pyserial_driver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/sbp/client/drivers/pyserial_driver.py b/python/sbp/client/drivers/pyserial_driver.py index db069d14ab..0ed66729be 100644 --- a/python/sbp/client/drivers/pyserial_driver.py +++ b/python/sbp/client/drivers/pyserial_driver.py @@ -81,6 +81,7 @@ def read(self, size): print() print("Piksi disconnected") print() + self.handle.close() raise IOError def write(self, s): @@ -103,6 +104,7 @@ def write(self, s): print() print("Piksi disconnected") print() + self.handle.close() raise IOError def __enter__(self): From f589875d8d3121af73e5b07436e7bde8b3c16c19 Mon Sep 17 00:00:00 2001 From: Matt Woodward Date: Tue, 5 Mar 2019 13:33:25 +1100 Subject: [PATCH 2/2] Use hostname instead of IP address --- python/tests/sbp/client/test_driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/sbp/client/test_driver.py b/python/tests/sbp/client/test_driver.py index 8f8d167859..dc1072566c 100755 --- a/python/tests/sbp/client/test_driver.py +++ b/python/tests/sbp/client/test_driver.py @@ -30,7 +30,7 @@ class MockServer(socketserver.ThreadingMixIn, socketserver.TCPServer): pass def tcp_server(handler): - server = MockServer(("127.0.0.1", 0), handler) + server = MockServer(("localhost", 0), handler) ip, port = server.server_address server_thread = threading.Thread(target=server.serve_forever) server_thread.daemon = True