J'ai eu le même problème et n'a pas été en mesure de trouver un outil approprié pour mon cas, J'ai donc décidé qu'il était plus rapide de trouver mon propre code. Le code suivant utilise termios2
API (et BOTHER
, qu'Andy Shevchenko a mentionné dans son commentaire) pour définir le débit en bauds personnalisé pour le port série.
n'a jamais regardé dans le code du pilote de série, mais vous pouvez essayer ce code premier:
main.c:
#include "termios2.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ioctl.h>
int main(int argc, char *argv[])
{
struct termios2 tio;
int fd, ret, speed;
if (argc != 3) {
printf("%s device speed\n\n"
"Set speed for a serial device.\n"
"For instance:\n %s /dev/ttyUSB0 75000\n",
argv[0], argv[0]);
return EXIT_FAILURE;
}
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
perror("open() error");
return EXIT_FAILURE;
}
speed = atoi(argv[2]);
ret = ioctl(fd, TCGETS2, &tio);
if (ret == -1) {
perror("TCFETS2 error");
close(fd);
return EXIT_FAILURE;
}
/* Speed settings */
tio.c_cflag &= ~CBAUD;
tio.c_cflag |= BOTHER;
tio.c_ispeed = speed;
tio.c_ospeed = speed;
/* Ignore CR (\r) characters */
tio.c_iflag |= IGNCR;
ret = ioctl(fd, TCSETS2, &tio);
if (ret == -1) {
perror("TCSETS2 error");
close(fd);
return EXIT_FAILURE;
}
close(fd);
return 0;
}
termios2.h:
/* The content for this file was borrowed from:
* /usr/include/asm-generic/termbits.h
*
* We can't just include <asm/termios.h>, because it will interfere with
* regular <termios.h> (compiler will give some errors).
* So it's better to copy needed stuff here instead.
*/
#ifndef TERMIOS2_H
#define TERMIOS2_H
#include <termios.h>
/* termios.h defines NCCS as 32, but for termios2 we need it to be 19 */
#undef NCCS
#define NCCS 19
#define BOTHER 0010000
struct termios2 {
tcflag_t c_iflag; /* input mode flags */
tcflag_t c_oflag; /* output mode flags */
tcflag_t c_cflag; /* control mode flags */
tcflag_t c_lflag; /* local mode flags */
cc_t c_line; /* line discipline */
cc_t c_cc[NCCS]; /* control characters */
speed_t c_ispeed; /* input speed */
speed_t c_ospeed; /* output speed */
};
#endif /* TERMIOS2_H */
Construire:
$ gcc -Wall -O2 main.c -o set-tty-speed
Utilisation:
$ ./set-tty-speed /dev/ttyMSM1 250000
Voir aussi cette question: How to set a custom baud rate on Linux?
Vous devez utiliser une application qui prend en charge 'BOTHER'. AFAIK * picocom * peut être compilé avec un tel support. N'a pas essayé cependant. – 0andriy