Add instrument CLI commands
This commit is contained in:
@@ -125,5 +125,39 @@ def run_test_cmd(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@app.command(name="query")
|
||||||
|
def query_cmd(
|
||||||
|
instrument: Annotated[
|
||||||
|
str,
|
||||||
|
typer.Argument(help="Instrument to query (chamber, psu, or dmm)."),
|
||||||
|
],
|
||||||
|
command: Annotated[
|
||||||
|
str,
|
||||||
|
typer.Argument(help="SCPI command to send (e.g., *IDN?, TEMP:SETPOINT?)."),
|
||||||
|
],
|
||||||
|
config_file: Annotated[
|
||||||
|
str | None,
|
||||||
|
typer.Option("--config", "-c", help="Path to configuration YAML file."),
|
||||||
|
] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Send a SCPI command to an instrument and print the response.
|
||||||
|
|
||||||
|
Useful for debugging and manual instrument control. Connect to
|
||||||
|
instruments based on configuration and send raw SCPI commands.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
py-dvt-ate query chamber "*IDN?"
|
||||||
|
py-dvt-ate query psu "VOLT? 1"
|
||||||
|
py-dvt-ate query dmm "MEAS:VOLT:DC?"
|
||||||
|
"""
|
||||||
|
from py_dvt_ate.app.instrument_commands import query_instrument
|
||||||
|
|
||||||
|
query_instrument(
|
||||||
|
instrument=instrument,
|
||||||
|
command=command,
|
||||||
|
config_file=config_file,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app()
|
app()
|
||||||
|
|||||||
68
src/py_dvt_ate/app/instrument_commands.py
Normal file
68
src/py_dvt_ate/app/instrument_commands.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
"""Instrument query commands for CLI."""
|
||||||
|
|
||||||
|
import typer
|
||||||
|
|
||||||
|
from py_dvt_ate.app.config import load_config
|
||||||
|
from py_dvt_ate.instruments.factory import InstrumentConfig, InstrumentFactory
|
||||||
|
|
||||||
|
|
||||||
|
def query_instrument(
|
||||||
|
instrument: str,
|
||||||
|
command: str,
|
||||||
|
config_file: str | None = None,
|
||||||
|
) -> None:
|
||||||
|
"""Send a SCPI command to an instrument and print the response.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
instrument: Instrument to query (chamber, psu, or dmm).
|
||||||
|
command: SCPI command to send.
|
||||||
|
config_file: Path to configuration YAML file.
|
||||||
|
"""
|
||||||
|
# Load configuration
|
||||||
|
config_path = config_file or "config/default.yaml"
|
||||||
|
try:
|
||||||
|
config = load_config(config_path)
|
||||||
|
except FileNotFoundError as err:
|
||||||
|
typer.echo(f"Error: Configuration file not found: {config_path}", err=True)
|
||||||
|
raise typer.Exit(code=1) from err
|
||||||
|
except Exception as e:
|
||||||
|
typer.echo(f"Error loading configuration: {e}", err=True)
|
||||||
|
raise typer.Exit(code=1) from e
|
||||||
|
|
||||||
|
# Create instruments
|
||||||
|
try:
|
||||||
|
# Convert AppConfig to InstrumentConfig
|
||||||
|
inst_config = InstrumentConfig(
|
||||||
|
backend=config.instruments.backend,
|
||||||
|
simulator_host=config.instruments.simulator.host,
|
||||||
|
chamber_port=config.instruments.simulator.thermal_chamber_port,
|
||||||
|
psu_port=config.instruments.simulator.power_supply_port,
|
||||||
|
dmm_port=config.instruments.simulator.multimeter_port,
|
||||||
|
chamber_visa=config.instruments.pyvisa.thermal_chamber,
|
||||||
|
psu_visa=config.instruments.pyvisa.power_supply,
|
||||||
|
dmm_visa=config.instruments.pyvisa.multimeter,
|
||||||
|
)
|
||||||
|
instruments = InstrumentFactory.create(inst_config)
|
||||||
|
except Exception as e:
|
||||||
|
typer.echo(f"Error connecting to instruments: {e}", err=True)
|
||||||
|
raise typer.Exit(code=1) from e
|
||||||
|
|
||||||
|
# Send command to the specified instrument
|
||||||
|
try:
|
||||||
|
# Access the transport layer to send raw commands
|
||||||
|
if instrument == "chamber":
|
||||||
|
response = instruments.chamber._transport.query(command) # type: ignore[attr-defined]
|
||||||
|
elif instrument == "psu":
|
||||||
|
response = instruments.psu._transport.query(command) # type: ignore[attr-defined]
|
||||||
|
elif instrument == "dmm":
|
||||||
|
response = instruments.dmm._transport.query(command) # type: ignore[attr-defined]
|
||||||
|
else:
|
||||||
|
typer.echo(f"Error: Unknown instrument '{instrument}'", err=True)
|
||||||
|
typer.echo("Valid instruments: chamber, psu, dmm", err=True)
|
||||||
|
raise typer.Exit(code=1)
|
||||||
|
|
||||||
|
if response:
|
||||||
|
typer.echo(response)
|
||||||
|
except Exception as e:
|
||||||
|
typer.echo(f"Error sending command: {e}", err=True)
|
||||||
|
raise typer.Exit(code=1) from e
|
||||||
Reference in New Issue
Block a user