fifo_bridge.py: Write PID to a file

This commit is contained in:
Malte Bublitz 2023-11-08 19:59:03 +01:00
parent 5f218f6d40
commit c693412535
Signed by: malte70
GPG key ID: 605DA5C729F9C184
2 changed files with 17 additions and 0 deletions

3
.env
View file

@ -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"

View file

@ -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)