I have been using LibUsbDotNet for a few years now and all of my development has been done on a W7 machine running (currently) VS2022. LibUsbDotNet provides the 'WinForms' end of my projects - the other ends are all AtTiny or AtMega microcontrollers using Objective Development's firmware-only USB driver VUSB. I have made an in-circuit programmer for Atmel devices, a controller and throttles for DCC trains and a system for controlling and monitoring my Electric Master Clock system. These all work fine including a bootloader interface to avoid having to plug my in-circuit programmer in every time I make a change to the microcontroller code
A problem arises when running the WinForms app under W10. If my USB device is connected before starting the WinForms app then all is well. If I start the WimForms app first and then plug in the USB device it is not detected (If I run the WinForms app on a W7 machine it all works fine and detects insertions/removals correctly). Worse, if the WinForms app is run in Debug mode, it crashes when the USB decide is plugged in (again, it's fine on a W7 machine)
What I have tried:
In order to simplify the problem I have made a very simple app which just detects insertions and removals and logs the result on a text box.
Code shown below :-
//********************
using LibUsbDotNet.DeviceNotify;
//***********************************************************************
namespace USB_Test
{
public partial class Form1 : Form
{
private readonly IDeviceNotifier UsbDeviceNotifier;
private readonly TextBox text_box;
public Form1()
{
Text = "USB test";
UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
text_box = new TextBox
{
Multiline = true,
ReadOnly = true,
Width = 200,
Height = 400,
Top = 20,
Left = 20
};
Controls.Add(text_box);
Width = 300;
Height = text_box.Bottom + 50;
}
//**************************************************************
private void OnDeviceNotifyEvent(object? sender, DeviceNotifyEventArgs e)
{
text_box.AppendText("\n");
text_box.AppendText(e.ToString()); // Dump the event info to output.
}
#endregion
}
//************************************************************
}
This works fine on W7 machine whether in debug or release mode. On W10 machine it just crashes in debug mode and appears to do nothing in release mode
Compiled with Net 6 and using V2.2.8 of LibUsbDotNet
Any ideas please ???
----------------
Error occurs in 'Main' :-
static void Main()
{
ApplicationConfiguration.Initialize();
Application.Run(new Form1()); <------ error here
}
Error shown as :-
System.OverflowException: 'Arithmetic operation resulted in an overflow.'
This exception was originally thrown at this call stack:
[External Code]
The error details show it occurred in LibUsbDotNet.DeviceNotify so I guess that is a dead-end as far as Windows is concerned and will have to get hold of the author ????
Thanks