Version 3 (modified by 7 years ago) ( diff ) | ,
---|
Table of Contents
CCommClient
CCommClient is a C++ class that is provided to simplify 825 TCP/IP client communications. CCommClient is inherited from the CComm base class.
Constructor
Member Functions
Description
Example
if(commTypeSelection == CLIENT) { string svrIP = "192.168.1.25"; int svrPort = 8001; CCommClient *pClient = new CCommClient(svrIP, 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
Note:
See TracWiki
for help on using the wiki.