Author Topic: Usb communication  (Read 10059 times)

djsepddl

  • Member
  • ***
  • Posts: 2
Usb communication
« on: October 16, 2019, 09:25:40 pm »
hi Jan,
I am developing a tool with c# in the company.
We need to implement usb communication and are trying using the LibUsbDotNet library.
But we succeeded in recognizing usb, but we can't read/write.
I attach my source and log. What the hell is ClaimInterface?

Thanks in advance for your comments,
Regards,
Lee,

selectedDevice.ClaimInterface(selectedDevice.Configs[0].Interfaces[0].Number);

This error occurs in that statement.
LibUsbDotNet.LibUsb.UsbException: 'Access denied (insufficient permissions)'

Code: [Select]
    internal class ReadWrite
    {
        //Put your Product Id Here
        private const int ProductId = 0x572A;

        //Put your Vendor Id Here
        private const int VendorId = 0x0483;

        public static void Main(string[] args)
        {
            using (var context = new UsbContext())
            {
                //context.SetDebugLevel(LogLevel.Info);
                context.SetDebugLevel(LogLevel.Debug);

                //Get a list of all connected devices
                var usbDeviceCollection = context.List();

                //Narrow down the device by vendor and pid
                var selectedDevice = usbDeviceCollection.FirstOrDefault(d => d.ProductId == ProductId && d.VendorId == VendorId);

                //Open the device
                selectedDevice.Open();

                //Get the first config number of the interface
                selectedDevice.ClaimInterface(selectedDevice.Configs[0].Interfaces[0].Number);
                //Open up the endpoints
                var writeEndpoint = selectedDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
                var readEnpoint = selectedDevice.OpenEndpointReader(ReadEndpointID.Ep01);

                //Create a buffer with some data in it
                var buffer = new byte[512];
                buffer[0] = 0x20;
                buffer[1] = 0x01;
                buffer[2] = 0xAA;
                buffer[3] = 0x00;
                buffer[4] = 0x03;

                buffer[5] = 0x00;
                buffer[6] = 0x04;
                buffer[7] = 0x64;

                //Write three bytes
                writeEndpoint.Write(buffer, 3000, out var bytesWritten);

                var readBuffer = new byte[512];

                //Read some data
                var ret = readEnpoint.Read(readBuffer, 3000, out var readBytes);
                Console.WriteLine("{0}", ret.ToString());
            }
        }
    }

debugging log

