Du kunne starte med:
#include <windows.h>
#include <iostream>
void SetTimeOut(HANDLE Port, int MSec)
{
COMMTIMEOUTS commtimeouts;
GetCommTimeouts(Port, &commtimeouts);
commtimeouts.ReadIntervalTimeout = MSec;
commtimeouts.ReadTotalTimeoutMultiplier = 1;
commtimeouts.ReadTotalTimeoutConstant = MSec;
SetCommTimeouts(Port, &commtimeouts);
}
int main()
{
DCB dcb;
HANDLE ComPort = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
GetCommState(ComPort, &dcb);
dcb.BaudRate = 115200;
dcb.ByteSize = 8;
dcb.fRtsControl = RTS_CONTROL_ENABLE;
dcb.fErrorChar = TRUE;
dcb.fParity = TRUE;
dcb.Parity = ODDPARITY;
dcb.fAbortOnError = TRUE;
dcb.fOutxCtsFlow = 1;
SetCommState(ComPort, &dcb);
SetTimeOut(ComPort, 50);
while(1)
{
char Buffer;
DWORD Length = 0;
DWORD ErrorType = 0;
ReadFile(ComPort, &Buffer, 1, &Length, 0);
ClearCommError(ComPort, &ErrorType, 0);
if(Length || ErrorType)
{
std::cout << ".";
}
}
}
Jeg har kontakten til at sidde mellem ben 2 og 7, dvs. mellem RTS og RX.