How to add a SCPI Serial instrument

Hello,
I want to add a SCPI Serial instrument, because the default ScpiInstrument can’t set the baudrate and so on, but when i wait to add this SCPI Serial instrument, i can’t access the Visa class, so i don’t how to do, could you pls help me?
Thanks.

Hello @jesse123!

I did something similar a while back. You need to create your own class and implement the IScpiIO2 interface. Then, you can pass your IScpiIO2 implementation to the the ScpiInstrument constructor.

A quick way to implement your IScpiIO2 interface, would be to copy the default ScpiIO implementation here: https://github.com/opentap/opentap/blob/a09f3c1ab9265af52149bb7153a844394e584783/Engine/ScpiIO.cs#L9

You can see that there is an OpenTap.Visa class referenced by the default ScpiIO implementation. With that you can call any method/attribute get/set in VISA library. Create a custom Property that you expose through your instrument plugin (baudrate/flow control/etc…), and you should be able to accomplish what you want.

Hello @alan_copeland
Thanks for your asnwer, but the Visa access permission is internal, so the interface implement base on the IScpiIO2 is not allow as a plugins, it’s than right?

You can set the IScpiIO used in the constructor like this:

        public class MyScpiInstrument : ScpiInstrument
        {
            public MyScpiInstrument() : base(new MyScpiIo())
            {
                IO.SRQ += sender => Log.Debug("SRQ"); // unused.
            }
            
            public MyScpiIO IO => ((IScpiInstrument)this).IO as MyScpiIO;
        }