WIN7
我已经编写了一个程序来打开串行端口并向其中写入数据,例如COM4。我连接了COM4和5以接收来自COM4的数据发送。但是我没有收到来自com4的任何数据。
HANDLE hCom = CreateFile(TEXT("COM4"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hCom == INVALID_HANDLE_VALUE) return false;
DCB CommDCB;
GetCommState(hCom, &CommDCB);
CommDCB.BaudRate = 19200;
CommDCB.Parity = EVENPARITY;
CommDCB.StopBits = ONESTOPBIT;
CommDCB.ByteSize = 8;
CommDCB.fBinary = 1;
CommDCB.fParity = 1;
CommDCB.fOutxCtsFlow = 0;
CommDCB.fOutxDsrFlow = 0;
CommDCB.fDtrControl = 0;
CommDCB.fDsrSensitivity = 0;
CommDCB.fTXContinueOnXoff = 0;
CommDCB.fOutX = 0;
CommDCB.fInX = 0;
CommDCB.fErrorChar = 0;
CommDCB.fNull = 0;
CommDCB.fRtsControl = RTS_CONTROL_TOGGLE;
CommDCB.fAbortOnError = 0;
SetCommState(hCom, &CommDCB);
SetupComm(hCom, 100, 100);
COMMTIMEOUTS CommTimeouts;
GetCommTimeouts(hCom, &CommTimeouts);
CommTimeouts.ReadIntervalTimeout = MAXDWORD;
CommTimeouts.ReadTotalTimeoutMultiplier = 0;
CommTimeouts.ReadTotalTimeoutConstant = 0;
SetCommTimeouts(hCom, &CommTimeouts);
ULONG32 dwWrite = 0UL;
write(hCom, &dwWrite, 4);