In order to return a struct from LabWindows™/CVI™ to TestStand you must do the following:
- In LabWindows/CVI create a structure that contains the data you want to pass to TestStand. Here is an example that is used for the rest of the steps:
struct ErrorStruct {
unsigned char errorFlag; // 0 = FALSE, 1 = TRUE
int errorCode;
char errorMessage[256];
};
- In TestStand, create a custom data type (TestStand Container) that exactly resembles the structure you created in LabWindows/CVI.
- Rename the new data type to ErrorStruct (must be the same as the struct in CVI).
- Right-click inside the new data type and select Insert Custom Data Type » Boolean to insert a new field in the data type.
- Rename the new field to errorFlag.
- Right-click inside the new data type and select Insert Custom Data Type » Number to insert a new field in the data type.
- Rename the new field to errorCode.
- Right-click inside the new data type and select Insert Custom Data Type » String to insert a new field in the data type.
- Rename the new field to errorMessage.
- Right-click the data type that you have just created in the tree view and select Properties to launch the Type Properties dialog box.
- Select the C Struct Passing tab.
- Enable the Allow Objects of This Type to be Passed as Structs.
- Select errorMessage in the Property dropdown. Make sure that the String Type setting is set to C String buffer.
- Make sure the appropriate data types are selected for the other options in the Property dropdown.
- errorFlag - Signed 16-bit Integer
- errorCode - 64-bit Real Number (double)
- Click OK (saving changes).
- Once you have completed this, you can then use the DLL Adapter to call your LabWindows/CVI module that should have a prototype that resembles:
void __declspec(dllexport) Test(struct ErrorStruct *errorCluster);
Now you should be able to pass data into TestStand from CVI:
//Change the TestStand structure contents
errorCluster->errorCode = 999;
errorCluster->errorFlag = 1;
strcpy (*ErrorCluster->errorMessage, "Error Occurred");
- Next, create a local variable in TestStand with ErrorStruct type.
- Add a CVI Action into the sequence and configure dll:
Additional Information
Please find the working code (TestStand Sequence and LabWindows/CVI code) used in this tutorial in the attachment.