0

I have attempted many ways of trying to connect the serial ports, but I'm not sure how as they all show input output error. The system does recognize something is connected as shown on the screenshots.

enter image description here

enter image description here

enter image description here

I have tried edit the coding to /dev/ttyS39 and 40 also /dev/ttyS29 and 30. I'm not sure how to get the ports to connect.

4
  • Connect what ports to what? You need to be more specific. That's essential in programming software.
    – HuHa
    Mar 28, 2023 at 16:35
  • If this is really about Ubuntu 16.04, be prepared to let the next moderator who sees that outdated and unsupported version close this. And since this is really a programming question, I am not sure if this is the appropriate forum.
    – HuHa
    Mar 28, 2023 at 16:37
  • It's not 16.04. It's Ubuntu on WSL running this github.com/Active8Robots/AR10
    – popey
    Mar 28, 2023 at 17:18
  • 1
    Welcome to Ask Ubuntu! Please read why we ask that you not post text as images. That's a common reason for downvotes on questions, and while I can't say for sure, may be the reason for the two downvotes you've received. Thanks! Mar 28, 2023 at 21:35

4 Answers 4

5

Serial ports on WSL get mapped from the Windows side (COM1 through COM4) to the Linux side as /dev/ttyS1 through /dev/ttyS4. It looks like you're using the COM4 name in your python. Use the Linux device name, which matches the Windows port number.

`COM1:` - `/dev/ttyS1`
`COM2:` - `/dev/ttyS2`
`COM3:` - `/dev/ttyS3`

etc.

1
  • Isn't that for WSL 1? WSL 2 lacks access to COM ports...
    – gavenkoa
    Mar 3 at 22:23
1

Spent around 2 hours finding how to do this. This is how I did it. In short, follow this: https://learn.microsoft.com/en-us/windows/wsl/connect-usb

My config: Windows 10/ WSL2 Steps:

  1. Open Powershell as admin
  2. Install usbip (follow link instructions)
  3. usbipd list
  4. Bind the usb to share usbipd bind --busid 2-7 (for me it was 2-7)
  5. Verify using usbip list that its shared
  6. Attach to wsl usbipd attach --wsl --busid 2-7

Screenshot to commands executed and output

New contributor
Shreyansh Saha is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

Accessing physical hardware under Windows Subsystem for Linux is tricky. You don't mention whether you are running WSL1 or WSL2 (you actually didn't mention WSL at all, but it's apparent from the screenshot, thanks to @popey for catching that and editing it into the question tags).

Under WSL2, you definitely don't have direct access to the serial ports inside Ubuntu. Keep in mind that Ubuntu is running inside a namespace container (similar to Docker and other container technologies) inside a managed virtual machine. "Managed" means that WSL itself handles the configuration of the virtual machine, so there's not much user control over it.

For USB, you do have a workaround in the form of USB/IP, but AFAIK this won't work for non-USB serial ports unless you attached a USB<->RS232 serial adapter. Even then, you'd possibly need to build support for it into the kernel.

Under WSL1, the situation may be better, but it will depend on the capabilities that you need. WSL1 works directly on Windows through a "syscall<->WinAPI translation layer", which means that it does have direct access to some hardware. That access, though, is limited to the syscalls that the Windows team has implemented. In many cases, this won't include calls to configure the interface.

If you are using WSL2 (the default), then I would recommend:

  • First see this thread for a mention of using CommTunnel (in Windows) with socat (in Linux) to tunnel the serial port traffic. That's not going to be easy, and it's not something I can help with - Perhaps a dedicated RoS forum might be the place to ask if you need assistance with that.

  • Or you might try to convert your Ubuntu distribution to WSL1. You can do this from PowerShell with:

wsl -l -v
# Confirm the <distro_name>
wsl --set-version <distro-name> 1

If that doesn't work, you'll probably want to use a virtual machine instead of WSL for this.

0

I was struggling with this myself using WSL2 and Ubuntu, but I beleive I found a work around.

The way I code and use VSC is to open WSL, CD to the folder I want and type 'code .' in the console. Windows opens up VSC and connect it to WSL and from there I use the built in bash terminal for NPM etc. Its much easier than figiting with Windows to get common development tools installed.

For the project I'm working on I need access to the Serial data as I'm working with UART and the Serial Monitor provided /dev/ttyS3 which in theory should have worked but as its been pointed out WSL2 doesn't have direct access to hardward. But it didn't.

What did work? I revealed the project path (shift+alt+r) which opens an Explorter window. My path is:

\\wsl.localhost\Ubuntu\root\dev\uart

I opened a new VSC window, then opened the path manually. Usually when I do this I get stuck with PowerShell for a terminal, but I was suprised to see that it has connected to WSL and I had bash. However, the Serial Monitor now showed COM ports and when I used ESP-Link, I was able to read the data.

Success!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .