Danh mục

USB Complete fourth- P40

Số trang: 10      Loại file: pdf      Dung lượng: 325.57 KB      Lượt xem: 1      Lượt tải: 0    
Thư Viện Số

Hỗ trợ phí lưu trữ khi tải xuống: 4,000 VND Tải xuống file đầy đủ (10 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

USB Complete fourth- P40:This book focuses on Windows programming for PCs, but other computersand operating systems also have USB support, including Linux and AppleComputer’s Macintosh. Some real-time kernels also support USB.
Nội dung trích xuất từ tài liệu:
USB Complete fourth- P40Chapter 14 &GVCKNU The WinUsb_WritePipe function accepts a pointer to a WinUSB handle, an endpoint address, a buffer with data to send, and the number of bytes to write. On success, the function returns True with the number of bytes written in bytesWritten. If the function uses overlapped I/O, the Overlapped parameter contains a pointer to an OVERLAPPED structure. To send data via an inter- rupt transfer, change myDevInfo.bulkOutPipe to myDevInfo.interruptOut- Pipe. To cause the driver to terminate transfers that are exact multiples of wMaxPack- etSize with Z L Ps , call W i n Us b _ S e t P i p e Po l i c y with SHORT_PACKET_TERMINATE = True. This option can be useful if the device firmware needs a way to identify the end of a transfer of unknown length.4GCFKPI &CVC XKC $WNM CPF +PVGTTWRV 6TCPUHGTU The WinUsb_ReadPipe function can read data via bulk or interrupt transfers.8$ Definitions _ Friend Shared Function WinUsb_ReadPipe _ (ByVal InterfaceHandle As IntPtr, _ ByVal PipeID As Byte, _ ByVal Buffer() As Byte, _ ByVal BufferLength As UInt32, _ ByRef LengthTransferred As UInt32, _ ByVal Overlapped As IntPtr) _ As Boolean End Function Use Dim buffer(63) As Byte Dim bytesRead As UInt32 Dim bytesToRead As UInt32 = 64 Dim success As Boolean366 Using WinUSB for Vendor-Defined Functions success = WinUsb_ReadPipe _ (myDevInfo.winUsbHandle, _ myDevInfo.bulkInPipe, _ buffer, _ bytesToRead, _ bytesRead, _ IntPtr.Zero)8% Definitions [DllImport(winusb.dll, SetLastError = true)] internal static extern Boolean WinUsb_ReadPipe (IntPtr InterfaceHandle, Byte PipeID, Byte[] Buffer, UInt32 BufferLength, ref UInt32 LengthTransferred, IntPtr Overlapped); Use Byte[] buffer = new Byte[ 64 ]; UInt32 bytesRead = 0; UInt32 bytesToRead = 64; Boolean success = false; success = WinUsb_ReadPipe (myDevInfo.winUsbHandle, myDevInfo.bulkInPipe, buffer, bytesToRead, ref bytesRead, IntPtr.Zero); &GVCKNU The WinUsb_ReadPipe function accepts a pointer to a WinUSB handle, an endpoint address, the buffer that will store the received data, and the maximum number of bytes to read. On success, the function returns True with the received data in the passed buffer and the number of bytes read in bytesRead. If the function uses overlapped I/O, the Overlapped parameter contains a pointer to an OVERLAPPED structure. To send data via an interrupt transfer, change bulkInPipe to interruptInPipe. The number of bytes read can depend on the policies set by WinUsb_SetPipePolicy. 367Chapter 147UKPI 8GPFQTFGHKPGF %QPVTQN 6TCPUHGTU Another option for transferring data is to use vendor-defined requests sent via control transfers directed to the interface.8$ Definitions Friend Structure WINUSB_SETUP_PACKET Friend RequestType As Byte Friend Request As Byte Friend Value As UShort Friend Index As UShort Friend Length As UShort End Structure _ Friend Shared Function WinUsb_ControlTransfer _ (ByVal InterfaceHandle As IntPtr, _ ByVal SetupPacket As WINUSB_SETUP_PACKET, _ ByVal Buffer() As Byte, _ ByVal BufferLength As UInt32, _ ByRef LengthTransferred As UInt32, _ ByVal Overlapped As IntPtr) _ As Boolean End Function Use Dim bytesReturned As UInt32 Dim dataStage(1) As Byte Dim setupPacket As WINUSB_SETUP_PACKET Dim success As Boolean Use this for a vendor-specific request to an interface with a device-to-host Data stage. setupPacket.RequestType = &HC1 Use this for a vendor-specific request to an interface with host-to-device Data stage: setupPacket.RequestType = &H41 The number that identifies the specific request. setupPacket.Request = 1368 Using WinUSB for Vendor-Defined Functions Vendor-defined values to send to the device. setupPacket.Index = 2 setupPacket.Value = 3 For control Write transfers (host-to-device Data stage), provide data for the Data stage. Example: dataStage(0) = 65 dataStage(1) = 66 The number of bytes in the requests Data stage. setupPacket.Length = Convert.ToUInt16(dataStage.Length) success = WinUsb_ControlTransfer _ (myDevInfo.winUsbHandle, _ setupPacket, _ dataStage, _ setupPacket.Length, _ bytesReturned, _ IntPtr.Zero)8% Definitions internal struct WINUSB_SETUP_PACKET { internal Byte RequestType; internal Byte Request; internal ushort Value; internal ushort Index; internal ushort Length; } [DllImport(winusb.dll, SetLastError = true)] internal static extern Boolean WinUsb_ControlTransfer (IntPtr InterfaceHandle, WINUSB_SETUP_PACKET SetupPacket, Byte[] Buffer, UInt32 BufferLength, ref UInt32 LengthTransferred, IntPtr Overlapped); 369Chapter 14 Use UInt32 by ...

Tài liệu được xem nhiều:

Tài liệu liên quan: