NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying/Passing tsErrorDataType from CVI to TestStand

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?

0 Kudos
Message 1 of 6
(3,244 Views)

You can use this CVI function to directly set the arguments:

 

void TS_SetStepError (CAObjHandle Sequence_Context,int Error_Code, char Error_Message[]);

 

 

0 Kudos
Message 2 of 6
(3,234 Views)

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.

0 Kudos
Message 3 of 6
(3,227 Views)

I have used this function in a DLL.

 

Its functionality is same as the function that is written by you.

 

 

0 Kudos
Message 4 of 6
(3,222 Views)

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?

0 Kudos
Message 5 of 6
(3,219 Views)

Yes your runtime function needs to have this parameter.

0 Kudos
Message 6 of 6
(3,216 Views)