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

**URL:** <https://forum.opentap.io/t/scpiregexstep-didnt-call-the-scpiinstrument-open-in-wpf-gui-program/895>\
**Category:** General\
**Created:** [October 13, 2022, 11:49am UTC](https://forum.opentap.io/t/scpiregexstep-didnt-call-the-scpiinstrument-open-in-wpf-gui-program/895 "2022-10-13T11:49:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![allen](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@allen](https://forum.opentap.io/u/allen)\
**Post date:** [October 13, 2022, 11:49am UTC](https://forum.opentap.io/t/scpiregexstep-didnt-call-the-scpiinstrument-open-in-wpf-gui-program/895/1 "2022-10-13T11:49:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [October 13, 2022, 4:44pm UTC](https://forum.opentap.io/t/scpiregexstep-didnt-call-the-scpiinstrument-open-in-wpf-gui-program/895/2 "2022-10-13T16:44:02Z")

</div>

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

```csharp
Ì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.

---

<div class="post-metadata">

**Author:** ![allen](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@allen](https://forum.opentap.io/u/allen)\
**Post date:** [October 14, 2022, 8:46am UTC](https://forum.opentap.io/t/scpiregexstep-didnt-call-the-scpiinstrument-open-in-wpf-gui-program/895/3 "2022-10-14T08:46:48Z")

</div>

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();
    }

```
