NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

seqContextCVI - do I need it for every test?

Assum there are 5 tests in the TS sequence.
Assume that each of the test requires access to the TS.

Question: Does every test has a different handle? and if so, I guess I must "handle" it to the CVI via a parameter like:

void __declspec(dllexport) __stdcall testNumLimit(CAObjHandle seqContextCVI, double *measurement,
char reportText[1024], short *errorOccurred, long *errorCode, char errorMsg[1024])

Will it work if I only do it in the first test, store the seqContextCVI as a global veriable and use it in the other 4 tests?

Thanks
Rafi
0 Kudos
Message 1 of 6
(3,487 Views)
Rafi -
The purpose of the context is to allow the test to have access to additional information that relates to the test that is currently executing the code module.

In general we recommend to not hold onto a context inside a code module after returning from back to a step that gave the code module the context. If you must, you can hold onto the the engine, but all other information in the context has a specific lifetime where the data is valid. Things like thread, execution, and step, all have a limited lifetime.

During the execution of a single sequence, the context is valid to hold onto, but once the single sequence completes, the context is either released or placed in a cache for later reuse. If you want your code module to handle multiple thr
ead or executions at the same time, holding onto any of this information could lead to incorrect information.

There is not a requirement to pass the sequence context every time and yes your test could hold on to it, but note that you must add a reference to it to hold onto it so that the object reference count in TestStand is managed properly.

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 2 of 6
(3,487 Views)
Hello Scott and thanks,

I'm afraid I didn't understand your last remark "...your test could hold on to it, but note that you must add a reference to it to hold onto it so that the object reference count in TestStand is managed properly"

If I hold on to it it means I keep it as a global veriable in my Teststand module. What is the reference I must add? I lost you completely here...

Thanks
Rafi
0 Kudos
Message 3 of 6
(3,487 Views)
Rafi -
ActiveX/COM objects are reference counted, i.e. when the last reference to the object is released, the object is destoyed (memory deallocated).

In CVI, an CAObjHandle represents a reference to an object. When TestStand creates a CAObjHandle parameter to pass to a code module, CVI adds a COM reference to the object. When TestStand releases the CAObjHandle using CA_DiscardObjHandle, CVI releases the reference.

In a code module, if you want to maintain a handle that is passed to you and the caller releases what they pass, you must get your own CAObjHandle using the CVI function CA_DuplicateObjHandle. You are also expected to properly and timely call CA_DiscardObjHandle on the new CAObjHandle when it is no longer needed so the
object can be destroyed correctly, otherwise you have the potential for a memory leak because objects are no being released.

The problem with placing the object in a global is that you need to make sure that the release is done. If you are expecting a step later in the sequence to do it, what happens if the step is not called because of a error or a termination in the sequence?

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 4 of 6
(3,487 Views)
Hello Scott,

Thank you so much for clearing things up.

Can I conclude, then, that the safest or most practical way to handle it will be to pass the 'CAObjHandle context' parameter with every step calling a CVI module? (this is how I do it now....)

Did I understand it correctly, that in this case, the object is release/destroyed properly upon the end of the step (or termination or run time error)?

Thanks
Rafi
0 Kudos
Message 5 of 6
(3,487 Views)
Rafi -
Your conclusion is correct. Yes, since TestStand creates the parameter for the step, it is expected to cleanup the parameter when the step returns. Glad to help...

Scott Richardson (NI)
Scott Richardson
https://testeract.com
0 Kudos
Message 6 of 6
(3,487 Views)