我想要讀取USB的裝置,有usb的Readfile的實際範例嗎? 謝謝大家!
如果您指的是USB的快閃碟或是數位相機的話,目前這些設備只要連上就會自動模擬成類似硬碟的裝置你可以直接讀取,如果您指的是印表機或是掃描器的話,情況比較複雜一些,不知道您想要哪方面的資料。
我手邊有一塊usb的手寫版,我想要讀取手寫版的資料,不知怎麼做,我己經可以讀到Vendor ID,Product ID及InputReportByteLength的長度但不知要怎麼用ReadFile的函式來讀取資料. 下面是我用ReadFile的範例,但是會出現"ByRef引數型態不符"的錯誤,為什麼呢? ------ Public Declare Function ReadFile _ Lib "kernel32" _ (ByVal hFile As Long, _ ByRef lpBuffer As Byte, _ ByVal nNumberOfBytesToRead As Long, _ ByRef lpNumberOfBytesRead As Long, _ ByRef lpOverlapped As OVERLAPPED) _ As Long ------ Private Sub Command3_Click() Dim ReadBuffer() As Byte Dim NumberOfBytesRead As Long ReDim ReadBuffer(Capabilities.InputReportByteLength - 1) '呼叫ReadFile函式 Result = ReadFile _ (HidDevice, ReadBuffer(0), CLng(Capabilities.InputReportByteLength), NumberOfBytesRead, 0)'錯誤後程式在最後面0的地方停止. End Sub
@@沒人回,各位大大都沒範例嗎?
最後一個參數的用法說明,給你參考: Points to an OVERLAPPED structure. This structure is required if hFile was created with FILE_FLAG_OVERLAPPED. If hFile was opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must not be NULL. It must point to a valid OVERLAPPED structure. If hFile was created with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the function can incorrectly report that the read operation is complete. If hFile was opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the read operation starts at the offset specified in the OVERLAPPED structure and ReadFile may return before the read operation has been completed. In this case, ReadFile returns FALSE and the GetLastError function returns ERROR_IO_PENDING. This allows the calling process to continue while the read operation finishes. The event specified in the OVERLAPPED structure is set to the signaled state upon completion of the read operation. If hFile was not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is NULL, the read operation starts at the current file position and ReadFile does not return until the operation has been completed. If hFile is not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the read operation starts at the offset specified in the OVERLAPPED structure. ReadFile does not return until the read operation has been completed.