Specifying non-standard baud rate for FTDI virtual serial port under Linux

后端 未结 2 482
死守一世寂寞
死守一世寂寞 2020-12-18 11:18

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 rat

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 12:03

    Shodanex's solution works with an NDI Polaris Spectra (baud 1.2mbps) under Linux. As specified, open the serial device (/dev/ttyUSB0) with 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);
    

    then execute:

    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); 
    }
    

提交回复
热议问题