Beispiel #1
0
        public UsbDevice(LibUsb libusb, UsbDescriptor descriptor, int configuration, byte control_endpoint)
        {
            this.libusb           = libusb;
            this.descriptor       = descriptor;
            this.configuration    = configuration;
            this.control_endpoint = control_endpoint;
            var status = libusb.open(descriptor.device, out device_handle);

            if (status != 0)
            {
                throw new IOException($"libusb.open_device: {libusb.StrError(status)}");
            }
            status = libusb.get_configuration(device_handle, out var current_conf);
            if (status != 0)
            {
                libusb.close(device_handle);
                throw new IOException($"libusb.get_configuration: {libusb.StrError(status)}");
            }
            if (configuration != current_conf)
            {
                status = libusb.set_configuration(device_handle, configuration);
                if (status != 0)
                {
                    libusb.close(device_handle);
                    throw new IOException($"libusb.set_configuration: {libusb.StrError(status)}");
                }
            }
        }
Beispiel #2
0
 public UsbDevice Open(UsbDescriptor descriptor, int configuration, byte control_endpoint = 0x80)
 {
     return(new UsbDevice(libusb, descriptor, configuration, control_endpoint));
 }