0

I have an FTDI USB/serial device at /dev/ttyUSB0. I set up my channel with

% set channel [open /dev/ttyUSB0 r+]
file3
% chan configure $channel -mode "76800,n,8,1" -buffering none -blocking 0 -translation auto

which works just fine for Tcl on Windows. On Linux, baud rate queries show

% puts [chan configure $channel -mode]
57600,n,8,1

and I get all the garbage you'd expect from trying to communicate at the wrong baud rate. I saw this previous post: fconfigure refuses to set baud rate to 921600 ...reference a fixed set of baud rates in the Tcl source. Is there a way for me to add my non-standard baud rate to get communication to work under both Windows and Linux?

John Peck
  • 3
  • 1

2 Answers2

3

Tcl refuses to set the speed to those values because the underlying C functions don't support those baud rates on Linux. In fact, it's not Tcl or even your libc that's the problem here, but Linux: it supports a fixed set of baud rates, and 76800 is not one of them.

On my system (Debian sid), the baud rates beyond the ones specified by POSIX are visible in /usr/include/x86_64-linux-gnu/bits/termios-baud.h. This location may differ based on the OS and version.

If you want to use this serial device, you'll need to configure it for a different rate. The closest ones are 57600 and 115200. The maximum supported POSIX-specified version is 38400.

bk2204
  • 64,793
  • 6
  • 84
  • 100
0

While bk2204's response is correct in terms of standard baud rates, it is possible to use the non-standard baud rates with FTDI devices. At least in older versions of Linux, it is possible to tell the driver to set a custom divisor on the chip to output at the correct baud rate(see this answer for details). I haven't tried this in a few years though, so this may no longer work.

On Windows, you need to edit the registry for the chip that you want the custom baud rate for(see FTDI document AN_120).

Both of these are predicated upon the fact that you are using an FTDI chip - other USB to serial converters may not work at custom baud rates.

rm5248
  • 2,590
  • 3
  • 17
  • 16