NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I access ProgressText and ProgressPercent in Csharp?

Solved!
Go to solution

I have a Csharp application that is a wrapper around TestStand to hand-hold the operator through the process of selecting a UUT, connecting it to the test equipment, running the test, and publishing results.

 

I want to add two widgets (read-only textfields, or labels) onto my GUI to show the ProgressPercent and ProgressText so my two widgets look the same as the ProgressPercent and ProgressText that show up in the TestStand status bar.

 

Is it as simple as calling ConnectCaption() and somehow linking the ProgressPercent and ProgressText onto my widgets?

 

0 Kudos
Message 1 of 6
(3,672 Views)

Here is the code I tried but doesn't work:

    private NationalInstruments.TestStand.Interop.UI.Label captionPercent;
    private NationalInstruments.TestStand.Interop.UI.Label captionText;
...
    private System.Windows.Forms.Label progressPercent;
    private System.Windows.Forms.Label progressText;
...
        this.progressPercent = new System.Windows.Forms.Label();
        this.progressText = new System.Windows.Forms.Label();
...
        this.captionText = new NationalInstruments.TestStand.Interop.UI.Label();
        this.ExecutionViewMgr.ConnectCaption(
            this.captionText, CaptionSources.CaptionSource_ProgressText, true);
        this.captionText.Change += new _LabelEvents_ChangeEventHandler(captionText_Change);
        this.captionPercent = new NationalInstruments.TestStand.Interop.UI.Label();
        this.ExecutionViewMgr.ConnectCaption(
            this.captionPercent, CaptionSources.CaptionSource_ProgressPercent, true);
        this.captionPercent.Change += new _LabelEvents_ChangeEventHandler(captionText_Change);
...
    private void captionText_Change()
    {
        this.progressText.Text = captionText.Caption;
        this.progressPercent.Text = captionPercent.Caption;
    }

Am I heading down the wrong path?

0 Kudos
Message 2 of 6
(3,666 Views)

I'd recommend handling the UIMessages directly as follows:

 

1) Add a UIMessageEvent handler if you don't already have one (it's an event on ApplicationMgr)

2) When your handler is called. if the Event code is UIMsg_ProgressText get the text from the StringData property, if the Event code is UIMsg_ProgressPercent get the percentage from the NumericData property. See the online help for UIMessageCodes for more information.

3) Don't do anything for any of the other Event codes.

 

Hope this helps,

-Doug

0 Kudos
Message 3 of 6
(3,662 Views)

Ok, I understand what you are suggesting, but I have to ask, "What are the ConnectCaption() methods for if not for this type of activity?"

0 Kudos
Message 4 of 6
(3,659 Views)
Solution
Accepted by topic author tlaford

I think what you were trying is very close to working, you just needed to use the ConnectionActivity event instead of the Change event. At least it sounds that way from looking at the documentation for ConnnectionActivity.

 

Hope this helps,

-Doug

Message 5 of 6
(3,647 Views)

Yup, that did the trick. The code snippet below shows what I have working, but the Windows ProgressBar does not show the percent complete string (i.e., "20%") like the TestStand's status bar widget does.

 

    private NationalInstruments.TestStand.Interop.UI.Label captionPercent;
    private NationalInstruments.TestStand.Interop.UI.Label captionText;
...
    private System.Windows.Forms.ProgressBar progressPercent;
    private System.Windows.Forms.Label progressText;
...
        this.progressPercent = new System.Windows.Forms.ProgressBar();
        this.progressText = new System.Windows.Forms.Label();
...
        this.captionText = new NationalInstruments.TestStand.Interop.UI.Label();
        this.captionText.ConnectionActivity += new _LabelEvents_ChangeEventHandler(
            ProgressWidgets_ConnectionActivity);
        this.ExecutionViewMgr.ConnectCaption(
            this.captionText, CaptionSources.CaptionSource_ProgressText, true);

        this.captionPercent = new NationalInstruments.TestStand.Interop.UI.Label();
        this.captionPercent.Change += new _LabelEvents_ChangeEventHandler(
            ProgressWidgets_ConnectionActivity);
        this.ExecutionViewMgr.ConnectCaption(
            this.captionPercent, CaptionSources.CaptionSource_ProgressPercent, true);
...
    private void ProgressWidgets_ConnectionActivity(ConnectionActivityTypes activity)
    {
        // Write out the caption text
        this.progressText.Text = captionText.Caption;

        // Remove the percent sign from the caption percent
        string noPercentSign = captionPercent.Caption.Replace('%', ' ');
        Int16 percent = 0;
        Int16.TryParse(noPercentSign, out percent);
        this.progressPercent.Value = percent
    }

 

0 Kudos
Message 6 of 6
(3,640 Views)