public static void Main(string[] args)
{
ErrorCode ec = ErrorCode.None;
controllers = getControllers();
try
{
for (int i = 0; i < controllers.Length; i++)
{
if (controllers[i] == null) break;
UsbDevice controller = controllers[i]; // already opened
IUsbDevice device = controller as IUsbDevice;
device.SetConfiguration(1);
device.ClaimInterface(0);
}
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
finally // cleanup
{
for(int i = 0; i < controllers.Length; i++){
if (controllers[i] != null)
{
UsbDevice controller = controllers[i];
if (controller != null && controller.IsOpen)
{
IUsbDevice device = controller as IUsbDevice;
device.ReleaseInterface(0);
controller.Close();
}
}
}
UsbDevice.Exit();
Console.ReadKey();
}
}