2

I have just started on libusbdotnet. I have downloaded the sample code from http://libusbdotnet.sourceforge.net/V2/Index.html.

I am using a JetFlash 4GB Flash drive (a libusb-win32 filter driver was added for this drive).

The ShowInfo code works perfectly, and I can see my device info with two endpoints. Following is the device info from pastebin

http://pastebin.com/2Jdph6bY

However, the ReadOnly sample code does not work.

http://pastebin.com/hNZaEt8N

My code is almost same as that from the libsubdotnet website. I have only changed the endpoint that UsbEndpointReader uses. I have changed it from Ep01 to Ep02, because I read that the first endpoint is a control endpoint used for configuration, access control and similar stuff.

UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);

I always get the message "No more bytes!".

I thought that this is because of the absence of data, so I used the ReadWrite sample code.

http://pastebin.com/NiN5w9Jt

But here I also get "No more bytes!" message.

Interestly, the line

ec = writer.Write(Encoding.Default.GetBytes(cmdLine), 2000, out bytesWritten);

executes without errors.

Can pen drives be used for read write operations? Or is something wrong with the code?

Shuaib
  • 779
  • 2
  • 13
  • 47

1 Answers1

1

A USB thumb drive implements the USB mass storage device class, which is a subset of SCSI. The specification is here.

You're not going to get anything sensible by just reading from an endpoint - you have to send the appropriate commands to get any response.

You have not chosen an easy device class to begin your exploration of USB - you may be better starting with something easier - a HID class device, perhaps (Mouse/Keyboard) though Windows does have enhanced security around mice and keyboards which may prevent you installing a filter.

If you meddle with the filesystem on the USB stick while it's mounted as a drive by Windows, you'll almost certainly run into cache-consistency problems, unless you're extremely careful about what kind of access you allow Windows to do.

Will Dean
  • 39,055
  • 11
  • 90
  • 118
  • The libusbdotnet library does not recognize any usb devices (mouse, cellphone, flash drive) **UNLESS** I install a libusb win32 filter driver. I am worried my default driver will be corrupted if I install a filter driver over it, so I am not yet experimenting with a mouse. **I just want to test if read/write is OK, what device should I use?** – Shuaib Dec 01 '13 at 03:43
  • A filter driver is installed by a registry entry, which would be restored if you deleted the device in device manager and re-detected it. So you should not worry too much about experimenting. Do you have a USB-serial adaptor? You could perhaps experiment with that, though the protocol may not be easy to find docs for. HID has got to be easiest to start with, though. – Will Dean Dec 01 '13 at 08:15