Click or drag to resize

Implementing Simulation

Implementing Methods and Properties to Support Simulation

Simulation is a required feature for IVI drivers. To support simulation, the developer must take explicit steps in the driver implementation. Specifically, the driver must ensure that when simulation is turned on, no instrument I/O communication is attempted, since the I/O infrastructure in Nimbus is not initialized when simulation is on. Consequently, functions such as Printf will not work at all in simulation mode.

Simulation is enabled by the client application by either passing in "Simulate=True" in the OptionString parameter to IIviDriver::Initialize or by setting the IIviDriverOperation::Simulate property to true. In either case, Nimbus maintains the current state of the simulate option and makes it available via the GetSimulate function. Thus, the primary tactic for driver developers implementing simulation in a Nimbus driver is to use the GetSimulate function to "synthesize" special simulated results and to avoid calling any of the instrument I/O functions.

In the example below, a configure method is modified to support simulation. Since this function performs only setup operations on the instrument (i.e. no data is read back from the instrument), the implementation need only check for simulation and then return immediately if it is enabled.

C++
HRESULT Acme4321::IAcme4321_Configure(DOUBLE Frequency, DOUBLE Bandwidth)
{
   // Check for simulation enabled and return immediately if true
   if (GetSimulate())
      return S_OK;

   // If we get to here, simulation is not on, so instrument I/O is performed
   HRESULT hr = io.Printf(_T("SENS:CONF %f, %f"), Frequency, Bandwidth);

   return S_OK;
}

For query methods or property read operations, the driver implementation must return a simulated value for any of the output parameters. The example below demonstrates how to use GetSimulate with a property getter.

C++
HRESULT Acme4321::IAcme4321_get_Bandwidth(DOUBLE* Frequency)
{
   if (GetSimulate())
   {
      *Frequency = 1.5E7;
      return S_OK;
   }

   HRESULT hr = io.Queryf(_T("SENS:BAND?"), Frequency);

   return hr;
}
Multi-Model Drivers and Simulation

When an IVI driver is operating in connected mode (i.e. not in simulation mode), the instrument model is determined by communicating with the instrument. See the topic InitializeIdentification for details on how this is accomplished. However, when a driver is operating in simulation mode, the instrument model obviously cannot be determined by communicating with the instrument. Instead, the user can specify which instrument model to simulate by passing in a value for a special "Model" initialization option.

The example code below demonstrates how a user would specify the simulated model.

C++
// Client.cs
IAcme4321 driver = new Acme4321();

// Turn on simulation and specify a simulated model of "4321"
driver.Initialize("GPIB::3", true, true, "Simulate=True, DefaultSetup=Model=4321");

Given the client program above, any model-specific code in the driver implementation would use an instrument model value of "4321". This is the value that would be returned from the GetModel function.

If the "Model" initialization option is not specified when simulation is enabled, then the default model established by the driver developer would be used as the simulated model. The default model is set using the Models Page of the Driver Settings Editor.

Download a complete CHM version of this documentation here.