pyvisa / pyvisa-sim

A PyVISA backend that simulates a large part of the "Virtual Instrument Software Architecture" (VISA_)
https://pyvisa-sim.readthedocs.io/en/latest/
MIT License
69 stars 39 forks source link

`main` branch no longer allows dialog-without-response #76

Closed dougthor42 closed 1 year ago

dougthor42 commented 1 year ago

In v0.5.1, a dialog that does not have a response is valid:

dialogues:
  - q: "*RST"

And when trying to read() after write("*RST") will result in a visa timeout error ('cause there's nothing in the read buffer).

instr.write("*RST")
instr.query()  # raises VisaIOError timeout error

But in main (b0c2282), it's no longer valid and raises an error when parsing the yaml:

    def update_component(
        name: str, comp: Component, component_dict: Dict[str, Any]
    ) -> None:
        """Get a component from a component dict."""
        for dia in component_dict.get("dialogues", ()):
            try:
                comp.add_dialogue(*_get_pair(dia))
            except Exception as e:
                msg = "In device %s, malformed dialogue %s\n%r"
>               raise Exception(msg % (name, dia, e))
E               Exception: In device SMU, malformed dialogue {'q': '*RST'}
E               KeyError('r')

My main question is: Is this intentional?

It looks like the change happened in 970c18db8, specifically here: https://github.com/pyvisa/pyvisa-sim/commit/970c18db8f6513a66fda71e33fd9018a3f4e75d9#diff-00ae6e38b897e23f5d5f4ba58764e2de759b6e39ab2db9ea9c57d9315a20def4L62-R72

Yes it's intentional

How should we define a command that shouldn't put anything in the read buffer?

The docs say to use a special null_response value, but that ends up actually getting returned:

dialogues:
  - q: "*RST"
    r: null_response
instr.write("*RST")
instr.query()  # expected: timeout error. Actual: "null_response"

Same with using null and the empty string `` in the yaml file:

dialogues:
  - q: "*RST"
    r: null
dialogues:
  - q: "*RST"
    r:

No, it's not intentional and is a bug

I'd be happy to add a test case for it and see if I can't resolve it.

MatthieuDartiailh commented 1 year ago

This is definitively a bug, stemming from some bad refactoring. If you can address it I would be very grateful.