mnl100: control attenuator
This commit is contained in:
parent
f6b7731d84
commit
4a5c5bf6d0
47
mnl100.py
47
mnl100.py
@ -1,5 +1,28 @@
|
||||
import time
|
||||
import serial
|
||||
import sys
|
||||
import termios
|
||||
import select
|
||||
|
||||
|
||||
class GetKey:
|
||||
def __enter__(self):
|
||||
self.fd = sys.stdin.fileno()
|
||||
self.old = termios.tcgetattr(self.fd)
|
||||
new = termios.tcgetattr(self.fd)
|
||||
new[3] = new[3] & ~termios.ECHO & ~termios.ICANON
|
||||
termios.tcsetattr(self.fd, termios.TCSAFLUSH, new)
|
||||
return self
|
||||
|
||||
def __exit__(self, ty, value, tb):
|
||||
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old)
|
||||
|
||||
def get(self, timeout):
|
||||
r, w, e = select.select([sys.stdin], [], [], timeout)
|
||||
if r:
|
||||
return sys.stdin.read(1)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
@ -34,10 +57,28 @@ def main():
|
||||
print("laser is on")
|
||||
transact(b"u") # ExtTrigmode
|
||||
print("laser is ready")
|
||||
# keep the laser on (auto-shutdown if no comms for 30s)
|
||||
|
||||
transmission = 200
|
||||
while True:
|
||||
transact(b"W") # GetShortStatus
|
||||
time.sleep(5.0)
|
||||
with GetKey() as gc:
|
||||
match gc.get(5):
|
||||
case "q":
|
||||
return
|
||||
case "+":
|
||||
transmission += 1
|
||||
if transmission > 200:
|
||||
transmission = 200
|
||||
transact(bytes("O4{:02X}".format(transmission), "ascii"))
|
||||
print("transmission:", transmission)
|
||||
case "-":
|
||||
transmission -= 1
|
||||
if transmission < 0:
|
||||
transmission = 0
|
||||
transact(bytes("O4{:02X}".format(transmission), "ascii"))
|
||||
print("transmission:", transmission)
|
||||
case None:
|
||||
# keep the laser on (auto-shutdown if no comms for 30s)
|
||||
transact(b"W") # GetShortStatus
|
||||
finally:
|
||||
transact(b"X") # laser off
|
||||
print("laser is off")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user