PC Communication Driver
8/99 RS232 Communications Reference Manual 19
Code sample 2: dynamic instantiation of one of two driver objects on the heap,
continued
{
// Error handling goes here.
}
sprintf(pbyTxMsg, “My dog has fleas.”)
lRet = pDriver->OpenPort();
if(lRet)
{
/*
Error handling goes here. Chances are another application has locked
out access to the port.
*/
}
lRet = pDriver->TransCeive( pbyTxMsg, // Outgoing message ptr.
pbyRxMsg, // Rx buffer.
17, // Outgoing msg length.
64, // Rx buffer size.
&nRxLength, // Actual length of Rx.
1); // Unit addr. 1.
if(lRet)
{
// Error handling goes here.
}
lRet = pDriver->ClosePort();
if(lRet)
{
// Error handling goes here.
}
if(pDriver)
delete pDriver; // Destroy the comm driver object.
}
3.2.4 Code sample 3: error handling
if(lRet)
{
if(lRet & ERR_RX_OVERRUN)
// Receive overrun error.
else if(lRet & ERR_LINK)
// Link error: bad CRC indicates garbled data.
else if(lRet & ERR_PHYSICAL)
// Physical error: timeout, baud rate, parity or framing.
else if(lRet & ERR_APPLICATION)