void COMinit(){ COMMTIMEOUTS CommTimeouts; hCom = CreateFile("COM1", GENERIC_READ | GENERIC_WRITE, 0, // comm devices must be opened w/exclusive-access NULL, // no security attrs OPEN_EXISTING, // comm devices must use OPEN_EXISTING 0, // not overlapped I/O NULL // hTemplate must be NULL for comm devices ); if (hCom == INVALID_HANDLE_VALUE) { dwError = GetLastError(); printf("COM1 konnte nicht geöffnet werden\n"); } // COM Einstellungen werden gelesen fSuccess = GetCommState(hCom, &dcb); if (!fSuccess) { printf("Kein Status\n"); } // COM Einstellungen werden geändert dcb.DCBlength = 28; // sizeof(DCB) dcb.BaudRate = CBR_9600; // Baudrate at which running dcb.fBinary = TRUE; // Binary Mode dcb.fParity = FALSE; // Disable parity checking dcb.fOutxCtsFlow = FALSE; // CTS handshaking on output FALSE dcb.fOutxDsrFlow = FALSE; // DSR handshaking on output dcb.fDtrControl = DTR_CONTROL_ENABLE; // DTR Flow control dcb.fDsrSensitivity = FALSE; // DSR Sensitivity dcb.fTXContinueOnXoff = TRUE; // Continue TX when Xoff sent dcb.fOutX = FALSE; // Disable output X-ON/X-OFF dcb.fInX = FALSE; // Disable input X-ON/X-OFF dcb.fErrorChar = FALSE; // Disable Err Replacement dcb.fNull = FALSE; // Disable Null stripping dcb.fRtsControl = RTS_CONTROL_ENABLE; // Rts Flow control dcb.fAbortOnError = TRUE; // Abort all reads and writes on Error dcb.XonLim = 2048; // Transmit X-ON threshold dcb.XoffLim = 512; // Transmit X-OFF threshold dcb.ByteSize = 8; // Number of bits/byte, 5-8 dcb.Parity = NOPARITY; //None,Odd,Even,Mark,Space dcb.StopBits = ONESTOPBIT; //1, 1.5, 2 dcb.XonChar = 17; // Tx and Rx X-ON character dcb.XoffChar = 19; // Tx and Rx X-OFF character dcb.ErrorChar = 0; // Error replacement char dcb.EofChar =0; // End of Input character dcb.EvtChar = 0; // Received Event character // COM Einstellungen werden geschrieben fSuccess = SetCommState(hCom, &dcb); GetCommTimeouts(hCom, &CommTimeouts); CommTimeouts.ReadIntervalTimeout = MAXDWORD; CommTimeouts.ReadTotalTimeoutMultiplier = 0; CommTimeouts.ReadTotalTimeoutConstant = 0; CommTimeouts.WriteTotalTimeoutMultiplier = 10; CommTimeouts.WriteTotalTimeoutConstant = 1000; if (FALSE == SetCommTimeouts(hCom, &CommTimeouts)){ printf("CommTimeouts konnten nicht gesetzt werden\n"); } if (!fSuccess) { printf("Status nicht geschrieben\n"); } }