Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding an active COM port from Ubuntu WSL (or probing the device registry from bash)

I want to programmatically discover the name of the serial port that a USB serial device is plugged into in Ubuntu WSL on Windows 10. For example, COM9 in Windows would correspond to /dev/ttyS9 in Ubuntu WSL.

From Windows 10,

  • The Device Manager shows the device in the GUI when manually searching through "Ports (COM & LPT)"
  • The Windows Command Prompt utility lists the active serial devices via the "reg query" command. Specifically,

reg query \HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM

So it seems like the way to do this would be to run the above query in a Bash-style command, assuming that the Windows registry is even visible to Ubuntu WSL. Is it?

Other dead-ends:

  • On a Linux machine, plugging in a USB device would put a message in /var/log/something (syslog?). On Ubuntu WSL, I don't see any logfile update from plugging in the device, which probably means the plug-in event is not being passed from Windows to Ubuntu WSL.
  • Looking at date/time on devices /dev/ttyS* via 'ls -l', there is no time update on the port where the USB device was plugged in.
  • Actually, there is an FTDI chip in the USB device. A rule could be put into '/etc/udev' if it was recognized, but I see no evidence that udev is supported.

Unexplored:

  • 'binfmt_misc' to run a Windows binary. Is this worth pursuing? Doesn't this have a kernel dependency? What does this mean when the kernel is actually the Windows kernel?
like image 974
Rick 0xfff Avatar asked Oct 20 '25 01:10

Rick 0xfff


1 Answers

If you have the correct Port/Serial drivers installed (check device manager), then run:

for tty in $(ls /dev/ttyS*); do stty -F $tty -a; done

Any recongnized device will not show ... Input/output error

like image 95
brucelsprouts Avatar answered Oct 22 '25 00:10

brucelsprouts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!