plesty.pm100d.base_device ========================= .. py:module:: plesty.pm100d.base_device .. autoapi-nested-parse:: Base device implementation for the Thorlabs PM100D optical power and energy meter. Classes ------- .. autoapisummary:: plesty.pm100d.base_device.BaseDevice Module Contents --------------- .. py:class:: BaseDevice(address: str = 'USB::0x1313::0x8078::INSTR', timeout: int = 200) Bases: :py:obj:`plesty.lib.device.base_device_sync.BaseDeviceSyncModel` Base device class for the Thorlabs PM100D optical power and energy meter. The PM100D is a handheld USB optical power and energy meter. It connects via USB (USB-TMC class) and is controlled using the SCPI (Standard Commands for Programmable Instruments) protocol over a VISA interface. Supports Thorlabs C-series photodiode, thermal, and pyroelectric sensors. Parameters are registered from ``schema_param.json`` (wavelength, averaging, power range, power unit, attenuation, beam diameter). Functions are registered from ``schema_func.json`` (measure_power, measure_energy, measure_current, measure_voltage, measure_frequency, measure_temperature, get_sensor_info, zero_sensor). :param address: VISA resource string for the instrument, e.g. ``'USB::0x1313::0x8078::P0000118::INSTR'``. Use ``VisaTrafficManager.discover_instrument()`` or NI-MAX to find the correct address. :param timeout: VISA communication timeout in milliseconds. Default is 5000 ms. Initialise the PM100D device with a VISA address and timeout. :param address: VISA resource string, e.g. ``'USB::0x1313::0x8078::P0000118::INSTR'``. :param timeout: VISA communication timeout in milliseconds. The default is measured, not guessed: on the fitted meter every query and measurement answers within 30 ms at the p95, so 200 ms is about eight times the worst observed case. Averaged measurements get their own, longer budget. .. py:attribute:: _address :value: 'USB::0x1313::0x8078::INSTR' .. py:attribute:: _timeout :value: 200 .. py:attribute:: _tm :type: plesty.lib.traffic.visa.VisaTrafficManager | None :value: None .. py:attribute:: _param_solver :type: plesty.lib.solver.scpi.SCPISolver | None :value: None .. py:method:: init(main: object = None) -> None Instantiate the traffic manager and bind both SCPI solvers. Creates the ``VisaTrafficManager`` and ``SCPISolver`` (for params) and the ``_Pm100dOpSolver`` (for function calls), but does **not** open the VISA connection. Call :meth:`connect` to open the session. With ``address="mock"`` an in-memory SCPI simulator replaces the VISA traffic manager, so the whole stack runs without an instrument. :param main: Unused; accepted for interface compatibility. .. py:method:: connect() -> bool Open the VISA connection to the PM100D. Calls :meth:`init` if the traffic manager has not been created, then opens the VISA session. :returns: ``True`` if the connection is successfully open, ``False`` otherwise. .. py:method:: apply_sensor_limits() -> str | None Narrow the parameter ranges to what the fitted sensor accepts. The schema carries the console-wide envelope on purpose — one module serves every head — so a value can pass validation and still be rejected by the instrument. The fitted S130C accepts 400-1100 nm where the schema declares 185-25000. The measured limits per head live in ``sensor_capabilities.json`` and are applied here, which is what the schema descriptions have always promised. A head with nothing recorded keeps the console envelope: inheriting another sensor's limits would be worse than being permissive. :returns: The sensor name, or ``None`` if it could not be read. .. py:method:: disconnect() -> None Close the VISA connection and release all resources. .. py:method:: _write_(key: str, value: str | float | int | bool, **kwargs: Any) -> bool Write a parameter value to the device via SCPI. Called automatically by the ConfigSystem when :meth:`write` is invoked. :param key: Parameter key registered in the param schema. :param value: Value to write. :param \*\*kwargs: Additional keyword arguments (unused; accepted for interface compatibility). :returns: ``True`` if the write command was dispatched successfully. .. py:method:: _query_(key: str, **kwargs: Any) -> str | None Query a parameter value from the device via SCPI. Called automatically by the ConfigSystem when :meth:`query` is invoked. :param key: Parameter key registered in the param schema. :param \*\*kwargs: Additional keyword arguments (unused; accepted for interface compatibility). :returns: Raw response string from the device, or ``None`` if no query command is defined for this parameter. .. py:method:: identity() -> str Return the instrument identification string (``*IDN?``). :returns: Identification string in the form ``'THORLABS,PM100D,,'``. .. py:method:: check_errors() -> list[str] Query the error queue and return any active error messages. :returns: Empty list when the device reports no error (``0,"No error"``); a one-element list containing the raw error string otherwise. .. py:method:: check_operatability() -> bool Return ``True`` if the VISA session is open. :returns: ``True`` when the traffic manager exists and its session is open. .. py:method:: query_param_range(key: str) -> tuple[float | int | None, float | int | None] Return the sensor-dependent hardware range for a parameter key. Queries ``? MIN`` / ``? MAX`` on the instrument, which reports the limits of the currently attached sensor (e.g. the valid wavelength span of an S120C vs. an S155C, or the manual power range). ``synchronize_param_from_device(sync_constraints=True)`` calls this to replace the static schema envelope with the real sensor limits. :param key: Parameter key registered in the param schema. :returns: ``(min_value, max_value)``; either element is ``None`` when the limit cannot be determined. .. py:method:: reset() -> None Send ``*RST`` to return the instrument to its factory default state. .. py:method:: clear() -> None Send ``*CLS`` to clear the status registers and error queue.