Здрасте!!! Вот решил поиграться с ИК-портом но возникли проблемы - ни чего прочитать не могу. вот так я пытаюсь прочитать
| Код | g_hIr = CreateFile(L"COM1:", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE == g_hIr) { MessageBox(NULL, L"Error: Can't open IR port", L"Information", MB_OK); return; } EscapeCommFunction(g_hIr, SETIR); DCB dcb; dcb.DCBlength = sizeof(DCB); GetCommState(g_hIr, &dcb);
dcb.BaudRate = CBR_9600; dcb.fBinary = TRUE; dcb.fParity = TRUE; dcb.fOutxCtsFlow = FALSE; dcb.fOutxDsrFlow = FALSE; dcb.fDtrControl = DTR_CONTROL_DISABLE; dcb.fDsrSensitivity = FALSE; dcb.fTXContinueOnXoff = FALSE; dcb.fOutX = FALSE; dcb.fInX = FALSE; dcb.fErrorChar = FALSE; dcb.fNull = FALSE; dcb.fRtsControl = RTS_CONTROL_DISABLE; dcb.fAbortOnError = FALSE; dcb.ByteSize = 8; dcb.Parity = EVENPARITY; dcb.StopBits = TWOSTOPBITS; if (! SetCommState(g_hIr, &dcb)) { MessageBox(hWnd, L"Unable to configure the serial port", L"Error", MB_OK); CloseHandle(g_hIr); }
COMMTIMEOUTS timeouts; GetCommTimeouts(g_hIr, &timeouts); timeouts.ReadIntervalTimeout = MAXDWORD; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.ReadTotalTimeoutConstant = 0; timeouts.WriteTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 0; if (! SetCommTimeouts(g_hIr, &timeouts)) { MessageBox(hWnd, L"Unable to set the time-out parameters", L"Error", MB_OK); CloseHandle(g_hIr); }
BYTE Byte; DWORD dwBytesTransferred, dwCommStatus;
SetCommMask (g_hIr, EV_RXCHAR | EV_CTS | EV_DSR | EV_RLSD | EV_RING); MessageBox(hWnd, L"Start Wait", L"Information", MB_OK);
WaitCommEvent (g_hIr, &dwCommStatus, 0);
if (dwCommStatus & EV_RXCHAR) { do { ReadFile (g_hIr, &Byte, 1, &dwBytesTransferred, 0); if (dwBytesTransferred == 1) MessageBox(hWnd, L"READ OK", L"Information", MB_OK); } while(1 == dwBytesTransferred); } CloseHandle(g_hIr);
|
по мимо этого не знаю какой порт открывать Подскажите знающие люди где собака зарыта |