Experience with LibUsbDotNet C# USB Library

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
MaMu
Posts: 3
Joined: Sat Sep 25, 2010 8:46 am

Experience with LibUsbDotNet C# USB Library

Post by MaMu » Sat Sep 25, 2010 8:56 pm

Hi,

Does anyone have experience with the LibUsbDotNet C# USB Library?

As hardware I’m using the power switch reference project on an Atmega328p. As V-USB version I’m using: vusb-20100715. When using the provided Windows command line tool my hardware works.

Now I’m trying to get the LibUsbDotNet C# USB Library to work, without success.

See: Support forum LibUsbDotNet C# USB Library

Does anyone have V-USB working in combination with the LibUsbDotNet C# USB Library?

MaMu

_frank26080115

Re: Experience with LibUsbDotNet C# USB Library

Post by _frank26080115 » Sun Sep 26, 2010 5:07 am

have you tried break-pointing right before "ControlTransfer" and examining the packet before it's sent?

I have great success using LibUsbDotNet, I have made an LCD display which uses control transfers for text, brightness, and contrast setting, when I did it, I always made sure that the values for bmRequestType and bRequest were valid, it sounds like you are just putting in values from textboxes, are the values valid?

why are you always explicitly casting the UsbDevice object to interfaces? why not just call methods on usbDevice?

MaMu
Posts: 3
Joined: Sat Sep 25, 2010 8:46 am

Re: Experience with LibUsbDotNet C# USB Library

Post by MaMu » Sun Sep 26, 2010 9:22 pm

_frank26080115 wrote:have you tried break-pointing right before "ControlTransfer" and examining the packet before it's sent?


Of course! The debugger is always good idea!

Because I built my own hardware I'm using an old laptop for testing. I'll install the lightweight debugger.

_frank26080115 wrote:I have great success using LibUsbDotNet, I have made an LCD display which uses control transfers for text, brightness, and contrast setting, when I did it, I always made sure that the values for bmRequestType and bRequest were valid, it sounds like you are just putting in values from textboxes, are the values valid?


After I couldn't get it to work I added the textboxes so I can easily experiment with different values.

_frank26080115 wrote:why are you always explicitly casting the UsbDevice object to interfaces? why not just call methods on usbDevice?


I got the code from the provided examples, I'll try without the cast.

_frank26080115

Re: Experience with LibUsbDotNet C# USB Library

Post by _frank26080115 » Sun Sep 26, 2010 10:18 pm

I'll install the lightweight debugger.


I meant: use the Visual Studio debugger

here's a bit from my own code

Code: Select all

public bool SetContrast(byte contrast)
        {
            if (IsConnected == false)
                return false;

            UsbSetupPacket packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor, (byte)RequestCommand.SetContrast, (short)contrast, 0, 0);
            int temp1;
            object temp2 = null;
            return MyUsbDevice.ControlTransfer(ref packet, temp2, 0, out temp1);
        }

MaMu
Posts: 3
Joined: Sat Sep 25, 2010 8:46 am

Re: Experience with LibUsbDotNet C# USB Library

Post by MaMu » Tue Sep 28, 2010 9:16 pm

IT WORKS!

_frank26080115 wrote:
here's a bit from my own code

Code: Select all

public bool SetContrast(byte contrast)
        {
            if (IsConnected == false)
                return false;

            UsbSetupPacket packet = new UsbSetupPacket((byte)UsbRequestType.TypeVendor, (byte)RequestCommand.SetContrast, (short)contrast, 0, 0);
            int temp1;
            object temp2 = null;
            return MyUsbDevice.ControlTransfer(ref packet, temp2, 0, out temp1);
        }


I removed the cast from the UsbDevice object and integrate your code snippet into my program. After a bit of experimenting with some values it worked.

Thanks a lot!

Post Reply