linux - Linux UART (16550A) RS485 模式
问题描述
我正在尝试将我的串行端口 (/dev/ttyS0) 配置为自动控制 RTS 引脚。我已经可以通过 ioctl TIOCM_RTS 标志切换从用户空间执行此操作,但在我的情况下它太慢了 - 从设备响应太快,我错过了它。
我试图通过启用 RS485 模式来实现它,但我以以下错误结束:
unable to set IOCTL:: Inappropriate ioctl for device
我的实现
port_fd = open(port.c_str(), O_RDWR);
if (port_fd != -1) {
struct serial_rs485 rs485conf={0};
rs485conf.flags |= SER_RS485_ENABLED;
rs485conf.flags |= SER_RS485_RTS_ON_SEND;
rs485conf.delay_rts_before_send = 0;
int rv = ioctl(port_fd,TIOCSRS485, &rs485conf);
if(rv){
printf("rv = %d\n", rv);
perror("unable to set IOCTL:");
}
dmesq 输出:
[ 0.000000] console [tty0] enabled
[ 1.338716] 00:01: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[ 1.359441] 00:02: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[ 1.380168] 00:03: ttyS2 at I/O 0x3e8 (irq = 7, base_baud = 115200) is a 16550A
[ 1.400953] 00:04: ttyS3 at I/O 0x2e8 (irq = 7, base_baud = 115200) is a 16550A
[ 1.421677] 00:05: ttyS4 at I/O 0x2f0 (irq = 7, base_baud = 115200) is a 16550A
[ 1.442338] 00:06: ttyS5 at I/O 0x2e0 (irq = 7, base_baud = 115200) is a 16550A
如何强制我的串口工作在这种模式下或者可能有另一种方法来实现 RTS 自动控制?
操作系统:
4.15.0-23-generic #25-Ubuntu SMP Wed May 23 18:02:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
解决方案
推荐阅读
- .net - MuleSoft 是否支持 .Net Core 应用程序
- amazon-web-services - 将 Snowflake 账户链接到 AWS 账户 ID
- python - 如何在 Python 中找到列表的最大值?
- python - 如何使用从字符串中抓取的一些运算符
- java - 在 Java 中反转 PriorityQueue 顺序的最快方法
- react-native - 在 react-native 的应用程序中处于睡眠模式或不活动状态后,模态不会打开
- reactjs - 传递整个对象时是否可以避免重新渲染所有输入?
- javascript - MongoDB 无法使用 findOneAndUpdate() 推送到数组
- ip-address - 您的服务器拥有静态 IP 地址有什么好处?
- mysql - MySQL 中的触发器问题