mpylab.tools.visa_probe module

Safely probe one explicitly named VISA resource without discovery.

class mpylab.tools.visa_probe.VisaProbeResult(resource: str, backend: str, query: str | None, response: str | None)

Bases: object

Result of opening one VISA resource and optionally sending one query.

Parameters:
  • resource – Explicit VISA resource name that was opened.

  • backend – Description of the selected PyVISA backend.

  • query – Query sent to the device, or None for an open-only probe.

  • response – Stripped device response, or None without a query.

backend: str
query: str | None
resource: str
response: str | None
mpylab.tools.visa_probe.main(argv=None) int

Run the mpylab-visa-probe command.

Parameters:

argv – Optional command-line arguments without the executable name. If omitted, arguments are read from sys.argv by argparse.

Returns:

Process exit status: 0 on success, 1 for a VISA error, or 2 for an invalid safe-probe argument.

mpylab.tools.visa_probe.probe_resource(resource: str, *, query: str | None = None, timeout_ms: int = 3000, resource_manager_factory: Callable | None = None) VisaProbeResult

Open one explicit VISA resource and optionally send one read-only query.

The function deliberately does not call list_resources. This avoids unrelated serial, USB, and Zeroconf network discovery when only one known resource should be checked.

Parameters:
  • resource – Explicit VISA resource, for example GPIB0::29::INSTR.

  • query – Optional single query. It must end in ? and cannot contain ;. If omitted, the resource is only opened and closed.

  • timeout_ms – VISA operation timeout in milliseconds; must be positive.

  • resource_manager_factory – Optional factory used for isolated tests. Production code uses mpylab’s configured PyVISA resource manager.

Returns:

Resource, backend, query, and optional response information.

Raises:
  • ValueError – If an argument violates the safe probe contract.

  • Exception – If the VISA backend cannot open, query, or close cleanly.