Score:-2

I need help connecting serial ports to Ubuntu in WSL

vu flag

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.

HuHa avatar
es flag
Connect what ports to what? You need to be more specific. That's essential in programming software.
HuHa avatar
es flag
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.
pl flag
It's not 16.04. It's Ubuntu on WSL running this https://github.com/Active8Robots/AR10
NotTheDr01ds avatar
vn flag
Welcome to Ask Ubuntu! Please read why we ask that you [not post text as images](https://meta.stackoverflow.com/a/285557/11810933). 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!
Score:4
pl flag

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.

Score:0
vn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.