| Version 1 (modified by , 8 years ago) ( diff ) |
|---|
Table of Contents
CCommSerial
CCommSerial is a C++ class that is provided to simplify 825 serial communications. CCommSerial is inherited from the CComm base class.
Constructor
Member Functions
Description
Example
if(commTypeSelection == SERIAL)
{
int commPort = 2;
CCommSerial *pSerial = new CCommSerial(commPort);
pComm = pSerial;
}
pComm->Open();
// Now the app can call pComm->Send to send data without regard for whether it is serial or TCP/IP.
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;
}
Note:
See TracWiki
for help on using the wiki.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/cardinal.gif)