Instrument Opening using bench settings

Hi everyone,

Just wanted to understand how OpenTAP handles the following scenario:

  1. TestStepA has an instrument component InstrumentMeter1 (property with default get/set ,methods) which is of type InstrumentMeter.
  2. These properties are marked as XmlIgnore and are not serialized.
  3. In the bench settings (Instruments.xml), there are multiple entries for the component InstrumentMeter but with different names. For example, InstrumentMeter1, InstrumentMeter2, InstrumentMeter3.

When the resources are opened, I would assume it is based on the first entry that matches the type, as mentioned in the documentation. Just wanted to confirm if this behaviour is true and is always the case?

For this case, is it recommended to configure via the Bench and code to specifically connect to the first instrument? E.g. using the InstrumentSetttings.Current.FirstOrDefault?

And what about for the case where a test step uses multiple instruments of the same type? E.g. it uses InstrumentMeter1 and InstrumentMeter2, I would assume we would need to write code to connect accordingly?

Hi @antonio.quizon,

Actually it not related to how things are “Opened” but rather how they are “initialized”. When a test step is instanciated we try to assign the properties with the right resources. This happens in the base class constructor. This is done to save clicks for the most common use case.

We don’t recommend writing any code related to modifying the automatic assignment of resources. The assignment of resources is normally done manually by the user.

If you want to override the behavior you can make the initialization yourself like this:

// matches the default behavior:
public MyInstrument Instrument{get;set;} = InstrumentSettings.Current.OfType<MyInstrument>().FirstOrDefault();

//  select based on otherthings as well:
public MyInstrument Instrument{get;set;} = InstrumentSettings.Current
   .OfType<MyInstrument>()
   .FirstOrDefault(instrument => instrument.ExampleProperty == "Something");

The code for the default initialization is here opentap/Engine/TestStep.cs at 4335f01dc8fdba97b7b05f61ebe781ae16b8f826 · opentap/opentap · GitHub

What is the specific requirement you have?