{"id":1072,"date":"2012-06-18T16:53:39","date_gmt":"2012-06-18T20:53:39","guid":{"rendered":"http:\/\/mainlinetest.com\/?p=1072"},"modified":"2012-06-18T17:01:45","modified_gmt":"2012-06-18T21:01:45","slug":"introduction-to-callbacks","status":"publish","type":"post","link":"https:\/\/mainlinetest.com\/?p=1072","title":{"rendered":"Introduction to Callbacks"},"content":{"rendered":"<p>In TestStand, each sequence file has a setting that identifies a corresponding process model. TestStand comes with three default process models (Sequential, Batch, and Parallel) however you can custom home roll your own.  A process model itself is a sequence file, however it contains all of the common code needed to run individual sequences and is not specific to any UUT.\u00a0 Think of it like this.\u00a0 Whenever you execute a sequence file, typically the process model sequence file is what executes first.\u00a0 The process model is smart enough to know when it needs to do stuff behind the scenes that you don\u2019t need to worry about (i.e. report generation or database logging) and when it needs to tell the desired sequence file to start executing.\u00a0 In fact, the desired sequence file and the process model file can communicate with one another.\u00a0 It does so via Callbacks.<\/p>\n<p>In TestStand, there are two kinds of Callbacks; Model Callbacks and Engine Callbacks.\u00a0 Callbacks, like process models, are sequences that either execute when certain points of the process model file are reached or when certain events occur in the TestStand Engine.\u00a0 Callback sequences are optional and a lot of times are empty and possess no code.\u00a0 However, you may find yourself at times needing to customize TestStand to your specific needs and Callbacks provide major flexibility when architecting a solution.\u00a0 One way to modify or add code in one of these predefined Callbacks is in a process called overriding the Callback.\u00a0 In this blog post, I am going to introduce you the world of Callbacks by walking you through an existing Callback and then we will override it to demonstrate the flexibility of TestStand.<\/p>\n<p>First I am going to open up TestStand and start a new sequence file.\u00a0 Immediately in the lower left portion of TestStand you will be able to see what current process model file you are working with as shown in Figure 1.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb.png\" border=\"0\" alt=\"image\" width=\"485\" height=\"42\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 1<\/strong><\/p>\n<p>As you can see, I am currently defaulted to use the SequentialModel.seq.\u00a0 I can get into process models in detail in another blog post, but for now lets (meaning me) stay on task and take a look at the process model code.\u00a0 In order to open this file, you can browse your explorer window searching for that specific file or you can simply double-click on the box show in Figure 1 and it will bring it up in the TestStand script editor.\u00a0 I choose to double-click.\u00a0 Now that we have pulled the process model up, take a look at the Sequence window as shown in Figure 2.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb1.png\" border=\"0\" alt=\"image\" width=\"508\" height=\"298\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 2<\/strong><\/p>\n<p>See all those sequences with the green boxes next to them?\u00a0 Those sequences are the process model Callbacks that can be overridden in your sequence file.\u00a0 Click on \u2018PreUUTLoop\u2019 and take a look at the code.\u00a0 Pretty disappointing huh?\u00a0 Like I said earlier, a lot of these Callback sequences contain no code.\u00a0 TestStand contains these bookmark sequences however to help you, the user, potentially customize or modify process models in a manner that won\u2019t mess a lot of things up.\u00a0 Note that whenever you make a change to the process model, any sequence file that points to that process model file will now behave differently as you have defined.\u00a0 Therefore, sometimes it is best to make the modifications at a higher level and that is where overriding comes in.<\/p>\n<p>Next I want you to scroll the Sequence scroll bar all the way down to the bottom as shown in Figure 3.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb2.png\" border=\"0\" alt=\"image\" width=\"533\" height=\"319\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 3<\/strong><\/p>\n<p>Notice the two sequences with the purple boxes next to them?\u00a0 These are actually Engine Callbacks that have already been overridden.\u00a0 How can you even know that you ask?\u00a0 Well right-click on a sequence and select \u2018Sequence File Callbacks\u2026\u201d.\u00a0 You should get a window similar to that shown in Figure 4 below.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb3.png\" border=\"0\" alt=\"image\" width=\"523\" height=\"311\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 4<\/strong><\/p>\n<p>This window displays all of the current Callbacks that can be overridden.\u00a0 I want you to particularly notice two things.\u00a0 First of all, notice how all the Callbacks are of type \u2018Engine\u2019.\u00a0 Why don\u2019t we have any Model Callbacks?\u00a0 The reason is because we are currently in a process model file and having a process model override it\u2019s own Callbacks would be crazy and cause a black hole to open around the Earth.\u00a0 Secondly, notice under the \u2018Present\u2019 column that two Callbacks are set to \u2018yes\u2019.\u00a0 These happen to be the ones that have been overridden and thus have been modified for this specific process model.\u00a0 Pretty cool stuff!\u00a0 Now click \u2018Cancel\u2019 and lets select the \u2018PreUUT\u2019 sequence (not the \u2018PreUUTLoop\u2019 sequence).\u00a0 You should see code similar to that shown in Figure 5 below.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb4.png\" border=\"0\" alt=\"image\" width=\"607\" height=\"160\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 5<\/strong><\/p>\n<p>If you read the comment associated with this sequence it says the following: \u201cDisplays a dialog box in which the operator enters the UUTserial number.\u00a0 Override this in client file to change or replace this action.\u201d\u00a0 So pretty straight forward here.\u00a0 If you have ever executed a script using the \u2018Test UUTs\u2019 button you would know that this is the code that pops up the dialog box prompting to either enter the Serial Number of the UUT to begin the next test or to stop testing altogether.\u00a0 Now imagine you have a specific UUT in which your manager wants you to add an additional pop-up message telling the operator to make sure all cell phones and electronic devices are turned off prior to beginning a test and that he wants this message to pop up prior to testing every unit.<\/p>\n<p>While you could just add the code in the process model itself; other UUTs may use the same process model and that user message may not even apply or make sense in those cases.\u00a0 So we need to override the PreUUT Callback in our own sequence file.\u00a0 So now lets go back to our new blank sequence file but keep the process model open in another window.\u00a0 Before you add any code lets execute the script to get the general gist of how the \u2018PreUUT\u2019 sequence works.\u00a0 Select Execute&gt;&gt;Test UUTs and you should get a popup dialog as shown in Figure 6.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image5.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb5.png\" border=\"0\" alt=\"image\" width=\"363\" height=\"173\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 6<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>This is the popup dialog that takes in the Serial Number prior to execution.\u00a0 We are still going to want this in our new overridden Callback.\u00a0 Therefore, we need to copy the code from the \u2018PreUUT\u2019 sequence file, but before we can do this we need to override it first.\u00a0 Once again, right-click on a sequence and select \u2018Sequence File Callbacks\u2026\u201d to get a window similar to that shown in Figure 7.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image6.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb6.png\" border=\"0\" alt=\"image\" width=\"466\" height=\"283\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 7<\/strong><\/p>\n<p><strong><br \/>\n<\/strong><\/p>\n<p>Now you should be able to see both Engine and Model Callbacks.\u00a0 Also, notice how \u2018MainSequence\u2019 itself is a Callback.\u00a0 I just blew your mind! So go ahead and select \u2018PreUUT\u2019 and hit the ADD button.\u00a0 Your sequence window should now look like that shown in Figure 8.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image7.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb7.png\" border=\"0\" alt=\"image\" width=\"448\" height=\"111\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 8<\/strong><\/p>\n<p><strong><br \/>\n<\/strong><\/p>\n<p>So now go ahead and copy the code from the process model to the \u2018PreUUT\u2019 Callback.\u00a0 You will have to declare Locals.SerialNumber as a string such that the script doesn\u2019t generate an error.\u00a0 Now insert a \u2018Message Popup\u2019 step and configure it as shown in Figure 9 below.<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image8.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb8.png\" border=\"0\" alt=\"image\" width=\"536\" height=\"146\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 9<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>Your Callback should now look like that shown in Figure 10.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image9.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border: 0px;\" title=\"image\" src=\"http:\/\/mainlinetest.com\/wp-content\/uploads\/2012\/06\/image_thumb9.png\" border=\"0\" alt=\"image\" width=\"531\" height=\"208\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 10<\/strong><\/p>\n<p>Now one last time lets select Execute&gt;&gt;Test UUTs.\u00a0 BAM!\u00a0 Try it out by entering several different serial numbers.\u00a0 You have just overridden your first Callback.\u00a0 Well not really, cause you have been using \u2018MainSequence\u2019 for a while now.\u00a0 Either way, pat yourself on the back.<\/p>\n<p>In conclusion, Callbacks are a very powerful tool and add to the flexibility and customizability of TestStand.\u00a0 Knowing when to override versus modifying in the process model is a big decision.\u00a0 Sequence files can override both Engine and Model Callbacks while process models can only override Engine Callbacks.\u00a0 Also note, that when both a sequence file and a process model override the same Engine Callback, the sequence file version takes precedence.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In TestStand, each sequence file has a setting that identifies a corresponding process model. TestStand comes with three default process models (Sequential, Batch, and Parallel) however you can custom home roll your own. A process model itself is a sequence file, however it contains all of the common code needed to run individual sequences and&nbsp;<a href=\"https:\/\/mainlinetest.com\/?p=1072\" 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":[48,44,45,46,49,50,51,39,52,47,23],"class_list":["post-1072","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-batchmodel","tag-callbacks","tag-engine-callbacks","tag-model-callbacks","tag-parallelmodel","tag-preuut","tag-preuutloop","tag-process-model","tag-sequence-file","tag-sequentialmodel","tag-teststand","cat-1-id"],"_links":{"self":[{"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts\/1072","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=1072"}],"version-history":[{"count":6,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts\/1072\/revisions"}],"predecessor-version":[{"id":1078,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=\/wp\/v2\/posts\/1072\/revisions\/1078"}],"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=1072"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1072"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mainlinetest.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1072"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}