From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP Callback function passing data to teststand

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...

0 Kudos
Message 1 of 3
(3,403 Views)

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!

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
0 Kudos
Message 2 of 3
(3,359 Views)

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;   
}

0 Kudos
Message 3 of 3
(3,335 Views)