Changes between Initial Version and Version 1 of Docs/Prog/Manual/ApplicationLibraries/lib825ev/Comm/CCommServer


Ignore:
Timestamp:
04/09/18 14:14:42 (7 years ago)
Author:
Don Wilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/Prog/Manual/ApplicationLibraries/lib825ev/Comm/CCommServer

    v1 v1  
     1[[TOC]]
     2
     3= CCommServer =
     4
     5CCommServer is a C++ class that is provided to simplify 825 TCP/IP server communications. CCommServer is inherited from the CComm base class.
     6
     7=== Constructor ===
     8
     9=== Member Functions ===
     10
     11
     12==== Description ====
     13
     14
     15
     16
     17==== Example ====
     18
     19{{{
     20   if(commTypeSelection == SERVER)
     21   {
     22      int svrPort = 8001;
     23      CCommServer *pServer = new CCommServer(svrPort);
     24      pComm = pClient;
     25   }
     26   pComm->Open();
     27
     28   pComm->AddRcvEvent(CHR_STX, CHR_ETX, CommEventDataMsg, 0, NULL);
     29
     30}
     31
     32void StopCommunications(void)
     33{
     34   if(pComm != NULL)
     35   {
     36       pComm->Close();
     37       delete pComm;
     38       pComm = NULL;
     39   }
     40}
     41
     42COMM_EVENT(DataMsg)
     43{
     44   uint8* buf = pConnection->GetRcvBuffer();
     45   buf[pConnection->GetRcvPos() - 1] = '\0';
     46
     47   printf("rcvd [%s]\r\n", buf);
     48
     49   if(buf[1] == 'T') // Received <STX>T<ETX> return timeval
     50   {
     51       time_t tmval;
     52       time(&tmval);  // Get timeval
     53
     54       char response[12];
     55       sprintf(response, "%d\n", tmval);
     56       // pConnection isn't important in the case of serial port, but if TCP/IP server it is important to send
     57       // the response to the connection that the message was received from.
     58       pComm->Send(pConnection, response, strlen(response);
     59    }
     60
     61
     62   return 0;
     63}
     64
     65
     66}}}