Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL1 ignores CTS/DSR input lines in serial ports #12396

Open
1 of 2 tasks
0wwafa opened this issue Dec 19, 2024 · 1 comment
Open
1 of 2 tasks

WSL1 ignores CTS/DSR input lines in serial ports #12396

0wwafa opened this issue Dec 19, 2024 · 1 comment

Comments

@0wwafa
Copy link

0wwafa commented Dec 19, 2024

Windows Version

Windows 10

WSL Version

WSL version: 2.3.24.0 Kernel version: 5.15.153.1-2 WSLg version: 1.0.65 MSRDC version: 1.2.5620 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.26100.1-240331-1435.ge-release Windows version: 10.0.19045.5073

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.153.1-2

Distro Version

Ubuntu 22.04

Other Software

WSL version: 2.3.24.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.19045.5073

Repro Steps

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <termios.h>

void print_status(int status) {
    printf("Status: ");
    if (status & TIOCM_RNG) printf("RI ");
    if (status & TIOCM_DSR) printf("DSR ");
    if (status & TIOCM_CAR) printf("DCD ");
    if (status & TIOCM_CTS) printf("CTS ");
    if (status & TIOCM_DTR) printf("DTR ");
    if (status & TIOCM_RTS) printf("RTS ");
    if (status & TIOCM_RI) printf("RX ");
    printf("\n");
}

int main(int argc, char *argv[]) {
    if (argc < 2 || argc > 3) {
        fprintf(stderr, "Usage: %s <serial_port> [speed]\n", argv[0]);
        return 1;
    }

    int speed = (argc == 3) ? atoi(argv[2]) : 1000000;

    int fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY);
    if (fd == -1) {
        perror("open");
        return 1;
    }

    struct termios options;
    tcgetattr(fd, &options);
    cfsetispeed(&options, speed);
    cfsetospeed(&options, speed);
    options.c_cflag |= (CLOCAL | CREAD);
    tcsetattr(fd, TCSANOW, &options);

    int prev_status = 0;
    ioctl(fd, TIOCMGET, &prev_status);
    print_status(prev_status);

    while (1) {
        int curr_status;
        ioctl(fd, TIOCMGET, &curr_status);
        if (curr_status != prev_status) {
            print_status(curr_status);
            prev_status = curr_status;
        }
        usleep(100000); // Sleep for 100ms
    }

    close(fd);
    return 0;
}

The above program works on Linux, unix (in general) and if compiled using MSYS2 or CYGWIN it works on windows too.

IN WSL1 CTS (and probably other signals) are ignored and fixed.

Expected Behavior

The same as in linux/windows :D

Actual Behavior

Shorting CTS to ground does not show any change in the program (it does if compiled with MSYS2 or CYGWIN for windows and it does on any other system.

Diagnostic Logs

No need.

Copy link

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions here

Once completed please upload the output files to this Github issue.

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant