# Add an instrument resource dynamically?

**URL:** <https://forum.opentap.io/t/add-an-instrument-resource-dynamically/267>\
**Category:** Technical\
**Created:** [March 14, 2021, 1:11pm UTC](https://forum.opentap.io/t/add-an-instrument-resource-dynamically/267 "2021-03-14T13:11:24Z")\
**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:** [March 14, 2021, 1:11pm UTC](https://forum.opentap.io/t/add-an-instrument-resource-dynamically/267/1 "2021-03-14T13:11:24Z")

</div>

Is it possible to create an Instrument/ScpiInstrument at run time within a Teststep?  
Create, open, use and close, all from a Teststep (PreRun,Run,PostRun)?

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [March 15, 2021, 4:26pm UTC](https://forum.opentap.io/t/add-an-instrument-resource-dynamically/267/2 "2021-03-15T16:26:13Z")

</div>

@GoranJohnsson you may be able to do this by creating a new instrument and calling the Open/Close methods directly. Can you share a bit more on why you need this so we can help provide a recommendation?  
At a minimum, it seems like you may want to type of dummy Instrument that you manage all of this under.

We also have the concept of a short lived connection, which depending on what you are trying to do, may work better.

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [March 15, 2021, 4:29pm UTC](https://forum.opentap.io/t/add-an-instrument-resource-dynamically/267/3 "2021-03-15T16:29:26Z")

</div>

You should be able to create and use an Instrument from within a test step. However, I believe you’ll be responsible for calling all of its methods (Open, PreRun, Run, etc).

---

<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:** [March 15, 2021, 8:13pm UTC](https://forum.opentap.io/t/add-an-instrument-resource-dynamically/267/4 "2021-03-15T20:13:19Z")

</div>

Yes, it seems to work to create an instrument (I guess you have to create a dummy class since ScipInstrument (and Dut) are abstract classes) and then instansiate/open/use/close as needed from within the teststep.  
Sometimes the resource cannot be opened until UUT is powered up (a virtual serial port on the UUT) and you need more explicit control.
