NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem transferring data from LabWindows/CVi to Test Stand

Hello

The example dll code is presented here, what it is doing is measuring the Ascii value of the 6th byte and then passing on the value to the Test Stand. I think it is something stupid on my part that I am not able to extract the data out of the byte and then convert it to byte and then pass onto Test Stand.
The process should be

Tx 16 bytes ------> Rx 24 bytes --------> Obtain desired byte( 6th in this particular case)----------> Transfer its Ascii value to a double (testmeasurement)------->Pass on that value of double to Test Stand.

I dont know where I am breaking the chain or if the chain is even wrong or there is another process of doing it. I am attaching the screen capture module from the function I am using in Test Stand. I am always getting the result to be a 0, no matter what I do. I am attaching the source code being used in this test to pass on the value. I have tried the code to work independently in the attached atest.prj but it is not working when i try to run it in Test Stand.


void __declspec(dllexport) __stdcall ADC_J3_1(double *measurement,
char reportText[1024], short *errorOccurred, long *errorCode, char errorMsg[1024])
{
int error = 0;
// ErrMsg errMsg = {'\0'};
// ERRORINFO errorInfo;

// REPLACE THE FOLLOWING WITH YOUR SPECIFIC TEST CODE
double testMeasurement = 5.0;
// double lowLimit;

char Rdbuf[23];
int i;

//--------------------------
// Write Data
//--------------------------
Wrtbuf[0]=0x41;
Wrtbuf[1]=0x02;
Wrtbuf[2]=0x00;
Wrtbuf[3]=0x00;
Wrtbuf[4]=0x00;
Wrtbuf[5]=0x00;
Wrtbuf[6]=0x00;
Wrtbuf[7]=0x00;
Wrtbuf[8]=0x00;
Wrtbuf[9]=0x00;
Wrtbuf[10]=0x00;
Wrtbuf[11]=0x00;
Wrtbuf[12]=0x00;
Wrtbuf[13]=0x00;
Wrtbuf[14]=chksum(Wrtbuf);
//Wrtbuf[15]=0x0D;
for (i=0; i<15; i++)
{
ComWrtByte (COMport,Wrtbuf[i]);
//DebugPrintf("%c",Wrtbuf[i]);
}
ComWrtByte (COMport,0x0D);
Delay(1);
//------------------------------
// Receive Data
//------------------------------

ComRd (COMport, Rdbuf, 24); // "Buf" is the string into which device response is stored

// Test lenght of response

if (strlen (Rdbuf) < 24) goto Error;
//TestResponse
//sprintf(&Rdbuf[6],"%s>%f",&testMeasurement);
//Scan(&Rdbuf[6],"%s>%f",&testMeasurement);
//Fmt(&Rdbuf[6], "%s>%f",testMeasurement);
//testMeasurement=Rdbuf[6];
//DebugPrintf("%x",Rdbuf[6]);
testMeasurement= strtod(&Rdbuf[6], NULL);

*measurement = testMeasurement;

// The following code shows how to access a property or variable via the TestStand ActiveX API
// To use this code you must add a parameter "CAObjHandle seqContextCVI" to this function and pass
// a sequence context to it.
// tsErrChk(TS_PropertyGetValNumber(seqContextCVI, &errorInfo,
// "Step.Limits.Low", 0, &lowLimit));

Error:
// FREE RESOURCES HERE

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

// OPTIONALLY SET THE ERROR CODE AND STRING
// *errorCode = error;
// strcpy(errorMsg, errMsg);
}
}
0 Kudos
Message 1 of 4
(3,501 Views)
Hi,

strtod() requires an const char[] but you are not providing that.

You could try copying Rdbuf[6] to a temporary char which has been declare

char tmpbuf[2] = "";

and do

tmpbuf[0] = Rdbuf[6];

before

testMeasurement= strtod(tmpbuf, NULL);

regards
Ray Farmer
Regards
Ray Farmer
0 Kudos
Message 2 of 4
(3,493 Views)
Congratulations Ray for your 1K post. Could you drop me an Email ?
Chilly Charly    (aka CC)
0 Kudos
Message 3 of 4
(3,482 Views)
The above code has some problems:

char tmpbuf[2] = "";

This declares an array of length 2 and initializes it to the empty string. In this case, tmpbuf[0] = '\0' and tmpbuf[1] is uninitialized.

So after you set:

tmpbuf[0] = Rdbuf[6];

you have to do:

tmpbuf[1] = '\0';

to make sure the string is NULL-terminated.

However, to answer the original poster's question, it looks like all he/she wants is simply to pass the value of the 6th byte back as ascii to TestStand (as all numbers in TestStand are stored as double). In this case, it should be a simple assignment:

*measurement = Rdbuf[6];

The C compiler will take care of converting the value of the character to a double. You can add a cast for clarity if you like, but the effect will be the same:

*measurement = (double)(Rdbuf[6]);



strtod actually converts a string to a double, for example something like this:

double myNumber = strtod("6.03", NULL);

This would store the value 6.03 in the floating point number myNumber.

--Peter
0 Kudos
Message 4 of 4
(3,457 Views)