在Linux下为FTDI虚拟串行端口指定非标准波特率 [英] Specifying non-standard baud rate for FTDI virtual serial port under Linux

查看:308
本文介绍了在Linux下为FTDI虚拟串行端口指定非标准波特率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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指定常量,因此我不能使用cfsetispeedcfsetospeed.
  • 在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 use cfsetispeed and cfsetospeed.
  • 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 the tty_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