# Using Instrument plugins in non-testplan programs

**URL:** <https://forum.opentap.io/t/using-instrument-plugins-in-non-testplan-programs/2097>\
**Category:** Technical\
**Tags:** plugin\
**Created:** [August 21, 2024, 7:57am UTC](https://forum.opentap.io/t/using-instrument-plugins-in-non-testplan-programs/2097 "2024-08-21T07:57:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GoranJohnsson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/goranjohnsson/32/140_2.png) [@GoranJohnsson](https://forum.opentap.io/u/GoranJohnsson)\
**Post date:** [August 21, 2024, 7:57am UTC](https://forum.opentap.io/t/using-instrument-plugins-in-non-testplan-programs/2097/1 "2024-08-21T07:57:25Z")

</div>

In order to avoid having to re-create Instrument I/O in applictions that are not OpenTAP testplan based I want to re-use/consume some instrument plugins.

I created a simple Console app referencing a simple SCPI Instrument plugin DLL and OpenTAP nuget package.

Creating the object and setting the VISA address works wo any error but the base.Open() in the Open() method call throws an error: System.Exception: ‘Could not create VISA connection’.  
Code:  
MyInstrument1 myInstrument1 = new MyInstrument1();  
myInstrument1.VisaAddress = “GPIB0::17::INSTR”;  
myInstrument1.Open();

The plugin works fine when used in a testplan/teststep and I can communicate with the device using ConnectionExpert/InteractiveIO.

Any ideas?

---

<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:** [August 22, 2024, 2:21pm UTC](https://forum.opentap.io/t/using-instrument-plugins-in-non-testplan-programs/2097/2 "2024-08-22T14:21:57Z")

</div>

Hi @GoranJohnsson,

I think this is because OpenTAP puts all those dependencies in sub folders, so a standard .NET application cannot just resolve those paths.

To fix it you can force the plugin manager to initialize the DLL resolver using this code:

```cs
OpenTap.PluginManager.DirectoriesToSearch().ToList()

```

In OpenTAP 9.26 (upcomming release) you will be able to call, but its essentially the same.

```cs
OpenTap.PluginManager.Initialize();

```

---

<div class="post-metadata">

**Author:** ![GoranJohnsson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/goranjohnsson/32/140_2.png) [@GoranJohnsson](https://forum.opentap.io/u/GoranJohnsson)\
**Post date:** [August 22, 2024, 9:11pm UTC](https://forum.opentap.io/t/using-instrument-plugins-in-non-testplan-programs/2097/3 "2024-08-22T21:11:14Z")

</div>

Thanks!  
Thats seems to fix the problem. Not obvious.  
DirectoriesToSearch is a property, not a method.

I think main reason for the error was the VISA ResourceManager couldnt be started/found so no VISA session could be created.

---

<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:** [August 23, 2024, 8:17am UTC](https://forum.opentap.io/t/using-instrument-plugins-in-non-testplan-programs/2097/4 "2024-08-23T08:17:00Z")

</div>

> DirectoriesToSearch is a property, not a method.

This is because we just need the static constructor to be invoked. So doing anything with the PluginManager will do it, but nothing else is really safe to just call. That is why we are adding PluginManager.Initialize in the next version.
