1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <stdio.h> /* Standard input/output definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <fcntl.h> /* File control definitions */
int initport_ (int fd)
{
struct termios options;
// Récuperation d'options courante
tcgetattr(fd, &options);
// Vitesse In/out.
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cflag |= (CLOCAL | CREAD);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8;
// Applique la nouvelle config
tcsetattr(fd, TCSANOW, &options);
return 1;
}
int main ()
{
int fd;
fd = open("/dev/tts/0", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1) {
perror("Impossible d'ouvrir le port /dev/ttys/0 - ");
return 1;
} else {
fcntl(fd, F_SETFL, 0);
}
initport_(fd);
write(fd, "test", 4);
close(fd);
return 0;
} |
Partager