Use the LabWindows/CVI Adapter to call LabWindows/CVI code modules from TestStand, to create new code modules to call from TestStand, to edit and debug existing code modules, and to use LabWindows/CVI data types in TestStand.

Note Completed solution files are located in the <TestStand Public>\Tutorial\Solution directory.

Required LabWindows/CVI Settings

All of the tutorials on this page require you to have the LabWindows/CVI development system and TestStand installed on the same computer.

In addition, complete the following steps to configure the LabWindows/CVI Adapter to execute steps in an external instance of the LabWindows/CVI development system and to allow only new code templates.

  1. Select Configure»Adapters to launch the Adapter Configuration dialog box.
  2. Select LabWindows/CVI in the Adapter column and click the Configure button to launch the LabWindows/CVI Adapter Configuration dialog box.
  3. In the Step Execution section, select the Execute Steps in an External Instance of CVI option.
  4. In the Code Template Policy section, select the Allow Only New Templates option.
  5. Click OK to close the LabWindows/CVI Adapter Configuration dialog box, click OK again when the adapter displays a warning that confirms TestStand will unload all modules, and click Done in the Adapter Configuration dialog box.

Creating and Configuring Steps with the LabWindows/CVI Adapter

Complete the following steps to insert a new step that uses the LabWindows/CVI Adapter and configure the step to call a code module.

  1. Select File»New»Sequence File to open a new sequence file.
  2. Save the sequence file as CallCVICodeModule.seq in the <TestStand Public>\Tutorial directory.
  3. Select the LabWindows/CVI adapter from the Adapter ring control above the Step Types list.
  4. Insert a Pass/Fail Test step in the Main step group and rename the new step CVI Pass/Fail Test.
  5. On the LabWindows/CVI Module tab of the Step Settings pane, click the File Browse button located to the right of the Module control, navigate to <TestStand Public>\Tutorial\CallCVICodeModule.dll, and click Open.
  6. Select PassFailTest from the Function ring control.
    Note When you select a function, the LabWindows/CVI Adapter attempts to read the export information LabWindows/CVI includes in the DLL or the function parameter information from the type library in the code module, if one exists. When the function parameter information is not defined, you can select a code template from the Code Template ring control to specify the function prototype or add parameters to the Parameters Table control to specify the function prototype.
  7. Select PassFail template for LabWindows/CVI from the Code Template ring control. The Parameters Table control contains the default value expressions the code template specifies. When TestStand calls the code module, the LabWindows/CVI Adapter stores the returned values for the result and the error details in the specified properties of the step.
  8. Save the changes and select Execute»Single Pass. Because the LabWindows/CVI Adapter is configured to use an external instance of LabWindows/CVI to execute code modules, TestStand launches the LabWindows/CVI development environment to execute the function the step calls. When the execution completes, the report indicates the step passed.
  9. Select File»Unload All Modules to unload the DLL the step calls so you can rebuild the DLL in a subsequent tutorial.
  10. Close the Execution window. Leave the sequence file open for the next tutorial.

Creating a New Code Module from TestStand

Note NI recommends using DLL files when you develop code modules using the LabWindows/CVI Adapter. The following tutorials demonstrate creating and debugging only DLL code modules.

