SimplySerial icon indicating copy to clipboard operation
SimplySerial copied to clipboard

Allow selection of com port from a list of available ports when starting.

Open fasteddy516 opened this issue 3 years ago • 4 comments

I almost always have multiple CircuitPython devices connected, which means I almost always have to run ss.exe with the -c command-line option to specify which device to connect to. If there is more than one com port available, SimplySerial should - by default - display a list of com ports and allow the user to choose which one to connect to.

fasteddy516 avatar Apr 04 '21 18:04 fasteddy516

Note that the auto-connect functionality will have to work in conjunction with this feature. The ONE option is straight-forward enough. The ANY option should probably display the connection list again if there is still more than one available device.

fasteddy516 avatar Apr 04 '21 18:04 fasteddy516

It would also be nice if this list would auto-update when new devices are connected. I'm not sure what options are available with regards to "listening" for new com ports. A polling-type operation is certainly possible, but far from ideal.

fasteddy516 avatar Apr 04 '21 18:04 fasteddy516

I came across your repo because someone I watch recently took an interest in it, and since serial communication is something I have some experience with, I thought I'd drop by to provide some info that you might find useful...

I'm not sure what options are available with regards to "listening" for new com ports.

You may find this old project of mine interesting/useful: https://github.com/Pharap/SimpleSerialCommunication

In particular, this class provides a means of watching for being notified of serial devices being connected and disconnected: https://github.com/Pharap/SimpleSerialCommunication/blob/master/SerialCommunication/DeviceChangeWatcher.cs

And its usage is demonstrated in the main file: https://github.com/Pharap/SimpleSerialCommunication/blob/master/SerialCommunication/Program.cs

This is done using the System.Management namespace, which leverages the 'Windows Management Instrumentation' (WMI) system. via WMI queries (which are essentially a variant of SQL). Honestly, WMI isn't a particularly well designed system, but it does the job.

Another alternative would be to use Win32 calls, but it depends how you feel about using unsafe code and marshalling/interop, and enumerating serial ports using Win32 is a bit more complicated anyway.

Pharap avatar May 05 '21 20:05 Pharap

That is excellent information, thank you for sharing! I will likely be looking into this in the very near future, and will see what I can manage. This application is literally the first .NET app I wrote after working through a "C# for beginners" book, and I've done depressingly little C#/.NET since then. The examples in your demo code - particularly with regards to utilizing events/handlers - are greatly appreciated.

fasteddy516 avatar May 07 '21 01:05 fasteddy516