Linux下为FTDI虚拟串口指定非标准波特率 [英] Specifying non-standard baud rate for FTDI virtual serial port under Linux
问题描述
我有一个 USB 设备,我试图通过 ftdi_sio 内核模块提供的虚拟串行端口与之通信.但是,我在将端口的波特率设置为 14400 时遇到了一些问题:
I have a USB device I'm trying to communicate with over a virtual serial port provided by the ftdi_sio kernel module. However, I'm having some trouble setting the baud rate of the port to 14400:
termios.h
没有为 14400 指定常量,所以我不能使用cfsetispeed
和cfsetispeed
.- 在 ftdi_sio 内核模块的源代码中,波特基设置为 24000000,似乎没有办法更改它.这意味着我无法将自定义除数与
TIOCSSERIAL
ioctl 一起使用,从而获得 14400 波特率. - 模块源有一条注释,听起来像是将端口的
tty_struct
结构的alt_speed
成员设置为 14400 可以满足我的要求,但没有鉴于现有接口,似乎没有任何方法可以将其设置为 14400.
termios.h
doesn't specify a constant for 14400, so I can't usecfsetispeed
andcfsetospeed
.- In the source for the ftdi_sio kernel module, baud base is set to 24000000 and there doesn't seem to be a way to change it. This means I can't use a custom divisor with the
TIOCSSERIAL
ioctl and get a 14400 baud rate that way. - The module source has a comment making it sound like setting the
alt_speed
member of thetty_struct
structure for the port to 14400 would do what I want, but there doesn't seem to be any way to set it to 14400 given the existing interfaces.
有人对此有任何想法吗?通过破解内核模块很容易解决这个问题,但我真的在寻找一种不需要更改内核的解决方案.
Does anyone have any ideas about this? It'd be pretty easy to fix this by hacking up the kernel module, but I'm really looking for a solution that doesn't require kernel changes.
推荐答案
你不能改变波特基,我想它与硬件有关.所以弄乱模块对你没有任何好处.在您的第三点中,您只讨论了设置自定义波特率的第一种方法,您需要访问 tty->alt_speed
.似乎没有直接从用户空间设置 tty 结构的接口,至少没有使用 ftdi_sio 驱动程序.
但是,评论中解释了另一种方法:
You can't change baud base, I suppose it is hardware related. So messing with the module won't do you any good. In your third point you only talk about the first method proposed for setting a custom baudrate, where you need to access the tty->alt_speed
. It seems there is no interface to directly set tty struct from userspace, at least not with the ftdi_sio driver.
However, there is another method explained in the comments :
* 3. You can also set baud rate by setting custom divisor as follows
* - set tty->termios->c_cflag speed to B38400
* - call TIOCSSERIAL ioctl with (struct serial_struct) set as
* follows:
* o flags & ASYNC_SPD_MASK == ASYNC_SPD_CUST
* o custom_divisor set to baud_base / your_new_baudrate
你试过了吗?
这篇关于Linux下为FTDI虚拟串口指定非标准波特率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!