<pre id=code><font face=courier size= id=code>
To access the LPT or any COM port from C++ Builder, you need to use MFC functions.
DWORD
Errors,
dwdBytesSent,
dwdBytesRead;
COMSTAT
Status;
COMMTIMEOUTS
time_outs;
DCB
dcb;
char
chrSomeByte,
ptrSomeMultiBytePointer[400];
HANDLE PortHandle = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
GetCommState(PortHandle, &dcb);
SetupComm(PortHandle, 200, 200);
dcb.xxxx = xxxx;
/* Set dcb variables such as baud rate, stop bits, etc */
SetCommState(PortHandle, &dcb);
GetCommTimeouts(PortHandle, &time_outs);
time_outs.xxxx = xxxx;
/* Set comm timeouts for receive and transmit */
SetCommTimeouts(PortHandle, &time_outs);
PurgeComm(PortHandle, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
ClearCommError(PortHandle, &Errors, &Status);
ClearCommBreak(PortHandle);
/* Run a separte thread that writes to the port when it's not being read from if you need asynchronous (easy way to do it) */
WriteFile(PortHandle, &chrSomeByte, 1, &dwdBytesSent, NULL);
/* Run a separate thread that reads from the port when it's not being written to (easy way) */
ReadFile(PortHandle, ptrSomeMultiBytePointer, 200, &dwdBytesRead, NULL);
</font id=code></pre id=code>
Giovanni
---
http://www.y2ksw.com/vbulletin