NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

C# .Net Get Sequence caller

Solved!
Go to solution

Hello,

 

I'm developping a C# software using TestStand API.

I need to get the names of sequences when they are called.

In order to do this, I'm catching the event _ApplicationMgrEvents_StartExecutionEvent e and get the e.exec.DisplayName.

 

The thing is, I need to get the name of the sequence caller, in this example SelectUUTScenari (in yellow), but what I catch is p_SelectUUTScenari (in yellow).

 

Do you know how to get the sequence caller and not the sequence name itself ?

 

Thank you for your help

0 Kudos
Message 1 of 11
(3,457 Views)

      Well, actually, obtaining the sequence caller name is not difficult, you can use an expression:

RunState.Caller.Step.Name

      After obtaining it, it can be obtained by passing it through a UImessage message.

 

      But here's a situation that I think I need to explain to you:

       According to the rules of teststand, when the test runs to the subsequence step, it will directly enter the subsequence and run all necessary steps until it reaches the [end group] step of the subsequence, and the name of the subsequence caller can be obtained.

       I'm not sure if this meets your needs.

demo.png

0 Kudos
Message 2 of 11
(3,422 Views)

Hello,

 

Thank you for your answer !

I think it might be what I'm looking for, but I cannot find how I can call it ?

Here is how I tried :

 

IsMu_1-1682327769885.png

 

 

Caller does not exist in this context, I could not find what I have to do in order to find it ? Some initialization missing for the axApplicationMgr perhaps ?

0 Kudos
Message 3 of 11
(3,390 Views)

Well, I read what you said. There are two possible solutions to this problem that I have learned:

 

  • 1. During the test seq running, obtain the value of the dynamic variable RunState. Caller. Step. Name through the thread context, so as to obtain the caller name you need.
  • 2. Through the UImessage message mechanism. Enable the filepoststep callback in test seq file, process model file, or station model file. Obtain the information you need through expressions in the callbacks, and post these messages through RunState. Thread or RunState. Engine. Then, you only need to receive this  UImessage to obtain all the information as you want.

Usually, regardless of official recommendations or personal practice, it is recommended to use method 2.

 

However, this requires you to have an understanding of the entire runtime and messaging mechanism of teststand and know how to apply it, rather than just a little bit of content.

 

Of course, if anyone else knows there are other good ways, I hope they can share them. Thank you!

0 Kudos
Message 4 of 11
(3,383 Views)

Hello IsMu,

 

I hope I'm not completely wrong here so if anybody has different information please correct this.

 

The UIMsg_StartExecution event you are refering to is fired when a new execution is started.
I have been digging through TestStand and could not find any bit of information inside a new execution that would lead towards the caller.
I believe TestStand does not track who spawned a new execution. Unlike a new thread, a new execution always starts at callstack 0.

So the caller you are looking for simply does not exist, as the scope of a callstack or a caller is limited to a single execution.

 

If you want to get the caller sequence name of a standard or new thread sequence call, this event is not what you are looking for anyways.

 

Stefan

Message 5 of 11
(3,375 Views)

Hello,

 

I try to reach 

 

axApplicationMgr.GetRunState(e.exec);

 

but I could not get the caller out of it, do you know the syntax ?

 

I then tried other way, this way :

 

e.thrd.GetSequenceContext(0, out id).Caller.Step.Name;

 

but e.thrd.GetSequenceContext(0, out id).Caller.Step does not work.

 

Do you know which C# syntax I should use ?

I hope there is a way to catch it !

0 Kudos
Message 6 of 11
(3,369 Views)

Brother, I don't understand why you've been persistently trying axApplication Manager. GetRunState. Maybe there's something I don't know about it

But I used method 2, the UImessage mechanism, which I told you before, and I easily obtained the necessary information

The simple code is as follows:

private void axApplicationMgr_UserMessage(object sender, NationalInstruments.TestStand.Interop.UI.Ax._ApplicationMgrEvents_UserMessageEvent e)
{
            try
            {
                switch (e.uiMsg.Event)
                {
                    case (UIMessageCodes.UIMsg_UserMessageBase + 7):
                        MessageBox.Show(e.uiMsg.StringData);
                        break;
                }
            }
            catch (Exception theException)
            {
                MessageBox.Show(this, theException.Message, "Error");
            }
}

 

