add minimal MNL100 bring-up script

This commit is contained in:
Sébastien Bourdeauducq 2025-05-20 11:01:09 +08:00
commit 78745476d2

48
mnl100.py Normal file
View File

@ -0,0 +1,48 @@
import time
import serial
def main():
with serial.Serial("/dev/cuaU0", timeout=1., exclusive=True) as port:
def transact(rdu):
telegram = b"#!@" + rdu
telegram += bytes("{:02X}".format(sum(telegram)), "ascii")
telegram += b"\r"
port.write(telegram)
telegram = port.read_until(expected=b"\r")
if not telegram or telegram[-1] != 0x0d:
raise TimeoutError
match telegram[0]:
case 0x0d: # acknowledge
return None
case 0x3c: # reply
return telegram[3:-3]
case 0x1b: # error
raise IOError("laser reported error")
case _:
raise ValueError("invalid reply from laser")
transact(b"g") # laser on
print("laser turning on...")
try:
while True:
short_status = transact(b"W") # GetShortStatus
if short_status == b"W01":
break
time.sleep(0.3)
print("laser is on")
transact(b"u") # ExtTrigmode
print("laser is ready")
# keep the laser on (auto-shutdown if no comms for 30s)
while True:
transact(b"W") # GetShortStatus
time.sleep(5.0)
finally:
transact(b"X") # laser off
print("laser is off")
if __name__ == "__main__":
main()