Commit 89de38a42817d4e0fd5489029a858b43a27abadd

Authored by grouille
1 parent db82449f

Ajout d'un fichier de lecture du port série

Showing 1 changed file with 49 additions and 0 deletions   Show diff stats
minicom.c 0 → 100644
... ... @@ -0,0 +1,49 @@
  1 +#include <stdio.h>
  2 +#include <termios.h>
  3 +#include <sys/fcntl.h>
  4 +
  5 +void main(void)
  6 +{
  7 + int fd;
  8 + char c;
  9 + struct termios termios_p;
  10 +
  11 + /* Ouverture de la liaison serie */
  12 + if ( (fd=open("/dev/ttyACM0",O_RDWR)) == -1 ) {
  13 + perror("open");
  14 + exit(-1);
  15 + }
  16 +
  17 + /* Lecture des parametres courants */
  18 + tcgetattr(fd,&termios_p);
  19 + /* On ignore les BREAK et les caracteres avec erreurs de parite */
  20 + termios_p.c_iflag = IGNBRK | IGNPAR;
  21 + /* Pas de mode de sortie particulier */
  22 + termios_p.c_oflag = 0;
  23 + /* Liaison a 9600 bps avec 7 bits de donnees et une parite paire */
  24 + termios_p.c_cflag = B9600 | CS7 | PARENB;
  25 + /* Mode non-canonique avec echo */
  26 + termios_p.c_lflag = ECHO;
  27 + /* Caracteres immediatement disponibles */
  28 + termios_p.c_cc[VMIN] = 1;
  29 + termios_p.c_cc[VTIME] = 0;
  30 + /* Sauvegarde des nouveaux parametres */
  31 + tcsetattr(fd,TCSANOW,&termios_p);
  32 +
  33 + /* Affichage sur le terminal */
  34 + write(fd,"Tapez Ctrl-C pour quitter\n",26);
  35 +
  36 + /* Boucle de lecture */
  37 + while ( 1 ) {
  38 + read(fd,&c,1);
  39 + if ( c == 0x03 ) /* Ctrl-C */
  40 + break;
  41 + printf("%03u %02x %c\n",c&0xff,c&0xff,c);
  42 + }
  43 +
  44 + /* Fermeture */
  45 + close(fd);
  46 +
  47 + /* Bye... */
  48 + exit(0);
  49 +}
0 50 \ No newline at end of file
... ...