SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

LibUsbDotNet Write error

Last post 09-01-2008 5:33 PM by TimW. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 07-09-2008 9:21 PM

    • TimW
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 6

    LibUsbDotNet Write error

     Hello,

     I'm trying to write a Byte to the USB port but I keep getting the error -22 which is:  The operation is invalid given the current state of the device.

     Can someone help me solving this problem because I have no idea how to solve it.

    PS: I can read but not write data.

    Thanks in advance.

     ...// port setup like in the example

     int ret;

                closeDevice();

                mDevList = UsbGlobals.DeviceList;
                foreach (UsbDevice bus in mDevList)
                {
                    if (bus.Info.IdVendor == VENDOR_ID && bus.Info.IdProduct == PRODUCT_ID)
                    {
                        mDev = bus;
                        Console.WriteLine("VID" + mDev.Info.IdVendor + " == " + "PID" + mDev.Info.IdProduct);
                        mDev.Open();

                        Debug.Assert(mDev.SetConfiguration(1) == 0);
                        Debug.Assert(mDev.ClaimInterface(0) == 0);

                        mEpReader = mDev.OpenBulkEndpointReader(ReadEndpoints.Ep01);
                        mEpWriter = mDev.OpenBulkEndpointWriter(WriteEndpoints.Ep01);
                        mEpReader.DataReceivedEnabled = false;
                        

                    }
                }
            }

    .... // Here I try to write

    ret = mEpWriter.Write(buf,of,size,1000);


     

    Filed under:
  • 07-09-2008 9:25 PM In reply to

    • TimW
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 6

    Re: LibUsbDotNet Write error

     Never mind. I just solved the problem. The EndPoint address was incorrect.

     

    Thanks anyway ;)

  • 07-26-2008 10:02 PM In reply to

    Re: LibUsbDotNet Write error

    Hi TimW,

    I try, also to use it, have you got a sample or your source code is public and aviable ?

    I try , as yu to read/write with endpoint but cant find them in the lib/wrapper.

    Thank's by advance 

  • 07-28-2008 3:50 PM In reply to

    • TimW
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 6

    Re: LibUsbDotNet Write error

     Hello,

     You have to select the correct endpoints. I found the correct one by using a little program that gives you all the information you need. The program is called testlibusb-win.exe. After you run the program, connect the device and find the correct endpoint (HEX) for reading and writing.

    I have uploaded the program on: http://www.xmit.be/files/x86.zip 

    To open a usb port I used the following code.

     

            public void openDevice()
    {

    closeDevice();

    mDevList = UsbGlobals.DeviceList;
    foreach (UsbDevice bus in mDevList)
    {
    // Identification of Device
    if (bus.Info.IdVendor == VENDOR_ID && bus.Info.IdProduct == PRODUCT_ID)
    {
    mDev = bus;
    Console.WriteLine("Device: " + mDev.Info.ProductString + " - " + mDev.Info.ManufacturerString);
    mDev.Open();

    Debug.Assert(mDev.SetConfiguration(1) == 0);
    Debug.Assert(mDev.ClaimInterface(0) == 0);

    mEpReader = mDev.OpenBulkEndpointReader(ReadEndpoints.Ep01); // 0x81 thanks to program
    mEpWriter = mDev.OpenBulkEndpointWriter(WriteEndpoints.Ep03);// 0x03
    mEpReader.DataReceivedEnabled = false;
    }
    }
    }

    After opening the device you can read/write data by using the mEpReader.Read()/mEpReader.Write() methods. Choose your input buffer big enough otherwise you also will get an error.

    I hope this has helped you.

    Ps: The source code will become available on sourceForge as soon as I finish the program.

    With Kind Regards, Tim

  • 07-28-2008 4:21 PM In reply to

    Re: LibUsbDotNet Write error

     Hi timW, thank's

    In fact i have finded Ep, (2 and 4 for me) before your post, i write nice, in fact it display the bytes reded, but never read, with the integrated project "testbulk" i have sucefully read, but all the time the same response, delegate doesn't work and strangest thingh is the conect return error .

    Is libusbDotNet is the next generation of the Sharplibusb find here ?

    One is better or most complete ?

    Do you use it under Linux with succes ?

     

    Sorry for this lot of question but i'm in the dark and confuse , lol 

  • 07-28-2008 4:23 PM In reply to

    Re: LibUsbDotNet Write error

     Forget to re read, sorry :

     "In fact i have finded Ep, (2 and 4 for me) before your post, it write nice, in fact it display the bytes readed, but never read,

  • 08-14-2008 4:44 PM In reply to

    • TimW
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 6

    Re: LibUsbDotNet Write error

    My code is open source now. You can find it at: http://sourceforge.net/projects/xcom-hp Regards, Tim
  • 08-14-2008 8:29 PM In reply to

    Re: LibUsbDotNet Write error

    Well, i'm confuse, this link is  a tool who use USB transport, you are the author of libusb or libusbdotnet ?

    what is the differance with http://sourceforge.net/projects/libusbdotnet/ ?

     

  • 08-17-2008 1:17 PM In reply to

    • TimW
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 6

    Re: LibUsbDotNet Write error

    No, I'm not the author of libusbdotnet. The x-com hp program uses the libusbdotnet library. The program xcom-hp implements an xmodem protocol over usb what only available was for the com-port. The program I wrote is a program that enables you to transfer files to/from an hp-calculator. I just posted this link so you can look at my code, how I use the libusbdotnet library under GPL to help anyone who has problems using it. Greetings, Tim
  • 09-01-2008 3:32 PM In reply to

    Re: LibUsbDotNet Write error

     Hello TimW!

    I'm trying used your code how example for develop one aplications with USB, but I haven't had success. I'd like know if the libusbdotnet can to used with others devices USB and how can I find information about endpoints and the paramethers of method UsbDevice.IOControlMessage from libusbdotnet.

    Thanks advance.

  • 09-01-2008 5:33 PM In reply to

    • TimW
    • Not Ranked
    • Joined on 07-09-2008
    • Posts 6

    Re: LibUsbDotNet Write error

    Hello, http://libusbdotnet.sourceforge.net/ can be very helpfull. Also looking at the examples should help you to get started. If you use the devicenotify demo included when you download libusbdotnet you can use it to detect which endpoint is used with your device. Greetings, TimW
Page 1 of 1 (11 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.