PORTS Forum

Ports and Interfaces => Serial Ports => Topic started by: jmccabe on March 28, 2018, 05:08:30 pm

Title: Launch an app on windows when a COM Port becomes available?
Post by: jmccabe on March 28, 2018, 05:08:30 pm
I'm looking at the possibility of using an FTDI FT232 chip on-board some hardware so that, when it's plugged into a USB port, it will become available as a virtual COM port I'd really like this event to launch my own app on a Microsoft Windows system.

Does anyone know where I might find some information on how to cause the app to be launched? I've been searching, but most of the resources on Autoplay, for example, seem to be aimed at what to do when a USB mass storage device is connected.

Any pointers or advice gratefully appreciated.
John
Title: Re: Launch an app on windows when a COM Port becomes available?
Post by: Jan Axelson on March 28, 2018, 08:13:54 pm
Use WMI to detect device arrival:

https://msdn.microsoft.com/en-us/library/aa393964(v=vs.85).aspx

My example code (for HID but demonstrates use):

http://janaxelson.com/hidpage.htm#MyExampleCode

https://social.msdn.microsoft.com/Forums/vstudio/en-US/f3ebf6c4-4e93-48de-b4b5-ca85ab29a376/detect-if-serial-port-has-been-removerattached?forum=vbgeneral

In the routine that detects the arrival, launch the app.
Title: Re: Launch an app on windows when a COM Port becomes available?
Post by: jmccabe on March 29, 2018, 02:56:22 am
Thanks for those Jan. From a brief glance, it looks like the sort of stuff I'm looking for and has certainly given me help structuring a more useful Google query. I'll take a closer look at the links and see how it goes.

As an aside, the WDK link on your example page is dead.

Thanks again.
John
Title: Re: Launch an app on windows when a COM Port becomes available?
Post by: Jan Axelson on March 29, 2018, 12:43:59 pm
Thanks, will fix.
Title: Re: Launch an app on windows when a COM Port becomes available?
Post by: Renate on August 20, 2021, 06:48:39 am
You can also do this without WMI.
Use RegisterDeviceNotification, WM_DEVICECHANGE, DEV_BROADCAST_PORT

Edit: No, you don't have to register for port notifications, all top-level windows get that anyway.
(I've been registering for DEV_BROADCAST_DEVICEINTERFACE which you do need to do.)

I double-checked this by adding com ports to my UsbLog.exe
You can download that at http://www.temblast.com/windows.htm
Ok, I added volumes too (which you don't have to register to receive).