mpylab.device.pm_virtual module

Virtual power meter driver for deterministic test scenarios.

class mpylab.device.pm_virtual.POWERMETER(**kw)

Bases: POWERMETER

Simulate power readings from expressions or a coupled RF source.

Parameters:

kw (mapping) – Keyword arguments forwarded to the base power meter, including SearchPaths.

BindVirtualDevices(devices)

Attach graph-local devices used by source coupling.

Parameters:

devices (mapping) – Graph device instances indexed by graph name.

GetData()

Calculate virtual power including uncertainty.

Returns:

(0, power) with a scuq.Quantity in watts.

Return type:

tuple

GetDataNB(retrigger=False)

Return power through the non-blocking interface.

Parameters:

retrigger (bool or str, optional) – Trigger again after reading when true or equal to "on".

Returns:

Same result as GetData().

Return type:

tuple

GetDescription()

Return virtual instrument identification.

Returns:

(0, identification).

Return type:

tuple

Init(ini=None, channel=None, ignore_bus=None)

Initialize expressions and optional source coupling.

Parameters:
  • ini (path-like or file-like, optional) – Virtual power-meter configuration source.

  • channel (int or str, optional) – Measurement channel; channel one is used by default.

Returns:

Device status; zero indicates success.

Return type:

int

SetFreq(freq)

Set virtual measurement frequency.

Parameters:

freq (float) – Frequency in hertz.

Returns:

(0, frequency).

Return type:

tuple

conftmpl = {'channel_%d': {'file': <function _file_source>, 'filter': <class 'int'>, 'interpolation': <class 'str'>, 'manrange': <class 'float'>, 'name': <class 'str'>, 'rangemode': <class 'str'>, 'resolution': <class 'int'>, 'sensor': <class 'str'>, 'source': <class 'str'>, 'source_compression_slope': <class 'str'>, 'source_compression_start_dbm': <class 'str'>, 'source_gain_db': <class 'str'>, 'swr1': <class 'float'>, 'swr2': <class 'float'>, 'uncertainty': <class 'str'>, 'unit': <class 'str'>, 'value': <class 'str'>}, 'description': {'description': <class 'str'>, 'deviceid': <class 'str'>, 'driver': <class 'str'>, 'serialnr': <class 'str'>, 'type': <class 'str'>, 'vendor': <class 'str'>}, 'init_value': {'fstart': <class 'float'>, 'fstep': <class 'float'>, 'fstop': <class 'float'>, 'gpib': <class 'int'>, 'nr_of_channels': <class 'int'>, 'virtual': <function strbool>, 'visa': <class 'str'>}}
query(cmd, tmpl=None, send_opc=False)

Write a command and return its virtual response.

Parameters:
  • cmd (str) – SCPI-like command.

  • tmpl (str, optional) – Regular expression used to parse the response.

  • send_opc (bool, optional) – Return an operation-complete response after a non-query command.

Returns:

Raw or parsed response.

Return type:

str or dict

read(tmpl=None)

Read the last virtual SCPI response.

Parameters:

tmpl (str, optional) – Regular expression with named groups used to parse the response.

Returns:

Raw response when tmpl is omitted, otherwise matching named groups or an empty dictionary.

Return type:

str or dict

write(cmd)

Handle one command through the virtual SCPI facade.

Parameters:

cmd (str) – SCPI-like command supported by the virtual driver.

Returns:

Zero after processing the command.

Return type:

int

mpylab.device.pm_virtual.main()

Run a simple standalone smoke test for the virtual power meter.