09-04-2012 12:37 PM
Hi,
After several hours of debugging, I finally was able to pass a reference of type struct tsErrorDataType from TestStand to a CVI DLL and modify it.
The initial problem was that the struct is defined w/ a 1024 byte msg buffer, but TestStand passes a pointer to the buffer, so their is a memory alignment issue when trying to use the struct as defined in the tsutil.h file.
My solution was this:
#include <ansi_c.h>
#include <tsutil.h>
#pragma pack(8)
// Type Definitions
typedef struct {
int code;
char *msg;
int occurred;
}MyErrorDataType;
/*** Struct Definition in tsutil.h ******
struct tsErrorDataType
{ int code;
char msg[1024];
int occurred;
};
*****************************************/
__declspec(dllexport) void ErrStatus(struct tsErrorDataType *err) // Using TestStand's Error Data Type ensures we can pass variables such as Step.Result.Error
{
MyErrorDataType *MyErr = (MyErrorDataType *)err; // Re-casting the pointer to match what TestStand actually passes for the reference.
MyErr->code = -1;
MyErr->occurred = 1;
sprintf(MyErr->msg,"%s","Error!\0");
return;
}
This solution seems to work, but I'm surprised there was not a more obvious way to handle the Error Data Type in CVI so commonly found in TestStand and LabView.
Is this solution sound? Is there a better way?
09-04-2012 03:29 PM
You can use this CVI function to directly set the arguments:
void TS_SetStepError (CAObjHandle Sequence_Context,int Error_Code, char Error_Message[]);
09-05-2012 08:31 AM
The proposed solution is to be used in a number of instrument drivers compiled into .dll's that will be CVI adapter calls. The function you reference is part of the TestStand API that you would use if your writing a user interface application, correct? My goal is to standardize the error handling when calling instrument driver functions as I have a number of developers that will have their hands in developing the code. I'm trying to come up with a basic standardized error handling design and enforcre those requirements on the developers. Some of the drivers will be simple as they will essentially be just wrappers for their IVI equivilents, but some instrumentation is unique and the driver code will be developed from scratch.
09-05-2012 09:35 AM
I have used this function in a DLL.
Its functionality is same as the function that is written by you.
09-05-2012 09:44 AM
So your saying at run time I can get a reference to the "CAObjHandle Sequence_Context" from TestStand and pass it to my .dll function call and set the error parameter in the .dll call as needed?
09-05-2012 09:58 AM
Yes your runtime function needs to have this parameter.