Is there a single point in your application where you open & close VaComm? Normally, the VaComm.Open call is where the check should be added to see if the port can be opened and only if it could be opened succesfully, data can be read or written.
Yes, the port is open at program start and closed when ends. The port is used constantly while the program is running. The error does not occur on program state/port open.
No. These applications are 24/7 and most are in hardened cabinets. I have had it occur here sitting at my desk.
Let's say the cause is undetermined. I am seeking a way to trap this error/exception and inform the user via our normal methods, not an exception dialog.
I do not know the meaning of the last post and we have strayed a bit.
Back to the original question.
The exception "Error retrieving statistics (5)" is not the same exception message when opening the port a second time: "Can't open the specified device \.\COM1 (Error 5, access denied).
While both are “access denied (5)” they seem to be different, as the message indicates.
Original question: "What causes this? And I do not see any way to trap it." First part; I still do not know what causes the exception, “Error retrieving statistics (5)”. Second part; the OnErrorException should at least catch the issue and prevent the crash.