How to do serial communication in c program? -
How to access serial ports using the VC ++ compiler, the biosom function can be used in tollbo c is.
You have to open the appropriate com-device CreateFile is your needs Analog
// communication connection minus handle * comHandle; // port parameter, port index signed on its own needs; Unsigned bodwright; Unsigned data bits; Parity equality; Unsigned close bits; Bull hand int readIntervalTimeout; Int readTotalTimeoutMultiplier; Int readTotalTimeoutConstant; Int writtenTTTimeTimeMultiPlayer; Int ReadLatetime Constant; DCB DCB; Commimats whistle; // Create COM-device name string characters comDevice [20]; Sprintf (comDevice, "\\\\. \ COM COM% d", Port Index); // Open Serial Port _ComHandle = Create File (comDevice, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); If (comHandle == INVALID_HANDLE_VALUE) {return false; } Ct.ReadIntervalTimeout = readIntervalTimeout; Ct.ReadTotalTimeoutMultiplier = readTotalTimeoutMultiplier; Ct.ReadTotalTimeoutConstant = readTotalTimeoutConstant; Ct.WriteTotalTimeoutMultiplier = WriteTatatetimeTimeMultiplair; Ct.WriteTotalTimeoutConstant = WriteStatetimeTient; If (GetCommstate (_comHandle, & amp; DCB)) {disconnect (); return false; } Dcb.BaudRate = baudRate; Dcb.ByteSize = (BYTE) data bits; Dcb.Parity = (equality == none)? Noparity: ((equality == also)? EVENPARITY: ODDPARITY); Dcb.StopBits = (stopBits> 1)? TWOSTOPBITS: ONESTOPBIT; Dcb.fRtsControl = handshake? RTS_CONTROL_HANDSHAKE: RTS_CONTROL_ENABLE; Dcb.fOutxCtsFlow = handshake; Dcb.fOutxDsrFlow = handshake; Dcb.fDtrControl = handshake? DTR_CONTROL_HANDSHAKE: DTR_CONTROL_ENABLE; Dcb.fDsrSensitivity = handshake; Dcb.fOutX = FALSE; Dcb.fInX = FALSE; Dcb.fErrorChar = FALSE; Dcb.fNull = FALSE; Dcb.fAbortOnError = TRUE; Set the set port status (! SetCommState (_omHandle, & DCB) ||! SetCommTimeouts (comHandle, & amp; ct) ||! SetupCom (Commodity, 64, 64) ||! Purgcom (Commahndal, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)) {disconnect (); return false; } Read the appropriate MSDN entries for different tasks. Besides, I have omitted the disconnect method for short reasons.
Comments
Post a Comment