06-15-2023 02:43 AM
Here is the C# code which is to copy to Runtime Error Msg to C# UI(richTextBox1) when error happen:
case UIMessageCodes.UIMsg_RuntimeError:
Execution exc = axExecutionViewMgr.Execution;
PropertyObject po = exc.AsPropertyObject();
string LookupStr = "RunState.Step.Result.Error.Msg";
string ErrorMsg = po.GetValString(LookupStr,PropertyOptions.PropOption_InsertIfMissing);
richTextBox1.AppendText(ErrorMsg + "\r\n"); //Can run Here but Why alway get empty ErrorMsg?
break;
My question is why it can not work, Please give some advise,thanks a lot.
Attach the TestStand MessageBox screen shot:
Solved! Go to Solution.
06-15-2023 06:04 AM
I gave it a try and it's work correct.
You tried to obtain the value of the property object through the context, but you chose the wrong object.
For example, when I write an expression with a non-existent local variable, it triggers Runtime error, which is the captured error message in Console.
06-16-2023 09:07 PM
Maybe my question is not described quite clear. Actually I was confused that when runtime error happen, and teststand already showed the error message, how I can obtain the message again by C# code. So I tried by above ways(GetValString) and get the empty error message(Not the expect error message just showed as the sceen short: Com Port is not exist). Is there any problems of my way of using GetValString ? Or can you tell me which is the right object to choose (you mean the LookupStr of "RunState.Step.Result.Error.Msg" is wrong?)
06-17-2023 08:50 AM
No, I'm very clear about your problem. In the example above, I intentionally made an error in seq (accessing a non-existent Locals variable), and then used C # code to capture this error on the console application when the seq file runnung.
I just use this example to telling you that is can be captured.
propertyObject.GetValString---------> right
"RunState.Step.Result.Error.Msg"----------> right
PropertyObject po = exc.AsPropertyObject();----------> wrong [ Execution cannot be directly used as a property object ]
You didn't understand their structural relationship. Its hierarchical relationship is as follows:
SequenceContext --> Execution --> Thread --> sequenceContext[i] --> As propertyObject --> read / write the properties or variables.
Don't blame me for not telling you the code directly. In fact, I am directly developing based on Teststand Engine without using any TS ActiveX controls. Our principles and methods are the same, but the code is different.
For more information, please refer to the following links and images:
06-20-2023 08:40 PM
Firstly thanks very much for your reply.
According to your suggestion, I modify my code as below, and it works now.
(Add get SequenceContext by: SequenceContext seq_ctxt = exc.GetThread(0).GetSequenceContext(0, out intTemp);)
And I already realize that only SequenceContext AsPropertyObject can get the ValString under RunState.
Secondly, Would you please tell me when the exc.NumThreads is more than1, how I can find the right thread index to used to way of GetThread(). Above screen shot's exc.NumThreads is luckily 1. Thank you again for your alway patience to help me.
06-20-2023 08:53 PM
I think this way is better: SequenceContext seq_ctxt = exc.ForegroundThread.GetSequenceContext(0, out intTemp);