Home/Support/Support Forum/How can I set a custom baud rate in Linux?
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

How can I set a custom baud rate in Linux?

0 votes
Using DIGI TS 16. Redhat EL6. dgrp-1.9-30.x86_64. Cannot set custom baud rate. Ioctl calls return -1. Using ioctl calls with a non-DIGI usb to serial (RS422) device (code bellow) works fine. Trying to convert to use DIGI. Does DIGI have special ioctl call definitions for setting custom baud rate?

/* Setup a Custom Divisor Baud Rate */
int rate=11520; //ICD says 12Kbps
struct serial_struct serinfo;
serinfo.reserved_char[0] = 0;
ioctl(xfd, TIOCGSERIAL, &serinfo);

serinfo.flags &= ~ASYNC_SPD_MASK;
serinfo.flags |= ASYNC_SPD_CUST;
serinfo.custom_divisor = (serinfo.baud_base + (rate / 2)) / rate;

if (serinfo.custom_divisor < 1) {
serinfo.custom_divisor = 1;
ioctl(xfd, TIOCSSERIAL, &serinfo);

int speed = 0;
struct termios options;
fcntl(xfd, F_SETFL, 0);
tcgetattr(xfd, &options);
cfsetispeed(&options, speed ?: B38400);
cfsetospeed(&options, speed ?: B38400);
options.c_cflag &= ~CRTSCTS;
options.c_cflag |= CS7|PARENB|PARODD|CREAD|CLOCAL;

tcsetattr(xfd, TCSANOW, &options);

asked Mar 27, 2017 in Realport by bgantz12 New to the Community (0 points)

Please log in or register to answer this question.