[27.666000] [0000325c] libusb: error [auto_claim] could not auto-claim any interface
[27.666999] [0000325c] libusb: debug [usbi_remove_pollfd] remove fd 2
[27.666999] [0000325c] libusb: debug [libusb_free_transfer] transfer 0000028EFDA23508
[27.666999] [0000325c] libusb: debug [libusb_alloc_transfer] transfer 0000028EFDA23508
[27.668996] [0000325c] libusb: debug [libusb_submit_transfer] transfer 0000028EFDA23508
[27.669990] [0000325c] libusb: debug [usbi_add_pollfd] add fd 2 events 1
[27.669990] [0000325c] libusb: debug [libusb_claim_interface] interface 0
[27.670988] [0000325c] libusb: error [winusbx_claim_interface] could not access interface 0: [50] 지원되지 않는 요청입니다.
[27.671985] [0000325c] libusb: debug [libusb_claim_interface] interface 1
[27.671985] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 1 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.671985] [0000325c] libusb: debug [libusb_claim_interface] interface 2
[27.672983] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 2 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.672983] [0000325c] libusb: debug [libusb_claim_interface] interface 3
[27.672983] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 3 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.673980] [0000325c] libusb: debug [libusb_claim_interface] interface 4
[27.673980] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 4 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.673980] [0000325c] libusb: debug [libusb_claim_interface] interface 5
[27.674978] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 5 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.674978] [0000325c] libusb: debug [libusb_claim_interface] interface 6
[27.674978] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 6 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.675975] [0000325c] libusb: debug [libusb_claim_interface] interface 7
[27.675975] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 7 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.675975] [0000325c] libusb: debug [libusb_claim_interface] interface 8
[27.676972] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 8 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.678967] [0000325c] libusb: debug [libusb_claim_interface] interface 9
[27.679964] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 9 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.679964] [0000325c] libusb: debug [libusb_claim_interface] interface 10
[27.680961] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 10 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.680961] [0000325c] libusb: debug [libusb_claim_interface] interface 11
[27.681958] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 11 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.681958] [0000325c] libusb: debug [libusb_claim_interface] interface 12
[27.682956] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 12 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.682956] [0000325c] libusb: debug [libusb_claim_interface] interface 13
[27.683953] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 13 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.683953] [0000325c] libusb: debug [libusb_claim_interface] interface 14
[27.684951] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 14 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.684951] [0000325c] libusb: debug [libusb_claim_interface] interface 15
[27.685947] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 15 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.685947] [0000325c] libusb: debug [libusb_claim_interface] interface 16
[27.686945] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 16 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.686945] [0000325c] libusb: debug [libusb_claim_interface] interface 17
[27.689937] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 17 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.689937] [0000325c] libusb: debug [libusb_claim_interface] interface 18
[27.690944] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 18 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.690944] [0000325c] libusb: debug [libusb_claim_interface] interface 19
[27.691932] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 19 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.691932] [0000325c] libusb: debug [libusb_claim_interface] interface 20
[27.692929] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 20 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.692929] [0000325c] libusb: debug [libusb_claim_interface] interface 21
[27.693926] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 21 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.693926] [0000325c] libusb: debug [libusb_claim_interface] interface 22
[27.694923] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 22 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.694923] [0000325c] libusb: debug [libusb_claim_interface] interface 23
[27.694923] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 23 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.695920] [0000325c] libusb: debug [libusb_claim_interface] interface 24
[27.695920] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 24 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.696918] [0000325c] libusb: debug [libusb_claim_interface] interface 25
[27.696918] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 25 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.697915] [0000325c] libusb: debug [libusb_claim_interface] interface 26
[27.697915] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 26 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.699910] [0000325c] libusb: debug [libusb_claim_interface] interface 27
[27.699910] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 27 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.700913] [0000325c] libusb: debug [libusb_claim_interface] interface 28
[27.700913] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 28 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.701905] [0000325c] libusb: debug [libusb_claim_interface] interface 29
[27.701905] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 29 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.701905] [0000325c] libusb: debug [libusb_claim_interface] interface 30
[27.702902] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 30 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.703900] [0000325c] libusb: debug [libusb_claim_interface] interface 31
[27.703900] [0000325c] libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 31 with WinUSB): [50] 지원되지 않는 요청입니다.
[27.704897] [0000325c] libusb: error [auto_claim] could not auto-claim any interface
[27.704897] [0000325c] libusb: debug [usbi_remove_pollfd] remove fd 2
[27.705894] [0000325c] libusb: debug [libusb_free_transfer] transfer 0000028EFDA23508
[27.707889] [0000325c] libusb: debug [libusb_claim_interface] interface 0
[27.707889] [0000325c] libusb: error [winusbx_claim_interface] could not access interface 0: [50] 지원되지 않는 요청입니다.




Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Usb communication
« Reply #1 on: October 16, 2019, 10:29:01 pm »
I don't have experience with libusbdotnet so not sure if I can help much.

http://libusb.sourceforge.net/api-1.0/group__dev.html#ga32fabedf5f13fdecf1cb33acdb19b57a

What OS?

djsepddl

  • Member
  • ***
  • Posts: 2
Re: Usb communication
« Reply #2 on: October 17, 2019, 12:52:02 am »
i'm using Windows10 and vs2019

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Usb communication
« Reply #3 on: October 17, 2019, 11:47:51 am »
Kind of a shot in the dark, but you could try this and see if it makes a difference:

https://www.itechtics.com/run-programs-administrator/