| 1 | [[TOC]] |
| 2 | |
| 3 | = CCommSerial = |
| 4 | |
| 5 | CCommSerial is a C++ class that is provided to simplify 825 serial communications. CCommSerial 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 == SERIAL) |
| 21 | { |
| 22 | int commPort = 2; |
| 23 | CCommSerial *pSerial = new CCommSerial(commPort); |
| 24 | pComm = pSerial; |
| 25 | } |
| 26 | pComm->Open(); |
| 27 | |
| 28 | // Now the app can call pComm->Send to send data without regard for whether it is serial or TCP/IP. |
| 29 | |
| 30 | pComm->AddRcvEvent(CHR_STX, CHR_ETX, CommEventDataMsg, 0, NULL); |
| 31 | |
| 32 | } |
| 33 | |
| 34 | void StopCommunications(void) |
| 35 | { |
| 36 | if(pComm != NULL) |
| 37 | { |
| 38 | pComm->Close(); |
| 39 | delete pComm; |
| 40 | pComm = NULL; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | COMM_EVENT(DataMsg) |
| 45 | { |
| 46 | uint8* buf = pConnection->GetRcvBuffer(); |
| 47 | buf[pConnection->GetRcvPos() - 1] = '\0'; |
| 48 | |
| 49 | printf("rcvd [%s]\r\n", buf); |
| 50 | |
| 51 | if(buf[1] == 'T') // Received <STX>T<ETX> return timeval |
| 52 | { |
| 53 | time_t tmval; |
| 54 | time(&tmval); // Get timeval |
| 55 | |
| 56 | char response[12]; |
| 57 | sprintf(response, "%d\n", tmval); |
| 58 | // pConnection isn't important in the case of serial port, but if TCP/IP server it is important to send |
| 59 | // the response to the connection that the message was received from. |
| 60 | pComm->Send(pConnection, response, strlen(response); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | |
| 68 | }}} |