0

I have implemented a solution as per this here example where I listen to serial port changes. Normally this worked good but recently I have started stress testing the application and noticed that in certain situations this does not work.

Situation 1:

I have no serial ports. Nothing is connected. The code fails at the deviceAttachWatcher.Start();. So this is the first point where the code should start listening for changes. The error message is NotSupported. If I look in EventViewer under Applications and Services Logs/Microsoft/Windows/WMI-Activity/Operation I can find an entry with following message:

Id = {00000000-0000-0000-0000-000000000000}; ClientMachine = xyz; User = DOMAIN\user.name; ClientProcessId = 16548; Component = Unknown; Operation = Start IWbemServices::ExecNotificationQuery - root\WMI : select * from __InstanceCreationEvent within 1 where TargetInstance ISA 'MSSerial_PortName'; ResultCode = 0x80041032; PossibleCause = Unknown

Situation 2:

I have one serial port. The code does not fail at deviceAttachWatcher.Start();. It even goes through the second call deviceDetachWatcher.Start();. The application is not listening to changes on serial ports but if I connect or disconnect this device nothing happens. I get two entries in the Event Viewer.

  • Entry 1

Namespace = root\WMI; NotificationQuery = select * from __InstanceCreationEvent within 1 where TargetInstance ISA 'MSSerial_PortName'; UserName = DOMAIN\user.name; ClientProcessID = 20260, ClientMachine = xyz; PossibleCause = Temporary

  • Entry 2

Namespace = root\WMI; NotificationQuery = select * from __InstanceDeletionEvent within 1 where TargetInstance ISA 'MSSerial_PortName'; UserName = DOMAIN\user.name; ClientProcessID = 20260, ClientMachine = xyz; PossibleCause = Temporary

These two event entries correspond to my two queries.

Situation 3:

I have 2 serial ports connected. Code works as expected.

QUESTION

Obviously, I would like the situation 3 to be the constant. What is happening in situations 1 and 2? Why am I getting "NotSupported" error?

Initially I had this problem as well but I fixed it as per answer so now I do not get this log entry in the Event Viewer anymore(this one was under Windows Logs/System).

UPDATE

I just tested this on my colleagues machine and he has the same issue so environment as a problem is out.

Robert
  • 2,407
  • 1
  • 24
  • 35
  • There is a [doc page](https://learn.microsoft.com/en-us/troubleshoot/windows-client/system-management-components/wmi-activity-event-5858-logged-with-resultcode-0x80041032) for this mishap. Plug&play is never not a problem with serial ports, be sure that a program that uses the ports has closed them and use the "Safely remove hardware" tray icon before removing a device. – Hans Passant Nov 02 '21 at 08:57
  • I came across this page already and it doesn't help me. I have restarted the PC without any hardware connected so I expect that no other program was using the port once I started my application. – Robert Nov 02 '21 at 09:27

0 Answers0