Forum > Linux

Setting non-standard PC serial port speeds ("Baud rates") on Linux

(1/1)

MarkMLl:
Over the "holiday" I've spent a bit of time writing support software for a Shunda Tec-06 battery tester, as described at https://www.sevarg.net/2018/01/14/tec-06-serial-battery-tester-review/

One of the issues was that it used a serial speed of 1.240 Mbits/sec. The only other time that I've had to deal with a non-standard speed was when driving a DMX lighting controller, and in that case the speed was within 10% of one of the standard ones which is marginally OK for async RS232 since every byte is synchronised to the edge of the start bit.

There appear to be two Linux APIs for setting non-standard speeds.

The older one is used by the classic "setserial" program among others and is pretty much aboriginal on PCs. It works well with genuine (NOT counterfeit) FTDI chips, it might not work with some older mainboard chips and in particular can't set the speed higher then 115k since this exceeds the clock speed supplied to the chip.

The newer one was introduced in kernel 2.6, however it relies on TCGETS2 and TCSETS2 termios which were either rapidly deprecated or are only patchily implemented at the kernel driver module level... the situation is unclear.

In any event, if anybody needs this they will find both APIs supported at https://github.com/MarkMLl/shunda_tec06/blob/main/tec06/consoleapp.pas starting at roughly line 186. I might move it to my other serial support units at some point, but am in no great hurry to update that project now that I've uploaded it.

One caveat is that I found that /either/ the kernel was overspilling a data structure, /or/ that the correct packing is elusive in a way that I've not been able to duplicate with FPC. This only affects fields beyond what I needed to manipulate, so I've appended a canary and left it at that. Xref to https://forum.lazarus.freepascal.org/index.php/topic,69437.msg540177.html#msg540177 and Thaddy's packing suggestion, which I was unable to get working.

Obviously this is fairly esoteric since not many devices will demand non-standard speeds, but I contribute it in the hope that it will be useful to somebody at some point.

MarkMLl

Navigation

[0] Message Index

Go to full version