Dead Simple Voltage Sweep Parameterization

I’m surely overlooking the obvious here. I’ve seen the example of sweeping a delay variable and have replicated that, it works fine.

Now, I want to sweep a voltage setting on a power supply from, say, 1V to 10V. I can’t figure out what/how to parameterize this. The SCPI command SOURCE1:VOLT 1.0 needs to be changed each time from 1.0 to 2.0 to 3.0… to 10.0. I can’t parameterize the command, I need to parameterize some value that I append to that command.

I’m sure this is dead simple, what am I missing here?

Thanks

1 Like

Welcome to the OpenTAP Community!

Unfortunately I don’t think it’s quite that simple, in this instance. But, still easy to do. Simply create a custom TestStep for your SCPI command, have one of the settings be the voltage level for the power supply, and then do parameterization as normal.

Here’s the code for creating that custom TestStep:

using OpenTap;
using System;

namespace ParameterizeCustomStepExample
{
    [Display("Set Power Supply Voltage", Group: "ParameterizeCustomStepExample", Description: "Insert a description here")]
    public class SetPowerSupplyVoltage : TestStep
    {
        #region Settings
        [Display("Power Supply", "Reference to power supply being controlled")]
        public ScpiInstrument PowerSupply { get; set; }

        [Display("Voltage Level", "Voltage level to set power supply")]
        [Unit("V")]
        public double Voltage { get; set; }
        #endregion

        public SetPowerSupplyVoltage()
        {
        }

        public override void Run()
        {
            if (PowerSupply is null)
                throw new Exception("Error: Power Supply must be set");
            try
            {
                PowerSupply.ScpiCommand($"SOURCE1:VOLT {Voltage}");
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}

Another option if you want to have a more generic solution for your test step is to insert the skeleton for the SCPI command without the parameter, and then have the parameter as input to the TestStep. Here’s what I mean:
image
image

Here, instead of hard-coding the command into the test step, you allow the command itself to be a parameter to the TestStep, like the “SCPI” TestStep. But, this way you can parameterize the SCPI command parameter. This may be similar to how you wanted it to work, originally.

Here’s the code for such a TestStep:

using OpenTap;
using System;

namespace ParameterizeCustomStepExample
{
    [Display("Parameterizable Scpi Step", Group: "ParameterizeCustomStepExample", Description: "Generic SCPI step that allows for parameterizable values")]
    public class ParameterizableScpiStep : TestStep
    {
        #region Settings
        [Display("Scpi Instrument", "SCPI instrument being controlled")]
        public ScpiInstrument Instrument { get; set; }

        [Display("Scpi Command", "Parameterizable command without value inserted")]
        public string ScpiCommand { get; set; }

        [Display("Scpi Value", "Value to insert into SCPI Command")]
        public double ScpiValue { get; set; }
        #endregion

        public ParameterizableScpiStep()
        {
        }

        public override void Run()
        {
            if (Instrument is null)
                throw new Exception("Error: \"Instrument\" must be set");
            if (string.IsNullOrEmpty(ScpiCommand))
                throw new Exception("Error: \"Scpi Command\" must be set, cannot be empty");
            try
            {
                Instrument.ScpiCommand($"{ScpiCommand} {ScpiValue}");
            }
            catch
            {
                throw;
            }
        }
    }
}

Hope this helps!

1 Like

Ah, I see. I wasn’t thinking about this the right way. I can see that I will want custom code behind the scenes for much of my equipment and test steps, based on my particular needs.

Thanks!

2 Likes

No problem! This is one of OpenTAP’s biggest strengths, is how customizable it is when creating your custom code for testing, results, and DUT/instrument control. Post any more questions you have if you run into issues or just need advice!

1 Like