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

Resolves #64 Feature suggestion: Connecting instruments #65

Open murvar opened 1 year ago

murvar commented 1 year ago

New feature: Connecting instruments.

By adding connections in the yaml-file an instrument can have connections to others (or itself) and apply a function when the query is called.

An example can be found in device 5 in default.yaml.

connections: power: q: "READ1" source_list: [ {source_name: "GPIB0::2::65535::INSTR", source_parameter: amplitude}, {source_name: "self", source_parameter: frequency} ] function: "0.23 * (%amplitude% ** 2) - %frequency%"

When using query "READ1" the device will fetch amplitude from another source and frequency from itself then return power, applying the function.

I have also added a new test in test_all.py for connections.

This is the way my team have requested connection functionality. Please give any feedback as we would like this to be as valuable for the community as possible!

murvar commented 1 year ago

Any idea why my connection test fails? It works fine locally.

MatthieuDartiailh commented 1 year ago

Tests fail on master too sadly (your pyvisa version may be outdated since the GPIB secondary address is not part of the normalized resource name anymore if the secondary address is not set).

I am preparing a modernized version of the code base. I may ask you to rebase your work on it so that we get tests to pass.

MatthieuDartiailh commented 1 year ago

I merged my clean up PR so you will need to update your changes. Since this is my fault for not updating ths project for so long let me know if you do not have the bandwidth to do the changes and I can do them.

murvar commented 1 year ago

I will have a look at this tomorrow. Thank you for the fast update!

MatthieuDartiailh commented 1 year ago

It is not often I get somebody interested to put work in so I try to keep the momentum

murvar commented 1 year ago

I'm having problems installing the latest version. ERROR: Could not find a version that satisfies the requirement setuptools>=61.2 (from versions:...)ERROR: No matching distribution found for setuptools>=61.2

MatthieuDartiailh commented 1 year ago

Do you have internet access ? pip errors if it cannot look up build dependencies (even if it has local caches, which is extremely annoying but it did not yet dive to figure out the option to avoid that issue).

murvar commented 1 year ago

Could it be that I'm using Python 3.6? The newest version of Setuptools I get is 59.6.0. This is the version we use in our project so I'd rather not update to 3.8.

murvar commented 1 year ago

3.8 fixed my issue fyi.

MatthieuDartiailh commented 1 year ago

I am sorry but I do not have the bandwidth to keep supporting 3.6 which is EOL.

MatthieuDartiailh commented 1 year ago

There are still conflict and the history is change set is weird. It may be worth simply cherry-picking your changes on top of main (modulo the required changes).

murvar commented 1 year ago

As mentioned before, this is my first time working open source like this. What does module mean in this context? Is there anything more I can do to get this approved? If you prefer, you're welcome to do the required fixes.

MatthieuDartiailh commented 1 year ago

In order for this to get merged, you need to first address the conflicts. However I am a bit concerned by the fact that your PR looks like it contains many more changes than I would expect. It may be easier to redo your changes on top of main. Feel free to force push to this branch if necessary.

And by modulo (not module), I simply implied that because of the many changes I made you are unlikely to be able to only cherry-pick your changes on top of main because there will be conflicts that will need to be handled.

murvar commented 1 year ago

I'm having trouble with the MyPy errors. Do you have any suggestions for fixing them?

MatthieuDartiailh commented 1 year ago

One legitimate complaint from mypy is that Channel.add_dialogue signature does not match the signature in the base class. You can probably through some minor refactoring re-use the Component implementation in the Channel one (since the only difference is storing the result under __default__, rather than at the root of the dictionary)

murvar commented 1 year ago

One legitimate complaint from mypy is that Channel.add_dialogue signature does not match the signature in the base class.

This should be fixed now along with the formatting complaints.