Skip to content

Accessing Large Number of Variables

Kishor Basavaraju edited this page Oct 23, 2025 · 5 revisions

Accessing Large Number of Variables

Although only a subset of variables may be used in specific test scenarios, there can be cases where a large number or even all variables need to be accessed. This might be necessary for tasks such as performing negative testing, where all variables need to be accessed and (re)initialized.

In scenarios where a large number of variables need to be accessed temporarily, it's more efficient to use a combination of a command loop and the NI VeriStand - Send Message to Custom Device API, rather than increasing the reserved runtime capacity.

Example

In the Custom Device Example, two new custom string message events are supported: CD.Command.SetHWValues and CD.Command.GetHWValues. These commands use JSON format for both sending and receiving data.

CD.Command.SetHWValues

This command carries a map of SignalIDs and their corresponding values to be set. Upon receiving the message, the double values are deserialized and mapped to their respective SignalIDs. These values are then pushed into the RT FIFO.

The new values are applied to driver array during the "Write Data to HW" state of the RT driver.

CD.Command.GetHWValues

This command includes a list of SignalIDs for which current values are requested. Once received, the list is deserialized and pushed into the RT FIFO.

The corresponding values are retrieved from the driver array during the "Read Data from HW" state of the RT driver.

Example

Setting values through custom command

int start = 100;
int count = 100;

int[] signalIDs = new int[count];
double[] values = new double[count];

for (int  index = 0; index <  count; index++)
{
    signalIDs[index] = start + index;
    values[index] = (double)(start + index);
}

var data = new { SignalIDs = signalIDs, Values = values };
string json = JsonConvert.SerializeObject(data);

Factory FacRef = new Factory();
var cdQuery = FacRef.GetICustomDevice("localhost", "Targets/Controller/Custom Devices/Runtime Configuration Support Demo");
cdQuery.SendMessage("CD.Command.SetHWValues", json, 5000, out string response);
Console.WriteLine(response);

Getting values through custom command

int start = 100;
int count = 100;

int[] SignalIDsIn = new int[count];
int[] SignalIDsOut = new int[count];

for (int  index = 0; index <  count; index++)
{
    SignalIDsIn[index] = start + index;
    SignalIDsOut[index] = start + index;
}

var data = new { SignalIDsIn = signalIDsIn, SignalIDsOut = signalIDsOut };
string json = JsonConvert.SerializeObject(data);

Factory FacRef = new Factory();
var cdQuery = FacRef.GetICustomDevice("localhost", "Targets/Controller/Custom Devices/Runtime Configuration Support Demo");

cdQuery.SendMessage("CD.Command.GetHWValues", json, 5000, out string response);
Console.WriteLine("Response from Get HW Values Command:");
Console.WriteLine(response);

Parent Topic

Reconfigure parts of your custom device in a running VeriStand system without the need to undeploy