Changes between Version 1 and Version 2 of Docs/Prog/Manual/ApplicationLibraries/lib825ev/ccomm


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

--

Legend:

Unmodified
Added
Removed
Modified
  • Docs/Prog/Manual/ApplicationLibraries/lib825ev/ccomm

    v1 v2  
    44
    55CComm is a C++ class that is provided to simplify 825 serial and ethernet operations. CComm is a base class for the inherited classes CCommSerial (serial ports), CCommClient (TCP/IP client), and CCommServer (TCP/IP Server).
    6 
    7 ==== Examples ====
    8 
    9 
    10 == Member Functions ==
    11 
    12 === Open ===
    13 Opens a specified file, or using the filename already stored in the object.
    14 
    15 
    16 ==== Remarks ====
    176
    187==== Example ====
     
    2211// pComm is a pointer that can point to a CCommSerial, CCommClient, or CCommServer instance
    2312
    24 if(commTypeSelection == SERIAL)
     13#define SERIAL 1
     14#define CLIENT 2
     15
     16int commTypeSelection = CLIENT;
     17
     18void StartCommunications(void)
    2519{
    26     int comport = 2;
    27     CCommSerial *pSerial = new CCommSerial(commPort);
    28     pComm = pSerial;
    29 }
    30 else if(commTypeSelection == CLIENT)
    31 {
    32     string svrIP = "192.168.1.25";
    33     int svrPort = 8001;
    34     CCommClient *pClient = new CCommClient(svrIP, svrPort);
    35     pComm = pClient;
     20   if(commTypeSelection == SERIAL)
     21   {
     22      int comport = 2;
     23      CCommSerial *pSerial = new CCommSerial(commPort);
     24      pComm = pSerial;
     25   }
     26   else if(commTypeSelection == CLIENT)
     27   {
     28      string svrIP = "192.168.1.25";
     29      int svrPort = 8001;
     30      CCommClient *pClient = new CCommClient(svrIP, svrPort);
     31      pComm = pClient;
     32   }
     33
     34   pComm->Open();
     35
     36   // Now the app can call pComm->Send to send data without regard for whether it is serial or TCP/IP.
     37
     38   pComm->AddRcvEvent(CHR_STX, CHR_ETX, CommEventDataMsg, 0, NULL);
     39
    3640}
    3741
    38 pComm->Open();
     42void StopCommunications(void)
     43{
     44   if(pComm != NULL)
     45   {
     46       pComm->Close();
     47       delete pComm;
     48       pComm = NULL;
     49   }
     50}
    3951
    40 // Now the app can call pComm->Send to send data without regard for whether it is serial or TCP/IP.
     52COMM_EVENT(DataMsg)
     53{
     54   uint8* buf = pConnection->GetRcvBuffer();
     55   buf[pConnection->GetRcvPos() - 1] = '\0';
     56
     57   printf("rcvd [%s]\r\n", buf);
     58
     59   return 0;
     60}
     61
    4162
    4263}}}