NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate a Local Variable in TestStand using the LabWindows/CVI and the TestStand API

Hello,

I'm searching for a code example. The problem is to create a local variables in TestStand automatically from an application. This application is programmed in LabWindows/CVI using the TestStand API.

Thanks!
0 Kudos
Message 1 of 5
(4,441 Views)
Hi!

I don't have an example to share with you since I don't have LabWindows, but I can tell you how to do it, it is not so complicated.

In you code, you have a reference to the sequence context. The first step is to get the sequence context as a property object by calling AsPropertyObject Method. From that object, call the method SetValBoolean, SetValString, SetValNumeric, or SetValVariant depending on the type of local variable you want to create. There are three parameters for this method:
lookupString: this should be locals.x (x is the name of the local variable you want to create)
options: this should be a value of 1 which means "Insert if missing"
newValue: the value you want for your variable.

That should create a new local variable fo
r you. Hope this helps. Maybe a CVI user has an example for you.
0 Kudos
Message 2 of 5
(4,441 Views)
Hi,

There is an example in the TestStand examples, see AccessingPropertiesAndVariables.

This has been updated from TS1.0 with a note on what to do. below is snippit from example.

void TX_TEST DLLEXPORT AccessLocalVariables(tTestData *data,tTestError *testError)
{
VBOOL propertyExists;
ERRORINFO errorInfo;
int error = 0;
ErrMsg errMsg = {'\0'};

// Note: You do not have to call TS_PropertyExists if you know that the variable
// you are accessing exists.
// Note2: You can also create a new variable and sets its value
// with a single call by passing the TS_PropOption_InsertIfMissing option
// as the fourth parameter to TS_PropertySetValNumber, TS_PropertySetValString, or TS_PropertySetValBoolean
tsErrChk(TS_Propert
yExists(data->seqContextCVI, &errorInfo, "Locals.NumericValue", 0, &propertyExists));
if (propertyExists)
// This sets the local variable NumericValue to a random number.
// We use the tsErrChk macro defined in tsutil.h to perform error checking.
tsErrChk(TS_PropertySetValNumber(data->seqContextCVI, &errorInfo, "Locals.NumericValue", TS_PropOption_InsertIfMissing, (10 * rand()) / RAND_MAX));

I have modified the SetVal function in the snippit above.

regards
Ray Farmer
Regards
Ray Farmer
Message 3 of 5
(4,441 Views)
Thank you, but i can not realize your proposal.

My code is:
TS_EngineNewSequence (engine, &errorInfo, &newSequence);

Then i create the property object
TS_SeqContextAsPropertyObject (newSequence,&errorInfo,&newPropertyObj);

The last step is to set the new variable
TS_PropertySetValString (newPropertyObj,&errorInfo,"Locals.MyString", TS_PropOption_InsertIfMissing,"Hello World");

Now i save all sequences, but there is no local variable. What I'm doing wrong?

Greetings, and thank you for your help!
0 Kudos
Message 4 of 5
(4,441 Views)
Thank you!

It works.
0 Kudos
Message 5 of 5
(4,441 Views)