
我正在使用串行端口到 USB 的轉換器,在 Windows 中,可以打開串行端口屬性並設置複選框 RS-485,只有在此之後我才能從設備接收資料。如何在 Linux 中做同樣的事情?因為預設情況下我得到的結果與在 Windows 中未經檢查的 RS-485 相同:
Port name - /dev/ttyACM0; Method name - readBytes(); Serial port operation timeout (500 ms).
execute try 2 error: I/O exception - failed to read
我的設備是:
Bus 001 Device 008: ID 04e2:1411 Exar Corp.
setserial -a /dev/ttyACM0
/dev/ttyACM0, Line 0, UART: unknown, Port: 0x0000, IRQ: 0
Baud_base: 115200, close_delay: 5, divisor: 0
closing_wait: 300
Flags: spd_normal low_latency
答案1
您必須編寫一些 C 程式碼,如內核文件。
#include <linux/serial.h>
struct serial_rs485 rs485conf = {0};
int fd = open ("/dev/ttyACM0", O_RDWR);
if (fd < 0)...
rs485conf.flags |= SER_RS485_ENABLED;
if (ioctl (fd, TIOCSRS485, &rs485conf) < 0)...