Specifying Custom Baud Rate for FTDI Virtual Serial Port on Linux

I have a USB device that I'm trying to communicate with through the virtual serial port provided by the ftdi_sio kernel module. However, I am having problems setting the baud rate on the port to 14400:

  • termios.hdoesn't set a constant for 14400, so I can't use cfsetispeedand cfsetospeed.
  • In the source code for the ftdi_sio kernel module, the baud base is set to 24000000, and there seems to be no way to change it. This means that I can not use a custom divisor with TIOCSSERIALioctl and get a transfer rate of 14400 thereby.
  • The module source has a comment that sounds like the alt_speedstructure element tty_structfor port 14400 will do what I want, but there seems to be no way to set it 14400 based on existing interfaces.

Does anyone have any ideas about this? It would be pretty easy to fix this by cracking the kernel module, but I'm really looking for a solution that does not require kernel changes.

+3
source share
2 answers

, , . . , , tty->alt_speed. , tty struct , , ftdi_sio.
:

     * 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

?

+4

Shodanex NDI Polaris Spectra (baud 1.2mbps) Linux. , (/dev/ttyUSB0) B38400,

int port = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NONBLOCK);
tcgetattr(port,&g_initialAtt);// save this to restore later
newAtt=g_initialAtt;
newAtt.c_cflag = B38400 | CS8 | CLOCAL | CREAD; 
cfmakeraw(&newAtt);
tcsetattr(port,TCSANOW,&newAtt);

:

if(ioctl(port, TIOCGSERIAL, &sstruct) < 0){
    printf("Error: could not get comm ioctl\n"); 
    exit(0); 
}
sstruct.custom_divisor = custDiv;
//sstruct.flags &= 0xffff ^ ASYNC_SPD_MASK; NO! makes read fail.
sstruct.flags |= ASYNC_SPD_CUST; 
if(ioctl(port, TIOCSSERIAL, &sstruct) < 0){
    printf("Error: could not set custom comm baud divisor\n"); 
    exit(0); 
}
+3

Source: https://habr.com/ru/post/1753476/


All Articles