How to Obtain Instrument Properties from TestSteps before Run() executes

I’ve got a case where I use one of two similar, but not identical, instruments for my testing. I use the same instrument class and drivers for both instruments and can easily manage the differences in the driver by examining the model number. I have found however that this is very difficult to manage in the GUI since several GUI managed Instrument settings are not compatible between the instruments and getting a valid revision value from the Instrument class before the Run() method is executed is not straight-forward.

How can I read a value such as a model number from the Instrument Class and then use that value to setup valid values in the GUI? I’ve found that the Instrument values that I obtain in the TestStep’s run function are reliable but values collected in the TestStep’s constructor are not reliable.

I have found that the code below gets me the correct values from the instrument but results in some unwanted behavior, namely, that changing the InstrumentType changes the value of the current Instrument object in the Bench Settings and then changes made in the Bench Settings do not stick. I want the opposite behavior. Instrument’s bench settings should Never be altered.

Bottom Line: What’s the best way to obtain a value from the current Instrument object that can be used to configure a TestStep from the GUI ? The value should be displayed in the GUI but treated as read-only. Should never modify the Instrument Object or Bench Settings.

// Instrument Class
public class VXT : ScpiInstrument
{

public InstrumentTypes InstrumentType { get; set; }

}

// TestStep Class
public class PresetVXTandSelectPorts : TestStep
{

    private VXT _instr;
    [Display("Analyzer Instrument", Group: "Instrument", Order: 1.0, Description: "Select Analyzer Instrument.\nDefault: VXT")]
    public VXT instr { get { return _instr; } set { _instr = value; FormatStepName(); } }

    //Obtain InstrumentType from the current Instrument Object (Is there a cleaner way to do this?)
    [Display("Instrument Type", Group: "Instrument", Order: 1.0, Description: "Select Analyzer Instrument.\nDefault: VXT")]
    public VXT.InstrumentTypes InstrumentType { get { return instr.InstrumentType; } set { instr.InstrumentType = value; } }
   ...

}

// Test Step Constructor
public PresetVXTandSelectPorts()
{
//This value is NOT Reliable until Run () executes
InstrumentType = instr.InstrumentType;
}

Thanks
jim

1 Like

Hi Jim,

I am not sure what your request is here, but I’d recommend this in your step:

    [Display("Instrument Type", Group: "Instrument", Order: 1.0, Description: "Select Analyzer Instrument.\nDefault: VXT")]
    [Browsable(true)] // show the value even though it is not configurable
    public VXT.InstrumentTypes InstrumentType {
 get 
      { return instr?.InstrumentType ?? InstrumentTypes.NoInstrument; } // fallback value in case instr is null.
 } // read-only setting - no setter.
3 Likes

thanks Rolf.

That did the trick and I should have worked that out. I tried not using a setter before and was thrown by the large number of “XML line xx column xx: Unable to set property InstrumentType.The property does not exist” warnings when loading the testplan. Realize now that these warnings go away after the testplan is save and re-loaded.

BTW The reason that I want this functionality is to be able to validate that valid input and output ports are selected in the GUI based on the current instrument being used since the two instruments that I’m using use different ports.

jim

2 Likes