bicarlsen / easy-scpi

A library to control SCPI instruments
GNU General Public License v3.0
52 stars 20 forks source link

Feature request: optionally permit topmost SCPI class NAME to emit :NAME instead of NAME + raw sketch #16

Open jakobi opened 7 months ago

jakobi commented 7 months ago

Use case: Owon HDS200 series scope meter.

In this SCPI dialect, normal commands and queries usually(?) start with a mandatory ":".

Currently INSTRUMENT.chan.("OFF") sends CHAN OFF to the device. For the Owon to not ignore command, it must begin with a colon: i.e. :CHAN OFF to turn off the signal generator channel.

As expected, INSTRUMENT.:chan("OFF") and variants make Python throw errors, while easy-scpi already properly injects colons deeper in the hierarchy: INSTRUMENT.foo.bar(42) translates to <>FOO<:>BAR 42 (<> marks the spots).

So my issue is just a way to add the missing first colon on (some?) sent commands.

Possible implementation for this:

In the invoking script, permit the use of some horribly long "unique" string such as REPLACEBYCOLON as prefix to <SCPI-CLASS-NAME>.

Then mangle the used top class name of the command before sending by substituting REPLACEBYCOLON with just a colon. A global prefix on sending will probably have to implement exceptions, as e.g. the Owon dialect and esp. the programming guide are a bit - hmmm - funny.

Maybe make REPLACEBYCOLON configurable for the caller, thus that on collision or via eval the user can can change it or turn it off for a bit..

Thx, Peter

bicarlsen commented 7 months ago

I no longer work with SCPI machines, so won't implement it, but am happy to accept a PR.

jakobi commented 7 months ago

So adding 2 ways to mangle the top class name: Above scheme, plus a black/whitelist, or maybe just an optionally mangling callback, with a usable predefined example callback using in-instance attributes for above scheme and some black/whitelist and maybe a regex based substitution?

Maje these attributes into the instance that needs mangling, and there's no need for on/off, as I use different instances for different devices. Say, a instance that to mangling for the OWON scopemeter and one without for say a RIGOL scope and a 3rd for talking to a KORAD power supply?

And I can also get a contrib directory (owon use requires using a slightly patched usb2hdi, as I only managed to get tcp sockets to work for it in pyvisa). So a timestamped copy of hid2tcp, with a pair of patches (one minimal, one to better cope with the OWON's sleep habbits, upto yet-to-code infrequent reconnecting attempts)?

I will require a bit of review, otherwise easy-scpi will end up with with a few shiny spots of syntactically correct PYTHON line noise (or whatever PERL's pet name is these days).

Sounds ok?

bicarlsen commented 7 months ago

I didn't understand most of what you described. From what I do understand though, you want a way to prefix calls with a colon.

I think it should be fairly simple to add an option on Property that will do this in call, though.