SCPIRegexStep didn't call the scpiInstrument.Open() in wpf GUI program

I am trying to write a new editor.exe, using wpf. In the main window, I add a button. When I click the button, I create a new TestPlan, add a SCPIRegexStep to the TestPlan and execute the TestPlan.
I have already set a scpiInstrument with VISA address by the Keysight GUI Editor.exe.
But the program didn’t call the Open() method of the ScpiInstrument. I debug with the source code of OpenTAP 9.8.15, and found that the progrom called ResourceTaskManager.OpenResource, and execute the first code “await canStart;” and exit the function. The following code after the first line of the function is not called.

If I create a console application, and write the same code, the console application can send scpi command the the scpiInstrument successfully.

The code I use is similar to the example of BuildTestPlan.Api, shown as follow:
private void Button_Click(object sender, RoutedEventArgs e)
{
PluginManager.SearchAsync();
SessionLogs.Initialize(“console_log.txt”);

TestPlan myTestPlan = new TestPlan();

myTestPlan.ChildTestSteps.Add(new SCPIRegexStep());
string myFilePath = myTestPlan.Name + "3.TapPlan";
myTestPlan.Save(myFilePath);
List<ResultListener> resultListeners = new List<ResultListener>();
resultListeners.Add(new LogResultListener());
myTestPlan.Execute(resultListeners);
SessionLogs.Rename("sessionLog.txt");
MessageBox.Show("Press any key to exit.");

}
Can any one help me on this issue? Thanks a lot.

1 Like

The easiest is probably to add your ScpiInstrument to the instrument settings.

ÌnstrrumentSettings.Current.Add(instrument);

Then the test step should automatically select the appropriate instrument when you instanciate it or when you load a test plan.

Otherwise you can also manually assign it to the instrument property of SCPIRegexStep.

1 Like

Great,it really works. Many thanks.
The effective code is as follows:
private void Button_Click(object sender, RoutedEventArgs e)
{
PluginManager.SearchAsync();
SessionLogs.Initialize(“wpf_log.txt”);

        ScpiInstrument instrument = new ScpiInstrument();
        instrument.VisaAddress = "TCPIP::192.168.1.66::INSTR";
        InstrumentSettings.Current.Add(instrument);

        TestPlan myTestPlan = new TestPlan();
        SCPIRegexStep step = new SCPIRegexStep();
        myTestPlan.ChildTestSteps.Add(step);
        myTestPlan.ExecuteAsync();
    }
1 Like