SCPI Instrument resource opening

Hi,
I created a DmmInstrument class derived from the SCPIInstrument class. Then I created two other classes DmmVoltageMeas and DmmCurrentMeas derived from TestStep class, both using the DmmInstrument class.
Finally I generated a TestPlan with the two TestSteps in sequence.
The result is an error on opening resource: the first step open correctly the resource and respond to *IDN? the second one doesn’t respond and generate an error. I think that the problem is that TestPlan call Open method for all steps before execute Run method .
There is a way to open resource only when previuos is closed?
Thanks in advance for help

2 Likes

@ralphmagpie first off, welcome!

In your case, do you really only have 1 DMM instrument? There should not be a need to open and close the resource between test steps. The general flow is that the resource is automatically opened on the PrePlanRun, and the closed on the PostPlanRun.

Is it possible that you are trying to manage these resources (new instances, open/close) manually, rather than letting the engine control them? You can see an example of how to reference instruments from within Test Steps here:

If I am off on my guess, if you are able to share show code snippets, someone here can help look in to it further.

2 Likes

Hello @ralphmagpie and welcome to the forum!

I agree with Brennen, the open/close on the instrument should only be executed once throughout the execution of your test sequence, the engine takes care of this.

I implemented a very simple instrument and a couple of test steps that call the instrument:

namespace OpenTap.Plugins.MyPlugin1
{
[Display(“MyInstrument1”, Group: “OpenTap.Plugins.MyPlugin1”, Description: “Insert a description here”)]
public class MyInstrument1 : ScpiInstrument
{
#region Settings
// ToDo: Add property here for each parameter the end user should be able to change
#endregion

    public MyInstrument1()
    {
        Name = "MyINST";
    }

    /// <summary>
    /// Open procedure for the instrument.
    /// </summary>
    public override void Open()
    {
        base.Open();
    }

    /// <summary>
    /// Close procedure for the instrument.
    /// </summary>
    public override void Close()
    {
        base.Close();
    }

    public double MeasVoltage()
    {
        Log.Info("Instrument->MeasVoltage()");
        return 3.7;
    }

    public double MeasCurrent()
    {
        Log.Info("Instrument->MeasCurrent()");
        return 1.2;
    }
}

[Display("Meas Volt", Group: "OpenTap.Plugins.MyPlugin1", Description: "Insert description here")]
public class MeasVoltTestStep : TestStep
{
    #region Settings
    public MyInstrument1 MyInstrument1 { get; set; }
    #endregion

    public MeasVoltTestStep()
    {

    }

    public override void Run()
    {
        double volt = MyInstrument1.MeasVoltage();

        Log.Info("Measured Voltage: " + volt);

        // If no verdict is used, the verdict will default to NotSet.
        // You can change the verdict using UpgradeVerdict() as shown below.
        UpgradeVerdict(Verdict.Pass);
    }
}

[Display("Meas Current", Group: "OpenTap.Plugins.MyPlugin1", Description: "Insert description here")]
public class MeasCurrentTestStep : TestStep
{
    #region Settings
    public MyInstrument1 MyInstrument1 { get; set; }
    #endregion

    public MeasCurrentTestStep()
    {

    }

    public override void Run()
    {
        double current = MyInstrument1.MeasCurrent();

        Log.Info("Measured Current: " + current);

        // If no verdict is used, the verdict will default to NotSet.
        // You can change the verdict using UpgradeVerdict() as shown below.
        UpgradeVerdict(Verdict.Pass);
    }
}

}

Notice on the log how the Open is executed at the beggining of the test sequence and then is closed right before the sequence has completed (the two highlighted lines on the log):

Hope this helps you fix your implementation, otherwise feel free to share your snippet and we can review it for you,

Carlos Montes

1 Like

Thanks a lot Brennen and Carlos. This way I solved iussue
Ralph

1 Like