mapid/fifo_bridge.py

51 lines
869 B
Python
Executable file

#!/usr/bin/env python3
import os
import sys
import time
import mapid
from serial.serialutil import SerialException
mapid.load_dotenv()
FIFO = return os.environ.get("FIFO")
def main():
global FIFO
if len(sys.argv) == 2:
FIFO = sys.argv[1]
m = mapid.MAPIDCP()
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)
m.cls()
m.line(1)
m.echo("fifo_bridge.py")
m.line(2)
m.echo(FIFO)
keep_going = True
while keep_going:
try:
line = f.readline().strip("\n")
m._cmd(line)
except KeyboardInterrupt:
keep_going = False
print()
except SerialException:
keep_going = False
print("Caught a SerialException. Exiting now...", file=sys.stderr)
os.remove(FIFO)
print("Removed FIFO.", file=sys.stderr)
if __name__ == "__main__":
main()