Use Model callbacks to customize the behavior of a process model for each client sequence file that the process model uses. By defining one or more Model callbacks in a process model, you can specify the process model operations you can customize in a client sequence file. When you define a Model callback in a client sequence file, the Model callback overrides the sequence in the process model so that the sequence the client file defines runs instead of the sequence in the model file.
Why Use a Model Callback?
The default process model is sufficient for most situations, but you might need to modify the default model by replacing certain behaviors with different behaviors. For example, the default process models define a TestReport callback that generates the test report for each UUT. Normally, the TestReport callback in the default process model file is sufficient because the TestReport callback handles many types of test results. You can, however, override the default TestReport callback by defining a different TestReport callback in a particular client sequence file using the Sequence File Callbacks dialog box.
Other common use cases for overriding a model callback include:
- Changing the report options to always report in a certain format or location.
- Changing the database options to specify how TestStand logs information to a database.
- Changing the model options to always use a certain number of test sockets.
- Adding initialization code that TestStand runs once before testing a set of UUTs.
- Adding clean-up code that TestStand runs once after testing a set of UUTs.
- Identifying the UUT serial numbers with a barcode scanner.
- Changing how TestStand generates the report.
Modifying the Process Model vs. Using a Model Callback
You often must choose between modifying a process model directly and using a model callback when you decide how to handle custom behaviors. Although both options are feasible, consider the following scenarios to help you determine which alternative to use:
Situation: You want to add behavior you designed to be common across all the sequence files you run.
Solution: Put the code in the process model.
Justification: If you put the code in a callback, you must do so for every sequence file you run. Developers can forget to do this which can cause incorrect behavior. If you must modify the code, you must search for all the copies in multiple sequence files.
Situation: You want to add behavior that is mostly common across all the sequence files you run, but some sequence files require a different behavior.
Solution: Put the code in the process model.
Justification: This scenario is similar to Scenario 1, except sequence files that need a different behavior can use a callback to override the behavior.
Situation: You have many different behaviors you want to occur at some point in a sequence, but not for a majority of the time.
Solution: Choose one (or none) of the behaviors as a default. If you choose to make one of the behaviors the default, put the behavior in the process model. Override the callback for the other sequence files.
Justification: In a situation that varies for individual situations, the model must do something because there is no true default behavior. This behavior can be one behavior designated default or nothing and require the sequence files to implement the behavior. If a behavior is repeated, NI recommends that you code the behavior in a separate sequence file so the code resides in only one place.
How to Use a Model Callback
Each process model can define any number of Model callbacks, which appear with a green icon in the sequence list. Right-click the Sequence View control and select Sequence File Callbacks from the context menu to launch the Sequence File Callbacks dialog box, in which you can view a list of all Model and Engine callbacks available (depending on the process model currently associated with the sequence file) and add model callbacks to normal sequence files. Double-click on the desired callback or click the Add button in the Sequence File Callbacks dialog box to add model callbacks. Notice that when you double-click on the desired callback the value of the Present column changes from No to Yes. After you add the desired callbacks, they appear in the sequence list. Users can also create model callbacks by creating a new sequence and naming the sequence with the same name as a callback.
You can also add new model callbacks to the process model by adding a sequence to the sequence list. After you add the sequence, you must designate the sequence as a Model callback by right-clicking on the sequence and selecting Sequence Properties from the context menu. You must change the Type from Normal to Callback on the Model tab of the Sequence Properties dialog box. The Type option is only available when the sequence is in a process model.