Я пытаюсь инвертировать вывод / dev / ttyUSB0. Я работаю "C". Я новичок в Linux, но вы не обидите меня, если скажете мне этот глупый вопрос.
У меня есть 2 источника RS485; один из Raspberry Pi, который выглядит следующим образом:
Из Raspberry Pi RS485 "щит" / дочерняя плата (/ dev / serial0):
+
|--| |--|
| | | |
____| |_____| |_________
-
Другой от USB до RS485 конвертер на машине с Ubuntu (/ dev / ttyUSB0):
+
_____ _______ __________
| | | |
| | | |
|--| |--|
-
Я бы хотел инвертировать версию 2nd / Ubuntu, чтобы она выглядела как версия Raspberry Pi.
Вот мой код:
int set_interface_attribs(int fd, int baudRateFlag)
{
struct termios tty;
if (tcgetattr(fd, &tty) < 0)
{
printf("Error from tcgetattr: %s\n", strerror(errno));
return -1;
}
cfsetospeed(&tty, (speed_t)baudRateFlag);
cfsetispeed(&tty, (speed_t)baudRateFlag);
tty.c_cflag |= (CLOCAL | CREAD); /* ignore modem controls */
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8; /* 8-bit characters */
tty.c_cflag &= ~PARENB; /* no parity bit */
tty.c_cflag &= ~CSTOPB; /* only need 1 stop bit */
// TODO: CRTSCTS isn't defined in termios.h
// but is in "arm-linux-gnueabihf\bits\termios.h"
tty.c_cflag &= ~CRTSCTS; /* no hardware flowcontrol */
/* setup for non-canonical mode */
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
tty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
tty.c_oflag &= ~OPOST;
/* fetch bytes as they become available */
tty.c_cc[VMIN] = 1;
tty.c_cc[VTIME] = 1;
if (tcsetattr(fd, TCSANOW, &tty) != 0)
{
printf("Error from tcsetattr: %s\n", strerror(errno));
return -1;
}
return 0;
}