Here is a screenshot of the information I have obtained:

 

1.png

2.png

 As you can see, I wrote a simple demo that called 2 sub sequences, and when I ran through these two steps(test and text_xxx), I got the information I wanted (a message box popped up and displayed the obtained results)

 

0 Kudos
Message 7 of 11
(3,351 Views)

Um, add something

If you want to obtain the Call subsequence step caller name before the seq execution starts, you can directly access the the object properties after the test seq file loaded:

 

RunState.SequenceFile.Data.Seq["MainSequence"].Main

 

If you want to obtain it in runtime, then the previous answer is the answer.

0 Kudos
Message 8 of 11
(3,347 Views)

Thank you for your help, what is called "Call_another_seq_02" is precisely what I need to catch.

 

What I'm missing is, when you explained method 2 to me, "Obtain the information you need through expressions in the callbacks, and post these messages through RunState. Thread or RunState. Engine."

I do not understand what this means, is is something I have to do in the Sequence Editor of TestStand ? I'm sorry for all these weird questions, I only work in C# and I'm not the one in charge of TestStand sequences here, so I'm not familiar with that at all. This is why I was trying to find ways in the NI documentations to "translate" what you tell me in C#.

 

The RunState.Thread or Engine you mentioned, there not in the C# code I guess ?

 

I tried to call your method axApplicationMgr_UserMessage in the C# designer, like this

this.axApplicationMgr.UserMessage += new _ApplicationMgrEvents_UserMessageEventHandler(this.ApplicationManagerUserMessage);

But the axApplicationMgr_UserMessage method is never called, I'm guessing because I have to send the message, perhaps it is not done automatically.

 

SequenceFilePostStep is enabled as you told me in one of your previous messages, in TestStand Editor, but I do not understand how to send the message, could you help me with this ?

And/or, give me the code you used for the example if all is done in C# ?

 

Thank you again for all of your help

0 Kudos
Message 9 of 11
(3,339 Views)
Solution
Accepted by IsMu

Sorry for the late replied, I have too many things to handle recently.

Because there is a bit of knowledge involved, it may take more time to fully explain the problem. I am not good at communication myself, so I have compiled a feasible method. If you follow this method, it should be able to meet your needs.

OK, let's get started.

-----------------------------------------------------------------------------------------------------------

1. Test sequence file operations

Open the seq file you are preparing to test and insert a seq callback. The detailed operation is as follows:

     a. Open the teststand sequence file callbacks form and add a SequenceFilePostStep callback function

     b. Edit the SequenceFilePostStep callback function and add nei as follows: screenshot(1)

3.png

         I. You need to in the variables form

               Create StepResultSummary variable in local, string type

               Create a Result variable within parameters, Container type

         II. The code of red line is:

Locals.StepResultSummary = "Caller is : " + RunState.Caller.Step.Name + "\r\nCalled Sequence is : " + Parameters.Result.TS.SequenceCall.Sequence + "\r\nCalled Sequence Status is : " + Parameters.Result.TS.SequenceCall.Status

         III. The code of green line is screenshot(2) :

4.png

         IIII. follow the content of my screenshot(1) to handle the other parts.

         V.  save the seq file.

2. Run test sequence

    Okay, here you go, you can use your developed C # application, open the saved seq file, and run it.

    Then you should be able to receive the 10007 message, and you can obtain the information you want from its Locals. StepResultSummary attribute.

As for whether you want to display it or perform other operations, I cannot help you with this (only you know what you want it to do)

 

Note:

You should remember that the event Code defined earlier must be consistent with the Message code that needs to be received within your C # application, otherwise you will not be able to receive it.(UIMsg_UserMessageBase = 10000,     UIMsg_UserMessageBase + 7 = 10007)

0 Kudos
Message 10 of 11
(3,285 Views)