Complete the following steps to create a new code module from TestStand.

  1. Select File»Save <filename> As and save the sequence file as CallCVICodeModule2.seq in the <TestStand Public>\Tutorial directory.
  2. Insert a Numeric Limit Test step after the CVI Pass/Fail Test step and rename the new step CVI Numeric Limit Test.
  3. On the LabWindows/CVI Module tab, complete the following steps to configure the CVI Numeric Limit Test step.
    1. Click the File Browse button, navigate to <TestStand Public>\Tutorial\CallCVICodeModule.dll, and click Open.
    2. Enter NumericLimitTest in the Function ring control.
    3. Select NumericLimit template for LabWindows/CVI from the Code Template ring control. Notice that TestStand automatically updates the function prototype and parameter values based on the information stored in the code template for the Numeric Limit Test step type.
  4. Click the Source Code Files button, located to the right of the Parameter Details Table control, to launch the CVI Source Code Files window and complete the following steps.
    1. Enter CVINumericLimitTest.c in the Source File Containing Function control.
    2. For the CVI Project File to Open control, click the File Browse button, navigate to <TestStand Public>\Tutorial\CallCVICodeModule.prj, and click Open.
    3. Click Close.
  5. Click the Create Code button, located just below the Source Code Files button, to create a code module. When you click the Create Code button, TestStand launches the Select a Source File dialog box, in which you can specify the source code to use for the code module.
  6. Navigate to the <TestStand Public>\Tutorial directory and click OK. TestStand creates a new code module source file named CVINumericLimitTest.c based on the available code templates for the TestStand Numeric Limit Test step type and opens the code module in LabWindows/CVI.
    Note The TestStand Numeric Limit Test step type requires code modules to store a measurement value in the Step.Result.Numeric property, and the step type performs a comparison operation to determine whether the step passes or fails. Code modules can pass step properties as parameters to and from the code module or use the TestStand API in the code module to update step properties. When you use a default code template from NI to create a code module, TestStand creates the parameters needed to access the step properties for you.
  7. In LabWindows/CVI, uncomment the following code in the source file: double testMeasurement = 10.0; double lowLimit; *measurement = testMeasurement;
  8. Save and close the source file. Leave LabWindows/CVI open.
  9. In the LabWindows/CVI project window, select Build»Create Debuggable Dynamic Link Library to rebuild the DLL. Click OK when LabWindows/CVI prompts you that the files are created.
  10. In TestStand, save the changes and select Execute»Single Pass. When the execution completes, the report indicates the step passed with a numeric measurement of 10.
  11. Select File»Unload All Modules to unload the DLL.
  12. Close the Execution window. Leave the sequence file and LabWindows/CVI open for the next tutorial.

Editing an Existing Code Module from TestStand

Complete the following steps to edit an existing code module from TestStand.

  1. Select the CVI Numeric Limit Test step and use the LabWindows/CVI Module tab to complete the following steps.
    1. Click the Edit Code button, located just below the Create Code button. LabWindows/CVI becomes the active application in which the CVINumericLimitTest.c source file is open.
    2. Change the initial value in the declaration for the testMeasurement variable to 5.0.
    3. Save and close the source file. Leave LabWindows/CVI open.
  2. Rebuild the DLL. Click OK when LabWindows/CVI prompts you that the files are created.
  3. In TestStand, select Execute»Single Pass. When the execution completes, the report indicates the step failed with a numeric measurement of 5.
  4. Close the Execution window. Leave the sequence file and LabWindows/CVI open for the next tutorial.

Debugging a Code Module

Complete the following steps to debug a code module you call from TestStand using the LabWindows/CVI Adapter.

  1. Place a breakpoint at the CVI Pass/Fail Test step.
  2. Select Execute»Run MainSequence. The execution pauses at the CVI Pass/Fail Test step.
  3. Complete the following steps to debug the code module the CVI Pass/Fail Test step calls.
    1. Click the Step Into button on the Debug toolbar in TestStand. LabWindows/CVI becomes the active application, in which the LabWindows/CVI Pass-Fail Test code module is open and in a suspended state.
    2. Click the Step Into button or the Step Over button on the LabWindows/CVI toolbar to begin stepping through the code module.
    3. When you finish stepping through the code module, click the Finish Function button on the LabWindows/CVI toolbar to return to TestStand. The execution pauses at the next step in the sequence.
  4. Click the Resume button on the Debug toolbar in TestStand to complete the execution.
  5. Close the Execution window.
  6. Select File»Unload All Modules to unload the DLL.
  7. Remove the breakpoint from the CVI Pass/Fail Test step. Leave the sequence file and LabWindows/CVI open for the next tutorial.

Creating TestStand Data Types from LabWindows/CVI Structs

TestStand provides number, string, Boolean, and object reference built-in data types. TestStand also provides several standard named data types, including Path and Error. You can create container data types to hold any number of other data types. TestStand container data types are analogous to C structures in LabWindows/CVI.

Complete the following steps to create a TestStand data type that matches a LabWindows/CVI struct and call a function in a DLL that has the struct as a parameter.

Creating a New Custom Data Type

