This commit is contained in:
2025-12-16 19:20:38 +06:00
parent c77ab22055
commit c8342a62c2

View File

@@ -14,6 +14,8 @@ from ..writer import Writer
log = logging.getLogger(__name__)
KEITHLEY_DRIVER_KEYS = {"keithley2000", "keithley_2000"}
@dataclass(frozen=True)
class PrologixBinding:
@@ -27,7 +29,7 @@ def _driver_class(driver_key: str | None) -> type[Any] | None:
key = (driver_key or "").strip().lower()
if not key:
return None
if key in {"keithley2000", "keithley_2000"}:
if key in KEITHLEY_DRIVER_KEYS:
from pymeasure.instruments.keithley import Keithley2000 # type: ignore
return Keithley2000
@@ -67,11 +69,8 @@ class PrologixEndpointLoop:
":SENS:VOLT:DC:NPLC 10", # slow/low-noise integration
":SENS:VOLT:DC:DIG 7", # max digits
# offset drift?
":SYST:AZER ON",
":SYST:AZER:STAT ON",
":TRIG:SOUR IMM",
":TRIG:COUN 1",
":SAMP:COUN 1",
":INIT:CONT OFF",
]
extra = dev_meta.get("init_cmds")
@@ -80,29 +79,32 @@ class PrologixEndpointLoop:
return default_cmds
def _init_device(
self, gpib_addr: int, driver_key: str | None, meta: dict[str, Any]
self, gpib_addr: int, driver_key: str, meta: dict[str, Any]
) -> None:
dk = (driver_key or "").lower()
if "keithley" not in dk:
key = (driver_key or "").strip().lower()
# Only init if the configured driver is explicitly Keithley2000
if key not in KEITHLEY_DRIVER_KEYS:
self._initialized_addrs.add(gpib_addr)
return
cmds = self._keithley2000_init_cmds(meta)
log.info(f"Initializing Keithley @ {gpib_addr} with {len(cmds)} SCPI cmds")
if driver_key:
inst = self._get_instrument(gpib_addr, driver_key)
# make sure prologix is pointed at the right addr
self._get_adapter().address = gpib_addr
for cmd in cmds:
inst.write(cmd)
time.sleep(0.02)
else:
ad = self._get_adapter()
ad.address = gpib_addr
for cmd in cmds:
ad.write(cmd)
time.sleep(0.02)
inst = self._get_instrument(
gpib_addr, driver_key
) # driver_key is not None here
self._get_adapter().address = gpib_addr
for cmd in cmds:
inst.write(cmd)
time.sleep(0.02)
# Read error after each command; stop early if something is wrong
err = str(inst.ask(":SYST:ERR?")).strip()
if not err.startswith("0,") and "No error" not in err:
log.error(f"Keithley init failed at {cmd}: {err}")
break
self._initialized_addrs.add(gpib_addr)