plesty.pm100d.base_device
Base device implementation for the Thorlabs PM100D optical power and energy meter.
Classes
Base device class for the Thorlabs PM100D optical power and energy meter. |
Module Contents
- class plesty.pm100d.base_device.BaseDevice(address: str = 'USB::0x1313::0x8078::INSTR', timeout: int = 200)
Bases:
plesty.lib.device.base_device_sync.BaseDeviceSyncModelBase 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 fromschema_func.json(measure_power, measure_energy, measure_current, measure_voltage, measure_frequency, measure_temperature, get_sensor_info, zero_sensor).- Parameters:
address (str) – VISA resource string for the instrument, e.g.
'USB::0x1313::0x8078::P0000118::INSTR'. UseVisaTrafficManager.discover_instrument()or NI-MAX to find the correct address.timeout (int) – VISA communication timeout in milliseconds. Default is 5000 ms.
Initialise the PM100D device with a VISA address and timeout.
- Parameters:
address (str) – VISA resource string, e.g.
'USB::0x1313::0x8078::P0000118::INSTR'.timeout (int) – 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.
- _address = 'USB::0x1313::0x8078::INSTR'
- _timeout = 200
- _tm: plesty.lib.traffic.visa.VisaTrafficManager | None = None
- _param_solver: plesty.lib.solver.scpi.SCPISolver | None = None
- init(main: object = None) None
Instantiate the traffic manager and bind both SCPI solvers.
Creates the
VisaTrafficManagerandSCPISolver(for params) and the_Pm100dOpSolver(for function calls), but does not open the VISA connection. Callconnect()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.- Parameters:
main (object) – Unused; accepted for interface compatibility.
- Return type:
None
- connect() bool
Open the VISA connection to the PM100D.
Calls
init()if the traffic manager has not been created, then opens the VISA session.- Returns:
Trueif the connection is successfully open,Falseotherwise.- Return type:
bool
- 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.jsonand 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
Noneif it could not be read.- Return type:
str | None
- disconnect() None
Close the VISA connection and release all resources.
- Return type:
None
- _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
write()is invoked.- Parameters:
key (str) – Parameter key registered in the param schema.
value (str | float | int | bool) – Value to write.
**kwargs (Any) – Additional keyword arguments (unused; accepted for interface compatibility).
- Returns:
Trueif the write command was dispatched successfully.- Return type:
bool
- _query_(key: str, **kwargs: Any) str | None
Query a parameter value from the device via SCPI.
Called automatically by the ConfigSystem when
query()is invoked.- Parameters:
key (str) – Parameter key registered in the param schema.
**kwargs (Any) – Additional keyword arguments (unused; accepted for interface compatibility).
- Returns:
Raw response string from the device, or
Noneif no query command is defined for this parameter.- Return type:
str | None
- identity() str
Return the instrument identification string (
*IDN?).- Returns:
Identification string in the form
'THORLABS,PM100D,<serial>,<firmware>'.- Return type:
str
- 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.- Return type:
list[str]
- check_operatability() bool
Return
Trueif the VISA session is open.- Returns:
Truewhen the traffic manager exists and its session is open.- Return type:
bool
- query_param_range(key: str) tuple[float | int | None, float | int | None]
Return the sensor-dependent hardware range for a parameter key.
Queries
<CMD>? MIN/<CMD>? MAXon 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.- Parameters:
key (str) – Parameter key registered in the param schema.
- Returns:
(min_value, max_value); either element isNonewhen the limit cannot be determined.- Return type:
tuple[float | int | None, float | int | None]
- reset() None
Send
*RSTto return the instrument to its factory default state.- Return type:
None
- clear() None
Send
*CLSto clear the status registers and error queue.- Return type:
None