Complete the following steps to create a new container data type that contains numeric and string subproperties.

  1. Click the Types button on the sequence editor toolbar to open the Types window.
  2. Select the CallCVICodeModule2.seq sequence file on the View Types For pane.
  3. Right-click the Custom Data Types item and select Insert Custom Data Type»Container from the context menu to insert a new data type. Rename the new container data type CVITutorialStruct.
  4. Expand the CVITutorialStruct item.
  5. Right-click the CVITutorialStruct item and select Insert Field»Number from the context menu to insert a new field in the data type. Rename the new field Measurement.
  6. Right-click the CVITutorialStruct item and select Insert Field»String from the context menu to insert another new field in the CVITutorialStruct container data type. Rename the new field Buffer.
  7. Save the changes. If TestStand warns you that the sequence file contains modified types, review the information in the warning dialog box, select the Increment Type Versions option, and click OK. Leave the sequence file open for the next tutorial.

Specifying Structure Passing Settings

Complete the following steps to specify the structure passing properties for the CVITutorialStruct container data type.

  1. Right-click the CVITutorialStruct item in the Types window and select Properties from the context menu to launch the Type Properties dialog box. The name of the Type Properties dialog box is specific to the name of the property you select.
  2. Click the C Struct Passing tab of the Type Properties dialog box.
  3. Enable the Allow Objects of This Type to be Passed as Structs option. The Property ring control lists the two fields in the CVITutorialStruct container data type. Notice that the Numeric Type control for the Measurement property defaults to 64-bit Real Number (double).
  4. Select the Buffer property from the Property ring control.
  5. For the String Type control, select the C String Buffer option to allow the C function to alter the value of the structure field.
  6. Click the Version tab of the Type Properties dialog box and disable the Modified option.
  7. Select OK to close the Type Properties dialog box.
  8. Save the changes. Close the Types window. Leave the sequence file open for the next tutorial.

Calling a Function with a Struct Parameter

Complete the following steps to use the CVITutorialStruct container data type as a parameter to a function a step calls.

  1. Select File»Save <filename> As and save the sequence file as CallCVIModule3.seq in the <TestStand Public>\Tutorial directory.
  2. Click the Variables pane.
  3. Right-click the Locals item, select Insert Local»Type»CVITutorialStruct from the context menu to insert an instance of the container data type, and rename the new variable CVIStruct.
  4. Insert an Action step into the Main step group after the CVI Numeric Limit Test step and rename the new step Pass Struct Test.
  5. On the LabWindows/CVI Module tab, click the File Browse button, navigate to <TestStand Public>\Tutorial\CallCVICodeModule.dll, and click Open.
  6. Enter PassStructTest in the Function control.
  7. Click the Add Parameter button, located to the right of the Parameters Table control, to insert a new parameter in the Parameters Table control.
  8. Enter the following information in the Parameter Details Table control:
    1. In the Name field, rename the parameter cviStruct.
    2. In the Category field, select C Struct.
    3. In the Type field, select CVITutorialStruct.
  9. Enter Locals.CVIStruct in the Value Expression column for the parameter in the Parameters Table control.
  10. Click the Source Code Files button to launch the CVI Source Code Files window. Complete the following steps to select the source file and project file to use when inserting the function.
    1. Enter CVIStructPassingTest.c in the Source File Containing Function control.
    2. For the CVI Project File to Open control, click the File Browse button, navigate to <TestStand Public>\Tutorial\CallCVICodeModule.prj, and click Open.
    3. Click Close.
  11. Click the Create Code button to create a code module. TestStand launches the Select a Source File dialog box.
  12. Browse to the <TestStand Public>\Tutorial directory and click OK. TestStand creates a new source file named CVIStructPassingTest.c with an empty function.
  13. In LabWindows/CVI, complete the following steps.
    1. Add the following type definition before the PassStructTest function:
      struct CVITutorialStruct { double measurement; char buffer[256]; };
    2. Add the following code to the PassStructTest function:
      if (cviStruct) { cviStruct->measurement = 10.0; strcpy(cviStruct->buffer, "Average Voltage"); }
    3. Add the following statement to the top of the source file to include the declaration of the strcpy function:
      #include <ansi_c.h>
  14. Save and close the source file.
  15. In the LabWindows/CVI project window, select Build»Create Debuggable Dynamic Link Library to rebuild the DLL. Click OK when LabWindows/CVI notifies you that the files are created.
  16. In TestStand, place a breakpoint at the new Pass Struct Test step.
  17. Save the changes and select Execute»Run MainSequence.
  18. Step through the sequence and review the values in the Locals.CVIStructvariable on the Variables pane of the Execution window before and after executing the Pass Struct Test step.
  19. Select File»Unload All Modules to unload the DLL.
  20. Remove the breakpoint from the CVI Pass/Fail Test step. Close all the windows in the sequence editor.