From c693412535c97d7d5e8d658980e4ff693c59f980 Mon Sep 17 00:00:00 2001 From: Malte Bublitz Date: Wed, 8 Nov 2023 19:59:03 +0100 Subject: [PATCH] fifo_bridge.py: Write PID to a file --- .env | 3 +++ fifo_bridge.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/.env b/.env index e9789b7..5c75f6e 100644 --- a/.env +++ b/.env @@ -9,3 +9,6 @@ SERIAL_SPEED=9600 # FIFO filename FIFO="/tmp/mapid" + +# fifo_bridge.py PID file +FIFO_BRIDGE_PID_FILE="/tmp/mapid_fifo_bridge.pid" \ No newline at end of file diff --git a/fifo_bridge.py b/fifo_bridge.py index dc75f1e..977865d 100755 --- a/fifo_bridge.py +++ b/fifo_bridge.py @@ -16,20 +16,32 @@ def main(): if len(sys.argv) == 2: FIFO = sys.argv[1] + # Write PID + FIFO_BRIDGE_PID_FILE = os.environ.get("FIFO_BRIDGE_PID_FILE") + f = open(FIFO_BRIDGE_PID_FILE, "w") + f.write(os.getpid()) + f.close() + del f + + # Create MAPIDCP object to communicate with the Arduino m = mapid.MAPIDCP() + # Create FIFO os.mkfifo(FIFO) time.sleep(0.2) print("Created FIFO " + FIFO, file=sys.stderr) f = open(FIFO, "r") print("Opened FIFO for reading", file=sys.stderr) + + # Show greeting on screen m.cls() m.line(1) m.echo("fifo_bridge.py") m.line(2) m.echo(FIFO) + # Main loop: read commands from FIFO and execute it keep_going = True while keep_going: try: @@ -42,7 +54,9 @@ def main(): keep_going = False print("Caught a SerialException. Exiting now...", file=sys.stderr) + # Remove FIFO and PID files os.remove(FIFO) + os.remove(FIFO_BRIDGE_PID_FILE) print("Removed FIFO.", file=sys.stderr)