I am writing a simple program to open the serial port /dev/ttyS0
which is visible in /dev
.
The code opens the serial port no problems on my PC at home but on my work machine I run into an error that returns "Input/Output Error". The error appears as a result of tcgetattr
failing but I am unsure why as the serial port is visible. I added a verbose error printout via libexplain
and it reported to me.
tcgetattr(fildes = 3 "/dev/ttyS0", data = 0x7FFEEA8CEEB0) failed, Input/output error (5, EIO)
I am not sure what other information is relevant that I can provide. It is an Arch Linux system with a 5.3.8 kernel.
const char *port_name = "/dev/ttyS0";
int main(int argc, char *argv[])
{
int serial_fd, file_status;
struct termios termSettings;
struct sigaction act = { 0 };
serial_fd = open(port_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (serial_fd < 0) {
perror("Opening serial port failed");
return -1;
}
if (tcgetattr(serial_fd, &termSettings) < 0) {
perror("Getting terminal attributes failed");
printf("Error reason: %s\n", explain_tcgetattr(serial_fd, &termSettings));
goto error;
}
...
}
The complete source is here
dmesg | grep /dev/ttyS0
report something unusual? What driver does your port use? – Marcos G./dev/ttyS0, UART: unknown, Port: 0x03f8, IRQ: 4
./sys/class/tty/*/device/driver
is showing all of my 4 ttyS[0123] being run by theserial8250
driver. – Alex Hoffmannsudo modprobe serial-8250
and trydmesg | grep /dev/tty
again. You are on a desktop with a multiport card, right? – Marcos G./lib/modules
even though CONFIG_SERIAL_8250 is enabled in my kernel build. Funnily enough I get the same result from my home PC, saying 8250 cannot be found. Both are thinkpads with docks. My work computer (with the error) is an x280 with a thunderbolt dock. – Alex Hoffmann