Esempio n. 1
0
        public static void Main(string[] args)
        {
            using (var context = new UsbContext())
            {
                context.SetDebugLevel(LogLevel.Info);

                //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);

                if (selectedDevice != null)
                {
                    Console.WriteLine("Found USB device in DFU mode...");

                    //Open the device
                    selectedDevice.TryOpen();

                    //Get the first config number of the interface
                    selectedDevice.ClaimInterface(selectedDevice.Configs[0].Interfaces[0].Number);

                    Console.WriteLine(GetDeviceInfo(selectedDevice));

                    dfu.SetUsb(selectedDevice);

                    //do DFU stuff!!!
                    try
                    {
                        dfu.ProgramFirmware(@"F:\nanobooter-nanoclr.dfu");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Failed!!! - {e}");
                    }
                }
                else
                {
                    Console.WriteLine("No USB device found!");
                }
            }
        }