Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid power meter unresponsive state #5

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions yaqd_thorlabs/_thorlabs_pm_triggered.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,28 @@ def __init__(self, name, config, config_filepath):

async def _measure(self):
start = time.time()
try:
self.inst.write("ABORt; INIT")
self._check_inst()
await asyncio.sleep(4e-4 * self.averaging) # important to wait for requests
for _ in range(10):
status = int(self.inst.query("STAT:OPER?")[:-1])
out = float(self.inst.query("FETCh?")[:-1])
if status & (1 << 9):
end = time.time()
self.logger.debug(f"dt: {(end-start):0.3f}, sig {out:1.6f}")
break
self.logger.debug(f"status: {bin(status)} ({status}), out {out}")
await asyncio.sleep(0)
else:
self.logger.error("measure timeout; retrying")
return await self._measure()
return {"power": float(out)}
except Exception as e: # pyvisa.errors.VisaIOError as e:
self.logger.error(e)
return await self._measure()
while True:
try:
self.inst.write("ABORt; INIT")
self._check_inst()
await asyncio.sleep(4e-4 * self.averaging) # important to wait for requests
for _ in range(10):
status = int(self.inst.query("STAT:OPER?")[:-1])
out = float(self.inst.query("FETCh?")[:-1])
if status & (1 << 9):
end = time.time()
self.logger.debug(f"dt: {(end-start):0.3f}, sig {out:1.6f}")
break
self.logger.debug(f"status: {bin(status)} ({status}), out {out}")
await asyncio.sleep(0)
else:
self.logger.error("measure timeout; retrying")
continue
except pyvisa.errors.VisaIOError as e:
self.logger.error(repr(e))
continue
break
return {"power": float(out)}

def direct_serial_write(self, write: bytes) -> None:
out = self.inst.write(write.decode())
Expand Down