07-08-2013 07:38 AM
Hi,
I'm trying to pass data via a TCP Callback function to teststand using the TCP steptype that I downloaded from Ni.
When I open a connection, container data is passed to the dll on which it creates a connection, the dll in part creates a TCP Callback function.
The handle obtained from the connection is then passed back through the container data, and the dll returns back to the sequence editor which will execute the next steps.
The problem is that when the TCP Callback function gets an TCP_READY event it can not pass data to TestStand because it can not access the container data.
How can this TCP Callback function pass/alter data to/in Testand?
Thank you...
07-12-2013 06:33 AM
Hello Mo77,
Is it possible to share example code from this test?
If I understand correclty, then you just want to be able to send data back from the DLL towards TestStand, right?
Thanks in advance for your feedback!
07-15-2013 03:48 AM
Yes ThiCop,
That's exactly what I want to establish!
Here is the example code:
//Function needed by the TCP functions
int CVICALLBACK MsgHandler (unsigned handle, int event, int error, void *callbackData)
{
char receiveBuf[256] = {0};
char displayBuf[7] = {0};
char * tempLookup;
int dataSize = sizeof (receiveBuf) - 1;
switch (event)
{
case TCP_CONNECT:
break;
case TCP_DISCONNECT:
break;
case TCP_DATAREADY:
if ((dataSize = ClientTCPRead (handle, receiveBuf, dataSize, 1000)) > 0)
{
// Send data from receiveBuf to a variable in teststand ????
// TS_PropertyGetValString (HandleObject, NULL, "Step.Result.Data", 0, &tempLookup);
// TS_PropertySetValString (HandleObject, NULL, tempLookup, 0, receiveBuf);
}
else
{
receiveBuf[dataSize] = '\0';
}
break;
}
return 0;
}
void __declspec(dllexport) TX_TEST TCPConnectF(tTestData * testData, tTestError * testError)
{
int error = 0;
int TCPerror;
double Port;
double Timeout;
char *HandleLookup;
char *ServerAdd;
char *CallbackData;
ErrMsg errMsg = {'\0'};
ERRORINFO errorInfo;
tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.Handle", 0, &HandleLookup));
tsErrChk (TS_PropertyGetValNumber (testData->seqContextCVI, &errorInfo, "Step.Result.Port", 0, &Port));
tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.IP", 0, &ServerAdd));
tsErrChk (TS_PropertyGetValNumber (testData->seqContextCVI, &errorInfo, "Step.Result.Timeout", 0, &Timeout));
tsErrChk (TS_PropertyGetValString (testData->seqContextCVI, &errorInfo, "Step.Result.Data", 0, &CallbackData));
TCPerror = ConnectToTCPServer (((unsigned int *) &ConnectionHandle), ((unsigned int) Port), ServerAdd, MsgHandler, 0, Timeout);
if (TCPerror != 0)
{
//Get TCP Error Message
sprintf(errMsg,"%s",GetTCPErrorString ( TCPerror ));
error = TCPerror;
goto Error;
}
tsErrChk (TS_PropertySetValNumber (testData->seqContextCVI, &errorInfo, HandleLookup, 0, ((double) ConnectionHandle)));
Error:
// FREE RESOURCES
CA_FreeMemory(HandleLookup);
CA_FreeMemory(ServerAdd);
// If an error occurred, set the error flag to cause a run-time error in TestStand.
if (error < 0)
{
testError->errorFlag = TRUE;
testError->errorCode = error;
testData->replaceStringFuncPtr(&testError->errorMessage, errMsg);
}
return;
}