Skip to content

How to work with multi-element properties? #51

@safrie

Description

@safrie

Some of the instruments I'd like to simulate have settings that contain multiple elements/variables. For example, if I want to set the ramp rate of a heater, I send the following:

RAMP {output_idx}, {enable}, {rate}

{output_idx} is the output channel, {enable} is whether or not the heater should be turned on, and {rate} is what rate you want the heating to proceed at. All three need to be specified at once. How do I store all three settings in one property?

I currently have {output_id} set up as a channel, since the examples show how to retrieve channel ids, and that works elsewhere in my file. However, my attempts to set parameters such as default and boundary values do not work by putting the separate values in as tuples, dicts, or lists.

my setup (using lists) is:

spec: "1.1"
devices:
    device1:
        eom:
            GPIB INSTR:
                q: "\n"
                r: "\r\n"
        error: ERROR
        channels:
            out:
                ids: [1, 2]
                can_select: True
                properties:
                    ramp:
                        default: [0, 0]
                        getter:
                            q: "RAMP? {ch_id}"
                            r: "{0:d}, {1:.1f"}
                        setter:
                            q: "RAMP {ch_id}, {0:d}, {1:.1f}"
                            r: "Output {ch_id} set to {1:.1f} K/min"
                        specs:
                            min: [0, 0]
                            max: [1, 100]
                            type: [int, float]
resources:
    GPIB:01::INSTR:
        device: device1

The error is:

TypeError: Could not parse definitions file. 'Traceback (most recent call last):
  File "C:\path\to\pyvisa-sim\parser.py", line 144, in update_component
    getter, setter, prop_dict.get(\'specs\', {}))
  File "C:\path\to\pyvisa-sim\channels.py", line 112, in add_property
    default_value, specs)
  File "C:\path\to\pyvisa-sim\channels.py", line 28, in __init__
    super(ChannelProperty, self).__init__(name, default_value, specs)
  File "C:\path\to\pyvisa-sim\component.py", line 50, in __init__
    specs[key] = t(specs[key])
TypeError: \'str\' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\path\to\pyvisa-sim\highlevel.py", line 65, in _init
    self.devices = parser.get_devices(self.library_path, False)
  File "C:\path\to\pyvisa-sim\parser.py", line 296, in get_devices
    get_device(device_name, dd, loader, resource_dict))
  File "C:\path\to\pyvisa-sim\parser.py", line 205, in get_device
    loader, resource_dict))
  File "C:\path\to\pyvisa-sim\parser.py", line 179, in get_channel
    update_component(ch_name, channels, channel_dict)
  File "C:\path\to\pyvisa-sim\parser.py", line 147, in update_component
    raise type(e)(msg % (name, prop_name, format_exc()))
TypeError: In device out, malformed property ramp
\'Traceback (most recent call last):
  File "C:\path\to\pyvisa-sim\parser.py", line 144, in update_component
    getter, setter, prop_dict.get(\'specs\', {}))
  File "C:\path\to\pyvisa-sim\channels.py", line 112, in add_property
    default_value, specs)
  File "C:\path\to\pyvisa-sim\channels.py", line 28, in __init__
    super(ChannelProperty, self).__init__(name, default_value, specs)
  File "C:\path\to\pyvisa-sim\component.py", line 50, in __init__
    specs[key] = t(specs[key])
TypeError: \'str\' object is not callable
\'
'

I cannot send the settings to the instrument as a list (i.e., no q: "RAMP {ch_id}, [{enable}, {rate}]"). Am I just wrong about how to specify/index entries to stringparser, or is this an absent feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions