Changes between Version 1 and Version 2 of Docs/Prog/Manual/ApplicationLibraries/lib825ev/ccomm
- Timestamp:
- 04/09/18 09:02:19 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Docs/Prog/Manual/ApplicationLibraries/lib825ev/ccomm
v1 v2 4 4 5 5 CComm 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 ====17 6 18 7 ==== Example ==== … … 22 11 // pComm is a pointer that can point to a CCommSerial, CCommClient, or CCommServer instance 23 12 24 if(commTypeSelection == SERIAL) 13 #define SERIAL 1 14 #define CLIENT 2 15 16 int commTypeSelection = CLIENT; 17 18 void StartCommunications(void) 25 19 { 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 36 40 } 37 41 38 pComm->Open(); 42 void StopCommunications(void) 43 { 44 if(pComm != NULL) 45 { 46 pComm->Close(); 47 delete pComm; 48 pComm = NULL; 49 } 50 } 39 51 40 // Now the app can call pComm->Send to send data without regard for whether it is serial or TCP/IP. 52 COMM_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 41 62 42 63 }}}