如何讀取USB的EP1及EP2資料! |
尚未結案
|
chaojoe
一般會員 發表:1 回覆:5 積分:1 註冊:2009-03-11 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
chaojoe
一般會員 發表:1 回覆:5 積分:1 註冊:2009-03-11 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
chaojoe
一般會員 發表:1 回覆:5 積分:1 註冊:2009-03-11 發送簡訊給我 |
這是部份程式,會不會DevicePath指錯的可能!
void CUsbhidioc::PrepareForOverlappedTransfer() { //Get another handle to the device for the overlapped ReadFiles. ReadHandle=CreateFile (detailData->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); //Get an event object for the overlapped structure. /*API function: CreateEvent Requires: Security attributes or Null Manual reset (true). Use ResetEvent to set the event object's state to non-signaled. Initial state (true = signaled) Event object name (optional) Returns: a handle to the event object */ if (hEventObject == 0) { hEventObject = CreateEvent (NULL, TRUE, TRUE, ""); //Set the members of the overlapped structure. HIDOverlapped.hEvent = hEventObject; HIDOverlapped.Offset = 0; HIDOverlapped.OffsetHigh = 0; } } bool CUsbhidioc::ReadReport(char InBuffer[]) { DWORD Result; //Read a report from the device. /*API call:ReadFile 'Returns: the report in InputReport. 'Requires: a device handle returned by CreateFile '(for overlapped I/O, CreateFile must be called with FILE_FLAG_OVERLAPPED), 'the Input report length in bytes returned by HidP_GetCaps, 'and an overlapped structure whose hEvent member is set to an event object. */ if (DeviceDetected == false) FindTheHID (); if (DeviceDetected) { Result = ReadFile (ReadHandle, InputReport, 5,//65, //Capabilities.InputReportByteLength, 08Mar2005 - Capabilities call fails on WinXP &NumberOfBytesRead, (LPOVERLAPPED) &HIDOverlapped); /*API call:WaitForSingleObject 'Used with overlapped ReadFile. 'Returns when ReadFile has received the requested amount of data or on timeout. 'Requires an event object created with CreateEvent 'and a timeout value in milliseconds. */ Result = WaitForSingleObject (hEventObject, 1000); switch (Result) { case WAIT_OBJECT_0: { break; } case WAIT_TIMEOUT: { //Cancel the Read operation. /*API call: CancelIo Cancels the ReadFile Requires the device handle. Returns non-zero on success. */ Result = CancelIo(ReadHandle); //A timeout may mean that the device has been removed. //Close the device handles and set DeviceDetected = False //so the next access attempt will search for the device. CloseHandle(ReadHandle); CloseHandle(DeviceHandle); DeviceDetected = FALSE; break; } default: { break; } } // API call: ResetEvent // Sets the event object to non-signaled. // Requires a handle to the event object. // Returns non-zero on success. ResetEvent(hEventObject); // copy array to destination buffer, stripping off the report ID. unsigned int i; for (i=0; i < 5 /*Capabilities.InputReportByteLength*/; i) InBuffer[i] = InputReport [i 1]; Result = true; } else // could not find the device Result = false; return Result; } |
chaojoe
一般會員 發表:1 回覆:5 積分:1 註冊:2009-03-11 發送簡訊給我 |
我找了一下發現很有可能&NumberOfBytesRead這個有問題,每次讀EP2的時候這個值都是"0",但EP1就是正常的數值!
會不會我Fireware連續宣告兩個中斷型IN_Read在HID情況下是有問題的。 Result = ReadFile (ReadHandle, InputReport, 5,//65, //Capabilities.InputReportByteLength, 08Mar2005 - Capabilities call fails on WinXP &NumberOfBytesRead, (LPOVERLAPPED) &HIDOverlapped); ===================引 用 chaojoe 文 章=================== 這是部份程式,會不會DevicePath指錯的可能! void CUsbhidioc::PrepareForOverlappedTransfer() { //Get another handle to the device for the overlapped ReadFiles. ReadHandle=CreateFile (detailData->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); //Get an event object for the overlapped structure. /*API function: CreateEvent Requires: Security attributes or Null Manual reset (true). Use ResetEvent to set the event object's state to non-signaled. Initial state (true = signaled) Event object name (optional) Returns: a handle to the event object */ if (hEventObject == 0) { hEventObject = CreateEvent (NULL, TRUE, TRUE, ""); //Set the members of the overlapped structure. HIDOverlapped.hEvent = hEventObject; HIDOverlapped.Offset = 0; HIDOverlapped.OffsetHigh = 0; } } bool CUsbhidioc::ReadReport(char InBuffer[]) { DWORD Result; //Read a report from the device. /*API call:ReadFile 'Returns: the report in InputReport. 'Requires: a device handle returned by CreateFile '(for overlapped I/O, CreateFile must be called with FILE_FLAG_OVERLAPPED), 'the Input report length in bytes returned by HidP_GetCaps, 'and an overlapped structure whose hEvent member is set to an event object. */ if (DeviceDetected == false) FindTheHID (); if (DeviceDetected) { Result = ReadFile (ReadHandle, InputReport, 5,//65, //Capabilities.InputReportByteLength, 08Mar2005 - Capabilities call fails on WinXP &NumberOfBytesRead, (LPOVERLAPPED) &HIDOverlapped); ? /*API call:WaitForSingleObject 'Used with overlapped ReadFile. 'Returns when ReadFile has received the requested amount of data or on timeout. 'Requires an event object created with CreateEvent 'and a timeout value in milliseconds. */ Result = WaitForSingleObject (hEventObject, 1000); switch (Result) { case WAIT_OBJECT_0: { break; } case WAIT_TIMEOUT: { //Cancel the Read operation. /*API call: CancelIo Cancels the ReadFile Requires the device handle. Returns non-zero on success. */ Result = CancelIo(ReadHandle); //A timeout may mean that the device has been removed. //Close the device handles and set DeviceDetected = False //so the next access attempt will search for the device. CloseHandle(ReadHandle); CloseHandle(DeviceHandle); DeviceDetected = FALSE; break; } default: { break; } } // API call: ResetEvent // Sets the event object to non-signaled. // Requires a handle to the event object. // Returns non-zero on success. ResetEvent(hEventObject); // copy array to destination buffer, stripping off the report ID. unsigned int i; for (i=0; i < 5 /*Capabilities.InputReportByteLength*/; i) InBuffer[i] = InputReport [i 1]; Result = true; } else // could not find the device Result = false; return Result; } |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
chaojoe
一般會員 發表:1 回覆:5 積分:1 註冊:2009-03-11 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
chaojoe
一般會員 發表:1 回覆:5 積分:1 註冊:2009-03-11 發送簡訊給我 |
我endpoint 1及endpoint 2 都是抓取ReadHandle這會發生什麼問題嗎!
ReadHandle=CreateFile (detailData->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,// FILE_FLAG_OVERLAPPED, NULL); ===================引 用 taishyang 文 章=================== 個人推測你的handle取錯了,你該不會跟另外一個endpoint用同一個handle讀資料吧? |
HUNK999
初階會員 發表:9 回覆:35 積分:28 註冊:2009-07-23 發送簡訊給我 |
程式後面加入 --> int ErrorCode = GetLastError(); 用單步執行 , Check ErrorCode , 看看問題出在哪? ErrorCode List: http://blog.csdn.net/psongchao/archive/2007/04/04/1551594.aspx http://sites.google.com/site/hidlibrary/ ===================引 用 chaojoe 文 章=================== 我endpoint 1及endpoint 2 都是抓取ReadHandle這會發生什麼問題嗎! ReadHandle=CreateFile (detailData->DevicePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,// FILE_FLAG_OVERLAPPED, NULL); ===================引 用 taishyang 文 章=================== 個人推測你的handle取錯了,你該不會跟另外一個endpoint用同一個handle讀資料吧?
編輯記錄
HUNK999 重新編輯於 2009-08-14 14:36:28, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |