I am working on a project which uses an I2C interface implemented using CP2112. This is written using Visual Studio in C#, running on Win10. This works well enough except when the interface is removed from the USB connector. At this point it is very likely that a read will be taking place. The code then gets stuck in a function from which it never returns. The module is "Application.cs" and is owned by Microsoft. The function is:
bool UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,
int reason, int pvLoopData)
This seems to be part of the Visual Studio suite. This is looking at messages and I imagine that the failure takes place because the USB entry that generates the messages no longer exists. This function then waits forever waiting for a message that will never arrive. This locks up the driver and the only recourse is to close the application, plug in the interface and restart. Note that this is not a detection issue but how to exit this loop.
I don't think I can help you to solve this problem, maybe someone from SiLabs can.
But it's possible you can work around it by starting this function in a thread and kill that thread when you detect the lock up. You might even be able to get a signal of the surprise removal.
Hope this helps
I had tried a thread abort but that does not work (and it is a little desperate). I think I will try the Visual Studio forums as the problem seems to be around their infrastructure.
Appreciate the input :-)