{"id":684,"date":"2011-07-02T23:43:17","date_gmt":"2011-07-02T23:43:17","guid":{"rendered":"http:\/\/mainlinetest.com\/?p=684"},"modified":"2011-07-27T15:26:20","modified_gmt":"2011-07-27T15:26:20","slug":"using-the-teststand-api-%e2%80%93-controlling-the-progress-bar-part-1","status":"publish","type":"post","link":"https:\/\/mainlinetest.com\/?p=684","title":{"rendered":"Using the TestStand API \u2013 Controlling the Progress Bar &#8211; Part 1"},"content":{"rendered":"<div class=\"mceTemp mceIEcenter\" style=\"text-align: left;\">\n<div class=\"mceTemp mceIEcenter\" style=\"text-align: left;\">With TestStand allowing you to have complete control of the user interface, there are often some clever techniques you can use that can aid you during script development and execution.\u00a0 This post is an example of how the progress bar can be modified to determine the current status of a Sequence Call.<\/div>\n<\/div>\n<div class=\"mceTemp mceIEcenter\" style=\"text-align: left;\">\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_703\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig13.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-703\" class=\"size-full wp-image-703\" title=\"tstand-fig1\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig13.jpg\" alt=\"\" width=\"520\" height=\"332\" \/><\/a><p id=\"caption-attachment-703\" class=\"wp-caption-text\">Figure 1<\/p><\/div>\n<\/div>\n<\/div>\n<p>As shown in Figure 1, I simply inserted a Sequence Call and named it \u2018SequenceCallProgressBar\u2019.\u00a0 Now if I right-click on the Sequence Call and select <em>Open Sequence<\/em> we can look at the sequence code as shown below in Figure 2.<\/p>\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_704\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig22.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-704\" class=\"size-full wp-image-704\" title=\"tstand-fig2\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig22.jpg\" alt=\"\" width=\"520\" height=\"212\" \/><\/a><p id=\"caption-attachment-704\" class=\"wp-caption-text\">Figure 2<\/p><\/div>\n<\/div>\n<p>Using the Seconds() function, \u2018SequenceCallProgressBar\u2019 consists of a While Loop that repeatedly grabs a current\u00a0 timestamp and loops until 60 seconds has expired.\u00a0 Now suppose this loop was much more elaborate and could essentially take hours to execute.\u00a0 Wouldn\u2019t it be nice to be able to take a quick look at the sequence during execution and know just how much execution time remains?\u00a0 Sure you could just put a watch on the variable, but what if this script is to be executed on the manufacturing floor and the end user isn\u2019t familiar with getting around in TestStand?\u00a0 This is where controlling the progress bar may be of interest.<\/p>\n<p>So let\u2019s take a look at how to edit \u2018SequenceCallProgressBar\u2019 such that we can display current status on the progress bar.\u00a0 First, I\u2019ll add an <em>Action<\/em> step with adapter type ActiveX\/COM.\u00a0 For Automation Server I\u2019ll select the TestStand API and for Object Reference I\u2019m going to type \u2018RunState.Execution\u2019.\u00a0 Now the purpose of this step is to retrieve an object reference to the Sequence Call thread such that when it is executing you can update the progress bar.\u00a0 Therefore, for the Object Class I\u2019ll select <em>Execution<\/em> and then I\u2019ll use the Get Property \u2018ForegroundThread\u2019.\u00a0 Now I\u2019ll declare a variable (Locals.refThread) to store the object reference of the Sequence Call thread.\u00a0 Figure 3 below shows now what this step should look like.<\/p>\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_705\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig32.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-705\" class=\"size-full wp-image-705\" title=\"tstand-fig3\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig32.jpg\" alt=\"\" width=\"520\" height=\"170\" \/><\/a><p id=\"caption-attachment-705\" class=\"wp-caption-text\">Figure 3<\/p><\/div>\n<\/div>\n<p>Now that we have the object reference of the Sequence Call thread, we can start controlling the progress bar.\u00a0 The TestStand API contains two event codes that allow you to edit the progress bar.\u00a0 One allows you to control the percent complete and the other allows you to add text to the progress bar.\u00a0 Let\u2019s start with editing the percent complete status.<\/p>\n<p>First I\u2019ll add another <em>Action<\/em> step with adapter type ActiveX\/COM.\u00a0 For Automation Server once again I\u2019ll select the TestStand API but this time for Object Reference I\u2019m going to use the variable (Locals.refThread) in which I stored my thread reference.\u00a0 Next, for Object Class I\u2019m going to select <em>Thread<\/em> and now I\u2019ll use the built in Call Method, \u2018PostUIMessageEx\u2019.\u00a0 TestStand also comes with a Call Method called \u2018PostUIMessage\u2019 that could do the same trick, but according to the Help File, this function has been obsoleted and \u2018PostUIMessageEx\u2019 is the preferred Call Method to use.<\/p>\n<p>The \u2018PostUIMessageEx\u2019 Call Method contains 5 parameters.\u00a0 Depending on what you select for the first parameter determines how the other four will be used.\u00a0 For example, with the eventCode parameter, I\u2019m going to drop the enumeration down and select the \u2018UIMsg_ProgressPercent\u2019 message code.\u00a0 Now the other four parameters involved include a numeric data parameter, a string data parameter, an ActiveX data object reference, and a boolean variable.\u00a0 For the progess percent message code, the progress indicator is updated via the numeric parameter.\u00a0\u00a0 Therefore, in the string parameter I\u2019ll simply send an empty string.\u00a0 Also, I don\u2019t need to pass an ActiveX reference with the message so for the ActiveX object reference I\u2019ll type the key word \u2018Nothing\u2019 which is TestStand\u2019s equivalent to a null object.\u00a0 Finally, for the synchronous boolean I\u2019ll want to set it \u2018True\u2019.\u00a0 Setting this to \u2018True\u2019 will require the Call Method to wait for the user interface to process the message before continuing on.\u00a0 This is very important that you set this \u2018True\u2019 as I\u2019ll show you in a\u00a0later post\u00a0how setting this \u2018False\u2019 can hose up your script.<\/p>\n<p>Now I\u2019m ready to manipulate the progess indicator to show percent complete.\u00a0 As you may recall, the while loop simply loops until 60 seconds has expired.\u00a0 Therefore, I\u2019m going to want to show a percent complete based on the number of seconds that has expired out of the 60.\u00a0 So for the numeric parameter I pass in the following code \u2018(Locals.nCurrentTime\/60)*100\u2019.\u00a0 Figure 4 below now shows what this step looks like.<\/p>\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_710\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig42.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-710\" class=\"size-full wp-image-710\" title=\"tstand-fig4\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig42.jpg\" alt=\"\" width=\"520\" height=\"220\" \/><\/a><p id=\"caption-attachment-710\" class=\"wp-caption-text\">Figure 4<\/p><\/div>\n<\/div>\n<p>Finally, I\u2019m going to add a third <em>Action<\/em> step with adapter type ActiveX\/COM and configure it similar to the step above, but instead of selecting the \u2018UIMsg_ProgressPercent\u2019 message code, I will now select the \u2018UIMsg_ProgressText\u2019 message code.\u00a0 This message code uses the string parameter to display text on the progress bar.\u00a0 Therefore, I\u2019ll set the numeric parameter to 0 and once again set the ActiveX object reference and boolean the same as before.\u00a0 For the string parameter, I\u2019m going to display the current number of seconds that has currently expired so therefore I pass in the code Str(Locals.nCurrentTime) + &#8221; Seconds has Expired&#8221;.\u00a0 Figure 5 below shows what this step now looks like.<\/p>\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_707\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig51.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-707\" class=\"size-full wp-image-707\" title=\"tstand-fig5\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig51.jpg\" alt=\"\" width=\"520\" height=\"225\" \/><\/a><p id=\"caption-attachment-707\" class=\"wp-caption-text\">Figure 5<\/p><\/div>\n<\/div>\n<p>Now my Sequence Call is complete and I\u2019m ready for execution.\u00a0 However, before I do, let\u2019s take a look at how the finished Sequence Call code looks.<\/p>\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_708\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig61.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-708\" class=\"size-full wp-image-708\" title=\"tstand-fig6\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig61.jpg\" alt=\"\" width=\"520\" height=\"302\" \/><\/a><p id=\"caption-attachment-708\" class=\"wp-caption-text\">Figure 6<\/p><\/div>\n<\/div>\n<p>So now I\u2019m going to execute the sequence and let\u2019s see what we get.\u00a0<\/p>\n<div class=\"mceTemp mceIEcenter\">\n<div id=\"attachment_709\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig72.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-709\" class=\"size-full wp-image-709\" title=\"tstand-fig7\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2011\/05\/tstand-fig72.jpg\" alt=\"\" width=\"520\" height=\"27\" \/><\/a><p id=\"caption-attachment-709\" class=\"wp-caption-text\">Figure 7<\/p><\/div>\n<\/div>\n<p>Figure 7 shows that whenever I execute the sequence my progess indicator now shows a scrolling percent complete to the user and the progress bar text has been edited to show the current number of seconds that has expired.<\/p>\n<p>It is always good practice however to clear the progress bar indicator and text upon Sequence Call completion so I would recommend adding two steps in Cleanup to set the numeric parameter to 0 for \u2018UIMsg_ProgressPercent\u2019 and the string parameter to empty strings for \u2018UIMsg_ProgressText\u2019.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With TestStand allowing you to have complete control of the user interface, there are often some clever techniques you can use that can aid you during script development and execution.\u00a0 This post is an example of how the progress bar can be modified to determine the current status of a Sequence Call. As shown in&nbsp;<a href=\"https:\/\/mainlinetest.com\/?p=684\" class=\"read-more\">Continue Reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":741,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[24,25,23],"class_list":["post-684","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-national-instruments","tag-progress-bar","tag-teststand","cat-1-id"],"_links":{"self":[{"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts\/684","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=684"}],"version-history":[{"count":35,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts\/684\/revisions"}],"predecessor-version":[{"id":897,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts\/684\/revisions\/897"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/media\/741"}],"wp:attachment":[{"href":"https:\/\/mainlinetest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=684"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=684"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=684"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}