wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/Comm/CCommServer

CCommServer

CCommServer is a C++ class that is provided to simplify 825 TCP/IP server communications. CCommServer is inherited from the CComm base class.

Constructor

Member Functions

Description

Example

   if(commTypeSelection == SERVER)
   {
      int svrPort = 8001;
      CCommServer *pServer = new CCommServer(svrPort);
      pComm = pClient;
   }
   pComm->Open();

   pComm->AddRcvEvent(CHR_STX, CHR_ETX, CommEventDataMsg, 0, NULL);

}

void StopCommunications(void)
{ 
   if(pComm != NULL)
   {
       pComm->Close();
       delete pComm;
       pComm = NULL;
   }
}

COMM_EVENT(DataMsg)
{
   uint8* buf = pConnection->GetRcvBuffer();
   buf[pConnection->GetRcvPos() - 1] = '\0';

   printf("rcvd [%s]\r\n", buf);

   if(buf[1] == 'T') // Received <STX>T<ETX> return timeval
   {
       time_t tmval;
       time(&tmval);  // Get timeval

       char response[12];
       sprintf(response, "%d\n", tmval);
       // pConnection isn't important in the case of serial port, but if TCP/IP server it is important to send
       // the response to the connection that the message was received from.
       pComm->Send(pConnection, response, strlen(response);
    }


   return 0;
}


See Also

Last modified 7 years ago Last modified on 04/12/18 12:39:33
Note: See TracWiki for help on using the wiki.