Guest candyfeng Posted March 25, 2005 Report Posted March 25, 2005 I have writen a program running on smartphone to make use of the infrared port. I opened COM3 successfully (the IrCOMM is 3), but when I called WriteFile, the program was stalled, and seemed to be waiting for timeout, but it didn't return and I have to reset the phone. I don't know why since the same method works well on my Pocket PC. My smartphone is MPx220. Please help me, thanks!
Guest luti02 Posted April 10, 2005 Report Posted April 10, 2005 Hi Iam very interestic with irDA transmition, i have an MPX200 and i like make same electronic application and use irDA data transmition to sync. data. it's posibel to send me your programe to check it, and help you to analyse probleme!.
Guest candyfeng Posted April 21, 2005 Report Posted April 21, 2005 I am using eVC++4.0, and the codes are below. ////Find the IrCOMM port number void CCom::GetIrComm(short &sPort) { DWORD dwSize,dwType,dwData; HKEY hKey; if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,TEXT ("Drivers\\builtIn\\IrCOMM"),0,0,&hKey)==ERROR_SUCCESS) { dwSize=sizeof(dwData); if (RegQueryValueEx(hKey,TEXT("Index"),0,&dwType,(PBYTE)&dwData,&dwSize)==ERROR_SUCCESS) if(dwData<10) { sPort = dwData; } RegCloseKey(hKey); } } The port number I got is 3. Then I Open COM3 BOOL CIrdaPort::Open(UINT uiPort) { ASSERT(uiPort > 0 && uiPort <= 255); unsigned short strPort[255]; _stprintf(strPort,_T("COM%d:"), uiPort); m_hPort = CreateFile((LPCTSTR) strPort, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (m_hPort == INVALID_HANDLE_VALUE) { return FALSE; } // Set the size of the input and output buffer VERIFY(SetupComm(m_hPort, 2048, 2048)); // Terminates all outstanding read and write operations and clear the buffers VERIFY(PurgeComm(m_hPort, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)); // Reinitializes all IRDA port settings DCB dcb; dcb.DCBlength = sizeof(DCB); VERIFY(GetCommState(m_hPort, &dcb)); dcb.BaudRate = 19200; dcb.fBinary = TRUE; dcb.fParity = TRUE; dcb.fOutxCtsFlow = FALSE; dcb.fOutxDsrFlow = FALSE; dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fDsrSensitivity = FALSE; dcb.fTXContinueOnXoff = TRUE; dcb.fOutX = FALSE; dcb.fInX = FALSE; dcb.fErrorChar = FALSE; dcb.fNull = FALSE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.fAbortonerror = FALSE; dcb.ByteSize = 8; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; VERIFY(SetCommState(m_hPort, &dcb)); // Set the timeouts for all read and write operations COMMTIMEOUTS timeouts; VERIFY(GetCommTimeouts(m_hPort, &timeouts)); timeouts.ReadIntervalTimeout = 500; timeouts.ReadTotalTimeoutMultiplier = 5; timeouts.ReadTotalTimeoutConstant = 0; timeouts.WriteTotalTimeoutMultiplier = 100; timeouts.WriteTotalTimeoutConstant = 0; VERIFY(SetCommTimeouts(m_hPort, &timeouts)); return TRUE; } Then I send the data. //////Send data DWORD CIrdaPort::Write(BYTE *pData, DWORD dwCount) const { DWORD dwBytesWritten = 0; BOOL bR = WriteFile(m_hPort, pData, dwCount, &dwBytesWritten, NULL); return dwBytesWritten; } And the program blocked here.
Guest Gladers Posted May 10, 2005 Report Posted May 10, 2005 Has anyone compiled this as a dll and make it a simple API? ;)
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now