Example #1
0
        public int BulkTransfer(UsbTransferDirection direction, byte endpoint, UsbBuffer buffer, int timeout)
        {
            int transferred;

            LibUSBNative.ThrowIfError(LibUSBNative.libusb_bulk_transfer(handle, (byte)(endpoint | (byte)direction), buffer.AsPtr(), buffer.ByteLength, &transferred, (uint)timeout));
            return(transferred);
        }
Example #2
0
        public LibUSBProvider()
        {
            //Create the LibUSB instance
            LibUSBNative.ThrowIfError(LibUSBNative.libusb_init(ref ctx));

            //Create event thread
            eventThread              = new Thread(EventLoop);
            eventThread.Name         = "LibUSB Provider Event Loop";
            eventThread.IsBackground = true;
            eventThread.Start();
        }
Example #3
0
        public bool OpenDevice()
        {
            //If it's already opened, return true
            if (isOpened)
            {
                return(true);
            }

            //Request the device to be opened
            handle   = IntPtr.Zero;
            isOpened = LibUSBNative.libusb_open(device, ref handle) == 0;
            if (!isOpened)
            {
                return(false);
            }

            //Set config
            LibUSBNative.ThrowIfError(LibUSBNative.libusb_set_configuration(handle, 1));
            LibUSBNative.ThrowIfError(LibUSBNative.libusb_claim_interface(handle, 0));

            return(true);
        }
Example #4
0
 public void SubmitTransfer()
 {
     LibUSBNative.ThrowIfError(LibUSBNative.libusb_submit_transfer(transfer));
 }