Version 1 (modified by 7 years ago) ( diff ) | ,
---|
Table of Contents
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; }
Note:
See TracWiki
for help on using the wiki.