NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Retreiving char array from LabWindows/CVI

Hi,
I currently use LabWindows/CVI to automate the connection and sending commands to a Telnet server (in a DLL). This DLL is used in TestStand. The DLL reports any errors trough its numeric return value to TestStand, with the standard error codes of the Internet library. I also want to return the error string generated from InetGetErrorMessage. When I test my module in LabWindows/CVI the string is ok. What I want to do now is to return the error string trough the string buffer of one of the parameter of the function. The problem is that when I get back in TestStand the buffer has all kind of weird characters in it (not what's expected). Any tips on how I should return this string to TestSTand (3.1)?

Thanks!

Louis
0 Kudos
Message 1 of 8
(4,842 Views)
Hi,

Is this the sort of thing you are doing in your C code:

void __declspec(dllexport) __stdcall demoError(CAObjHandle seqContextCVI,
char reportText[1024], short *errorOccurred, long *errorCode, char errorMsg[1024])
{
ViSession rm;
ViSession handle;
int error = 0;
ErrMsg errMsg = {'\0'};
ERRORINFO errorInfo;
// char *lastUserName = NULL;

// INSERT YOUR SPECIFIC TEST CODE HERE

// The following code shows how to access a property or variable via the TestStand ActiveX API
// tsErrChk (TS_PropertyGetValString(seqContextCVI, &errorInfo,
// "StationGlobals.TS.LastUserName",
// 0, &lastUserName));

tsErrChk(viOpenDefaultRM (&rm));

tsErrChk(viOpen (rm, "GPIB::1::0::INSTR", VI_NULL, VI_NULL, &handle));

Error:
// FREE RESOURCES
// if (lastUserName != NULL)
// CA_FreeMemory(lastUserName);

// If an error occurred, set the error flag to cause a run-time error in TestStand.
if (error < 0)
{
*errorOccurred = TRUE;
viStatusDesc (handle, error, errMsg);

// OPTIONALLY SET THE ERROR CODE AND STRING
*errorCode = error;
strcpy(errorMsg, errMsg);
}
}


Or are you using the TestStand version 2.0 prototype?



Regards
Ray Farmer
Regards
Ray Farmer
0 Kudos
Message 2 of 8
(4,835 Views)
I was using something similar to this code. I switched to the testData and testError struc and now it works. Is there any obvious reason why the first solution wouldn't work proprely?

Thanks
0 Kudos
Message 3 of 8
(4,831 Views)
Hi,

No, it should have worked!!!

Regards
Ray Farmer
Regards
Ray Farmer
0 Kudos
Message 4 of 8
(4,824 Views)
Hi,

The code I attached was tried with TestStand 3.0, noticed that you are using TestStand 3.1.

Maybe someone else could try it on TestStand 3.1

Regards
Ray Farmer
Regards
Ray Farmer
0 Kudos
Message 5 of 8
(4,823 Views)
My bad, I was using a simple = to place the string in my errorMsg variable. With the strcpy ( strcpy(errorMsg, InetGetErrorMessage(testError->errorCode)); ) it works great. Still, shouldn't it have worked with the = ( errorMsg = InetGetErrorMessage(testError->errorCode) ) ?

Thanks,

Louis
0 Kudos
Message 6 of 8
(4,811 Views)
Louis,

No, assigning one string variable to another in C cannot be done using the = operator. This has to do with the way strings are handled in C. A string in C is really a NULL-terminated array of characters. An array of characters in C is really just a character pointer which points to some allocated memory. So, ErrMsg is a character pointer to an allocated bunch of memory. The memory for ErrMsg is allocated in TestStand and what gets passed to your function is actually a character pointer pointing to this memory. Actually, all you get is a copy of this character pointer, so assigning to it only changes your local copy of the pointer, not the pointer that TestStand has. In order to get the contents of the string into the character array that TestStand has passed in (pointed to by ErrMsg), you need to copy the string character by character from your local copy (a pointer to which is returned by InetGetErrorMessage(testError->errorCode)) into the memory pointed to by ErrMsg. In order to save you writing a loop to copy each character from one character array to the other, the typical method is to use the library function strcpy. However, you can also use the CVI specific function Fmt (though it may be better to use strcpy since it is part of the ANSI standard C language and more C programmers are familiar with it).

--Peter
0 Kudos
Message 7 of 8
(4,801 Views)
Thank you for the detailed explanation!

Louis
0 Kudos
Message 8 of 8
(4,796 Views)