PC Communication Driver
8/99
RS232 Communications Reference Manual
17
3.2.2 Code sample 1: instantiation of a driver object on the stack
#include “Commbase.h”
#include “Elnapi.h”
void SomeClass::SomeFunction()
{
unsigned char pbyTxMsg[64];
unsigned char pbyRxMsg[64];
int nTxLength;
int nRxLength;
long lRet;
CElnApi CommDriver(
“COM2”,
// Connect driver to com2.
5000,
// 5 sec. timeout.
5,
// 5 retries.
2000);
// 2 sec. delay between retries.
lRet = CommDriver.SetUpPort(
9600,
// 9600 baud.
FALSE, // No parity.
8,
// 8 data bits.
1);
// 1 stop bit.
if(lRet)
{
// Error handling goes here.
}
sprintf(pbyTxMsg, “My dog has fleas.”)
lRet = CommDriver.OpenPort();
if(lRet)
{
/*
Error handling goes here. Chances are another application has locked
out access to the port.
*/
}
lRet = CommDriver.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)
continued next page
Summary of Contents for RS-232
Page 12: ...Overview 2 RS232 Communications Reference Manual 8 99 ...
Page 24: ...Protocol Description 14 RS232 Communications Reference Manual 8 99 ...
Page 36: ...PC Communication Driver 26 RS232 Communications Reference Manual 8 99 ...
Page 143: ...Function Parameter Index Reference 8 99 RS232 Communications Reference Manual 133 ...
Page 150: ...Index 140 RS232 Communications Reference Manual 8 99 ...
Page 151: ......