beautypg.com

A n 9 3 – Silicon Laboratories SI2493/57/34/15/04 User Manual

Page 266

background image

A N 9 3

266

Rev. 1.3

}

// Build on the current configuration, and skip setting the size

// of the input and output buffers with SetupComm.

bSuccess = GetCommState(hCom, &dcb);

if (!bSuccess)

{

// Handle the error.

printf ("GetCommState failed with error %d.\n", GetLastError());

exit(1);

}

// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

dcb.fBinary = TRUE; // Binary mode; no EOF check

dcb.fOutxCtsFlow = FALSE; // No CTS output flow control

dcb.fOutxDsrFlow = FALSE; // No DSR output flow control

dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR flow control type

dcb.fDsrSensitivity = FALSE; // DSR sensitivity

dcb.fTXContinueOnXoff= TRUE; // XOFF continues Tx

dcb.fOutX = FALSE; // No XON/XOFF out flow control

dcb.fInX = FALSE; // No XON/XOFF in flow control

dcb.fErrorChar = FALSE; // Disable error replacement

dcb.fNull = FALSE; // Disable null stripping

dcb.fRtsControl = RTS_CONTROL_ENABLE; // assert RTS

dcb.fAbortOnError = FALSE; // Do not abort rds/wr on error

dcb.BaudRate = CBR_115200; // set the baud rate

dcb.ByteSize = 8; // data size, xmit, and rcv

dcb.Parity = NOPARITY; // no parity bit

dcb.StopBits = ONESTOPBIT; // one stop bit

bSuccess = SetCommState(hCom, &dcb);

if (!bSuccess)

{ // Handle the error.

printf ("SetCommState failed with error %d.\n", GetLastError());

exit(1);

}

printf ("Serial port %s successfully initialized.\n", pcCommPort);

return;

}

// -------------------------------------------------------------------------------

char *SendAndWaitFor(char *cpCommand, char *cpInBuffRd,

char *cpResponse, int iTimeoutMs)

{

unsigned long ulNoOfbytes;

strcpy(cpOutBuffer, cpCommand);

WriteFile(hCom, (long *)cpOutBuffer, strlen((char *)cpOutBuffer),

&ulNoOfbytes, 0);

if(iTimeoutMs)

This manual is related to the following products: