Simulating a Lookup Table with a C# Snippet
On a Test Bench, a wiring harness is used to connect the test equipment to the System Under Test (SUT). In the context of the MxSuite, the Harness connects MxVDev to the SUT.
The procedure below demonstrates how to use MxTransIt to create a simple Test Harness. The SUT is a simple transform that implements a lookup table.
A harness can be extended to connect to and test much more complex systems. The SUT can be a Simulink model, a dSPACE system, NI equipment, a simulated microcontroller, or a combination of these type of things. The harness is also used for creating a co-simulation environment, performing signal conditioning or custom pass/fail analysis.
This example demonstrates the operation of the simplest of custom harnesses with a single transform for a SUT. The SUT is a lookup table implemented in C# using the C# Snippet Transform. The table below shows the transformation to be implemented:
1.Select File‑>New‑>Project from the MxVDev main menu. Follow the wizard until you see this form:
For more details, see Creating a new project.
2.Select Custom SUT.
3.Select MxClock. For information about clocks, see Real Time/Accelerated Time.
4.Check Start MxTransIt on Finish.
5.Click the Finish button. MxTransIt opens.
6.From the Toolbox on the left of the screen, select the C# Snippet Transform and double-click to put it into the editor (center window).
7.In the editor, click on the Transform to select it. Its properties are displayed on the right of your screen:
8.Enter a name for your Transform in the Name field. In our example, we named it Look Up.
9.Next, enter create new input and output signals:
a.Click the Add InPort verb.
b.On the Add/Edit Port form, enter the name Col1 for the signal.
c.Select the Discrete (Integer) button.
d.Enter a Max value of 5 for Col1. (When you edit Col2, use a Max value of 10).
f.Click the Add OutPort verb, and repeat steps 9a through 9e for the output signal. Name it Col2 and give it a Max value of 10.
10.Click the Transform to select it and display its Properties box. (Do not confuse the Port properties with the Transform properties.)
Edit C# Verb in Properties Box
11.Click Edit C# at the bottom of the Properties box to display:
12.Enter the following C# snippet in the Execution Code window. Be sure to overwrite the code already in the window.
Tip: You can use copy and paste to copy the C# code from this Help window.
13.Click the View Code button to see the code you entered in context.
14.Click the Compile button.
If there are no errors in the snippet, "Compile Successful" is displayed in the Noticiations window.
16.Select Transform->Export Ports from the main menu:
17.Check both ports and click OK to export to MxVDev. (For more details, see Exporting Ports.)
18.Click to save your transform.
19.Select File->Exit from the main menu to close MxTransIt.
20.Return to MxVDev.
21.When you see the reload message, click Yes.
22.When the Stimulus Connections and Response Connections forms are displayed, click OK to import your ports (signals) from MxTransIt into the Signal Dictionary. (For more details, see Connecting Signals.)
You have now created a C# Look-up table SUT using MxTransIt. Next, we can test it with MxVDev.
Using Your Transform in a TestCase
1.To build a test case, select File->New->TestCase from the main menu.
2.Enter the name Look Up TestCase and other properties as shown in the figure above.
3.Press the OK button. The Pick Signals box is displayed.
4.Make sure that Stimulus>Standard is selected on the left-hand side.
5.Select Col1 and click to add it to Selected Signals.
6.Then select Response>Standard on the left-hand side and add Col2 to the Selected Signals.
7.Click the OK button and save the TestCase with an appropriate file name.
8.Select View->Transition List to display the Specified Transition List.
9.Click in the plot line area of the Col1 signal to select it. Be sure the correct signal is selected as shown below in the red oval. See Using the Transition List.
10.Enter the values shown below to create a test pattern for your input signal. Edited values shown in yellow are not accepted until you press the Enter key.
The specified values are displayed graphically in the TestCase window. Use the Enlarge button for easier viewing.
Create a Scenario
1.Select File->New->Scenario from the main menu.
2.Give the Scenario a suitable name and click OK.
3.Enter a description of the Scenario if desired.
4.Save the Scenario.
5.Click on the TestCase to select it, then select TestCase->Add to Scenario from the main menu.
For more details, see Working with Scenarios.
6.Now you are ready to run the test. Click Run ().
The test fails because we have not defined our expected results.
7.Since the Col2 signal matches the values defined in our Look-Up table, click to accept the results.
8.Click the Rewind and Run buttons to see the test pass.
If your test results are not repeatable, see System Reset.