fifo_bridge.py: Write PID to a file
This commit is contained in:
parent
5f218f6d40
commit
c693412535
2 changed files with 17 additions and 0 deletions
3
.env
3
.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"
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue