PC Communication Driver
Code sample 1: instantiation of a driver object on the stack, continued
{
// Error handling goes here.
}
lRet = CommDriver.ClosePort();
if(lRet)
{
// Error handling goes here.
}
}
3.2.3
Code sample 2: dynamic instantiation of one of two driver objects on the heap
#include "Commbase.h"
#include "Elnapi.h"
void SomeClass::SomeFunction()
{
unsigned char pbyTxMsg[64];
unsigned char pbyRxMsg[64];
int nTxLength;
int nRxLength;
long lRet;
CCommBase* pDriver;
// Dynamically instantiate an EL+N driver object.
pDriver = new CElnApi(
if(!pDriver)
{
// Error handling goes here.
}
/*
From this point on we don't care what kind of driver it is because
all driver objects that are derived from the CCommBase base class
have the same public API functions.
*/
lRet = pDriver->SetUpPort(
if(lRet)
18
"COM2", // Connect driver to com2.
5000,
// 5 sec. timeout.
5,
// 5 retries.
9600,
// 9600 baud.
FALSE,
// No parity.
8,
// 8 data bits.
1);
// 1 stop bit.
RS232 Communications Reference Manual
continued next page
8/99