NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign an expression to a statement Step in TestStand automatically?

Hi,
 
I am using VC++ and I am trying to create a statement step inside a SequenceFile already created. I can actually create my Statement type of step and insert it at the right place. Unfortunately, I can't find a way to set the Expression for this step. How can I do it?
 
Here is what I tried:
 

TS::StepPtr step = engine->NewStep(TS::NoneAdapterKeyName, TS::StepType_Statement);

// Assign its name to the step

_bstr_t calledName(stepName);

step->put_Name(calledName);

// Get all the sequence file variables into a PropertyObject

// TS::PropertyObject variables = TS::Execution.GetFileGlobals ( seqFile );

// Expression construction

_bstr_t expression("resourceHeader=ResStr(");

expression += _bstr_t(id_ptr) + ")";

step->CustomActionExpression.Assign(expression);

 
 
I get the expressions created but nothing in the Expression field.
 
NB: I use TS 4.0
 
Any hints are welcome.
 
- Eric
 
0 Kudos
Message 1 of 7
(4,400 Views)
The Statement step hijacks the post expression for its own use, so use step->PostExpression = expression.
 
Also, I'm not sure if it is ok to call Assign like you are doing. I'm afraid that might compile to a property-get with Assign being called on the returned temporary _bstr_t, instead of a property-set. However, I'd haven't compiled and disassembled an example to test this theory, so it is an unconfirmed suspicion.
0 Kudos
Message 2 of 7
(4,391 Views)
Works fine.
 
But as you are looking familiar with the kind of programming I do, can I ask another question?
 
 
There it is...
I highly inspire myself from a solution found on a discussion. I would like to create SequenceFile Global variables for a SequenceFile object but can't get it to work. Here is the code that should do it:

TS::SequenceFilePtr CreateSeqFileGlobals(TS::SequenceFilePtr seqFile) {

TS::PropertyObjectPtr propObjPtr = seqFile->AsPropertyObject();

propObjPtr->SetValString("Data.FileGlobalsDefaults.resourceHeader", 1 ,""); // resourceHeader

propObjPtr->SetValString("Data.FileGlobalsDefaults.resourceFail", 1, ""); // resourceFail

seqFile->IncChangeCount(); // Signify the file changed

return(seqFile);

}

Any idea why this doesn't do what I expect it to do?

 

Regards,

 

- Eric

0 Kudos
Message 3 of 7
(4,386 Views)
You are very close. I think you need to use FileGlobalDefaults instead of FileGlobalsDefaults in your lookup strings.
 
Better yet, use seqFile->FileGlobalsDefaultValues->SetValString("resourceHeader", ...)
0 Kudos
Message 4 of 7
(4,376 Views)

Thanks. I will try this in a moment.

Is there any list of all the available "lookup strings"? I mean, I can't guess all the right strings and right spelling (do I) ?!?

 

- Eric

0 Kudos
Message 5 of 7
(4,366 Views)

Most builtin TestStand settings do not need to be accessed via lookup strings. That is why I directed you to use the documented API property seqFile->FileGlobalsDefaultValues instead of a lookup string. By using the lookup string "Data.FileGlobalDefaults", you are taking advantage of undocumented knowledge of the implementation of the SequenceFile object. While this works and is unlikely to break in the future, theoretically we could change it since we don't document it.

This doesn't mean lookup strings aren't necessary. You need them whenever you use the API to access variables or custom properties of a type because these can be created by anyone at anytime and thus can't be hardcoded into the TestStand API.

Btw, I found the correct lookup string by breakpointing on a step, going to the variables view, and expanding Runstate.SequenceFile.Data to find the FileGlobalsDefaults property. I then right clicked and uses the context menu to copy the property path. Note that since you were starting from a SequenceFile instead of a SequenceContext (which is what the variables view displays), I removed the "Runstate.SequenceFile" part of the lookup string I copied.

0 Kudos
Message 6 of 7
(4,351 Views)
I've just started using the API (you probably noticed).
These tricks are quite helpfull.
 
Gratefully,
 
- Eric
 
 
0 Kudos
Message 7 of 7
(4,343 Views)