This commit is contained in:
2025-12-16 19:46:23 +06:00
parent 736824952e
commit d86adac11c

View File

@@ -86,12 +86,20 @@ class PrologixEndpointLoop:
return default_cmds + extra return default_cmds + extra
return default_cmds return default_cmds
def _drain_errors(self, inst: Any, maxn: int = 20) -> list[str]:
out: list[str] = []
for _ in range(maxn):
e = str(inst.ask(":SYST:ERR?")).strip()
if e.startswith("0,") or "No error" in e:
break
out.append(e)
return out
def _init_device( def _init_device(
self, gpib_addr: int, driver_key: str, meta: dict[str, Any] self, gpib_addr: int, driver_key: str, meta: dict[str, Any]
) -> None: ) -> None:
key = (driver_key or "").strip().lower() key = (driver_key or "").strip().lower()
# Only init if the configured driver is explicitly Keithley2000
if key not in KEITHLEY_DRIVER_KEYS: if key not in KEITHLEY_DRIVER_KEYS:
self._initialized_addrs.add(gpib_addr) self._initialized_addrs.add(gpib_addr)
return return
@@ -108,11 +116,15 @@ class PrologixEndpointLoop:
inst.write(cmd) inst.write(cmd)
time.sleep(0.02) time.sleep(0.02)
# Read error after each command; stop early if something is wrong
err = str(inst.ask(":SYST:ERR?")).strip() err = str(inst.ask(":SYST:ERR?")).strip()
if not err.startswith("0,") and "No error" not in err: if err.startswith("0,") or "No error" in err:
log.error(f"Keithley init failed at {cmd}: {err}") continue
break
log.error(f"Keithley init error at {cmd}: {err}")
errs = self._drain_errors(inst)
if errs:
log.warning(f"Keithley @ {gpib_addr} init error queue leftover: {errs}")
self._initialized_addrs.add(gpib_addr) self._initialized_addrs.add(gpib_addr)
@@ -122,6 +134,7 @@ class PrologixEndpointLoop:
res = self.endpoint.conn["resource"] res = self.endpoint.conn["resource"]
to_ms = int(self.endpoint.conn.get("gpib_read_timeout_ms", 500)) to_ms = int(self.endpoint.conn.get("gpib_read_timeout_ms", 500))
log.info(f"gpib_read_timeout_ms set to {to_ms}")
# auto=False gives us manual control over addressing # auto=False gives us manual control over addressing
self._adapter = PrologixAdapter(res, gpib_read_timeout=to_ms, auto=False) self._adapter = PrologixAdapter(res, gpib_read_timeout=to_ms, auto=False)
@@ -208,7 +221,7 @@ class PrologixEndpointLoop:
) )
except Exception as e: except Exception as e:
log.error( log.error(
f"Prologix error {b.device.device_key}/{b.channel.metric}: {e}" f"Prologix error {b.device.device_key}/{b.channel.metric} query={b.query!r}: {e}"
) )
await self.writer.write_error( await self.writer.write_error(
device_id=b.device.device_id, error=f"prologix: {e}" device_id=b.device.device_id, error=f"prologix: {e}"