0) 在Windows7终端32轨道下工作,安装了Llinusb-win32级过滤器1.2.6.0。
(1) 我尝试了利布斯布特网的示例,并在结果之后学习。
2) After that i am trying to read (polling) example of libusb but got error on line "ec = reader.Read(readBuffer, 1000, out bytesRead);" and error is "win32error:no more byte!" [Please see code (2-Code) ]
What is this error means and how can i solve it? Actually i am new in usb device communication, please help me if have any idea to usb device communication using c#
页: 1
Length:18 DescriptorType:Device BcdUsb:0x0110 Class:Comm SubClass:0x00 Protocol:0x00 MaxPacketSize0:64 VendorID:0x11CA ProductID:0x0241 BcdDevice:0x0100 ManufacturerStringIndex:1 ProductStringIndex:2 SerialStringIndex:3 ConfigurationCount:1 ManufacturerString:VeriFone Inc ProductString:Trident USB Device 1.1 SerialString:
Length:9 DescriptorType:Configuration TotalLength:67 InterfaceCount:2 ConfigID:1 StringIndex:0 Attributes:0xC0 MaxPower:25 ConfigString:
Length:7 DescriptorType:Endpoint EndpointID:0x85 Attributes:0x03 MaxPacketSize:16 Interval:0 Refresh:0 SynchAddress:0x00
Length:9 DescriptorType:Interface InterfaceID:1 AlternateID:0 EndpointCount:2 Class:Data SubClass:0x00 Protocol:0x00 StringIndex:0 InterfaceString:
Length:7 DescriptorType:Endpoint EndpointID:0x81 Attributes:0x02 MaxPacketSize:64 Interval:0 Refresh:0 SynchAddress:0x00
Length:7 DescriptorType:Endpoint EndpointID:0x03 Attributes:0x02 MaxPacketSize:32 Interval:0 Refresh:0 SynchAddress:0x00
《刑法》:
public static UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(4554, 577);
ErrorCode ec = ErrorCode.None;
try
{
// Find and open the usb device.
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
// If the device is open and ready
if (MyUsbDevice == null) throw new Exception("Device Not Found.");
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// This is a "whole" USB device. Before it can be used,
// the desired configuration and interface must be selected.
// Select config #1
wholeUsbDevice.SetConfiguration(1);
// Claim interface #0.
wholeUsbDevice.ClaimInterface(0);
}
// open read endpoint 1.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
byte[] readBuffer = new byte[1024];
while (ec == ErrorCode.None)
{
int bytesRead;
// If the device hasn t sent data in the last 5 seconds,
// a timeout error (ec = IoTimedOut) will occur.
ec = reader.Read(readBuffer, 5000, out bytesRead);
if (bytesRead == 0) throw new Exception(string.Format("{0}:No more bytes!", ec));
Console.WriteLine("{0} bytes read", bytesRead);
// Write that output to the console.
Console.Write(Encoding.Default.GetString(readBuffer, 0, bytesRead));
}
Console.WriteLine("
Done!
");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
finally
{
if (MyUsbDevice != null)
{
if (MyUsbDevice.IsOpen)
{
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Release interface #0.
wholeUsbDevice.ReleaseInterface(0);
}
MyUsbDevice.Close();
}
MyUsbDevice = null;
// Free usb resources
UsbDevice.Exit();
}
// Wait for user input..
Console.ReadKey();
}