Accessing COM port from WSL
|When WSL first came out, first thing I checked was COM port support. I think any IoT hacker would love to have COM port support from WSL, it gives all Linux tools on windows and access the boards.
If you haven’t used WSL, I highly recommend it. Its very easy to install. Just run the following command in power shell as admin then go to Microsoft store and pick the distribution you want and done. (You can install multiple distros as well)
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
We can access the COM ports (Serial interface) from WSL. Which means programs running in WSL can talk to the hardware. Like serial monitor tools, flashing tools etc. Mapping of the windows COM port to Linux tty is done automatically, COM<N> is mapped to ttyS<N>, for example for COM5 the device name in WSL would be /dev/ttyS5.
how to i connect python in wsl bash to window com port 3.
please give example code and procedure
Hi, I think following should work
import serial
ser = serial.Serial('/dev/ttyS3') # open serial port
print(ser.name) # check which port was really used
ser.write(b'hello') # write a string
s = ser.read(10)
ser.close()
I haven’t tested it though
hey! i cant access the port option in arduino ide in ubuntu 18.04. it is greyed. i tried all the solution present on internet but nothing worked . can you help?
which device you connected to system ?
I have tried getting access to the COM ports from a Linux container (which is supported by WSL), however I’m not able to see them listed under /dev. Could you verify if this should be possible?
Please note that WSL2 doesn’t have support for serial port yet
https://github.com/microsoft/WSL/issues/4322
I’m new to Linux on Windows. I installed Ubuntu and got bash working. I imported some scripts from a Raspberry pi to connect to my Icom IC-7300 transceiver.
The driver installs COMxx, in this case COM14. I don’t get /dev/ttyS14. However I get these
0 crw——- 1 root dialout 4, 64 Sep 9 15:01 /dev/ttyS0
0 crw——- 1 root dialout 4, 65 Sep 9 15:01 /dev/ttyS1
0 crw——- 1 root dialout 4, 66 Sep 9 15:01 /dev/ttyS2
0 crw——- 1 root dialout 4, 67 Sep 9 15:01 /dev/ttyS3
I chgrp’ed them because it was needed for the Pi.
When I try the script txcvr, it fails
{part of script}
DEV=/dev/ttyS0
(
stty raw 19200
case $1 in
“OFF”) echo -n -e “\xfe\xfe\x94\xe0\x18\x00\xfd” ;;
#Turn Txcvr OFF
:
:
sudo ./txcvr OFF
stty: ‘standard input’: Input/output error
./txcvr: line 11: echo: write error: Input/output error
Any ideas how to overcome this?
The Serial port that is installed when the Transceiver is plugged in:
Silicon Labs CP210x USB to UART Bridge COM14)
How can I write a bash script that gets the COM port on wsl to execute some commands specifing that port?
SErial port are I/O device. You want to write a command (ie a string? to a werial port?
cat “I command you, serial port” > /dev/ttyX
X is whatever serial port you need