NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Teststand OI using C# accessing Sequence variables

Solved!
Go to solution

I have a requirement to display Sequence variables during runtime on the OI.

 

Took the C# simple sample OI and after reading some help files and docs I tried two approaches. I failed to get to the sequence variables.

 

1) I tried to retrieve a SequenceContext from the ExecutionMgr, but that failed  with COM exceptions.

2) Then tried to retrieve the RuntimeVariables, but again it failed with COM exceptions.

 

 

Not being a C# or .Net expert I believe I must be making some simple mistake.

 

Anybody out there who did this in C# and is willing to share?

 

I am interested to find out:

1) What is the correct way to get access to Sequence Locals.

2) What event callbacks to use to update GUI with Sequence execution progress.

 

If no luck I will publish my code and problems.

 

Using Teststand 4.1 with VisualStudio 2008 free edition.

0 Kudos
Message 1 of 5
(4,606 Views)
Solution
Accepted by topic author Truhann

The event-oriented way to do this is have your sequence post UIMsgs using the Thread.PostUIMessageEx method. The messages will contain a data payload of your sequence variables. The OI will have an event handler that will receive these messages and then you add code in the OI to put the data where ever it goes on the OI front panel. You must create your own user-defined messages because TestStand enumerates a block of UIMessageCodes. You can post the messages from a code module, from a statement step, or use a TestStand API expression.

 

The TestStand I (or II) course has a good example about how to do it. It sounds wacky to begin with but it is a scalable way to do it. It provides some rough synchronization, you get the UIMessages as they are posted.

 

A cool trick is: When your OI receives one UIMessage, it can get thread.sequence context from the message. So you could send just one dummy message, have your event handler get the sequence context from the message, and you'll have acess to the sequence locals and everything else.

 

If you wanted to have the OI read sequence locals by some other way, I think you'd have to get an array of all the executions that the engine currently has from one of the OI managers (maybe the engine), then figure out which one is yours, then figure out what thread in that execution is yours and then the thread and sequence etc. It isn't possible to get seq context straight from ExecutionMgr. I personally would not do it this way.

 

cc

Message 2 of 5
(4,601 Views)

Thank you very much.  You show'ed me the light. Working very nice.

 

0 Kudos
Message 3 of 5
(4,595 Views)

Keep in mind the TestStand engine reuses sequence context objects, so the engine deletes all the variables associated with the running sequence when the sequence completes executing and the thread returns to the calling sequence. The sequence context object may be reused the next time a thread for the execution calls the same sequence. So in the end, the safest design to implement is to only access local objects on the sequence context during the lifetime of the message that gave it to you and not after you return from the event or manually acknowlege the event.

Scott Richardson
https://testeract.com
0 Kudos
Message 4 of 5
(4,568 Views)

Thank you for your response.

 

FYI: My solution ended up by only extending the UIMsg_UserMessageBase and using the associated Numeric and String variables.  This way the OI (still) don't need to be aware of sequence specific variables that leave us with a sequence independent OI.(To be reused accross multiple projects).

 

 

 


0 Kudos
Message 5 of 5
(4,561 Views)