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 37 38 39 40 41 42 43 44 45 46
   | int main () {
 
  int fd;
  char *num;
  char c;
  struct termios  termios_p;
 
  /* Ouverture de la liaison serie */
  fd = open(PORT, O_RDWR | O_NOCTTY);
  if (fd <0) {perror(PORT); exit(-1); }
 
  /* Lecture des parametres courants */     
  tcgetattr(fd,&termios_p);            
  /* On ignore les BREAK et les caracteres avec erreurs de parite */ 
  termios_p.c_iflag = IGNBRK | IGNPAR;   
  /* Pas de mode de sortie particulier */   
  termios_p.c_oflag = 0;     
  /* Liaison a 9600 bps avec 8 bits de donnees et une parite paire */
  termios_p.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
  /* Mode non-canonique avec echo */ 
  termios_p.c_lflag = ECHO; 
  /* Caracteres immediatement disponibles */
  termios_p.c_cc[VMIN] = 1;
  termios_p.c_cc[VTIME] = 0;
  /* Sauvegarde des nouveaux parametres */ 
  tcsetattr(fd,TCSANOW,&termios_p);
 
  /* Boucle de lecture du port  */
  while(1){    
 
    strcpy (&c, "");
    strcpy (&num, "");    
 
    while(c!=0x0a){
      read(fd, &c, 1);
      printf("%c\n",c);
      strcat (num,&c);
    }    
 
    printf("%s\n",num);  
  }
 
close(fd);   
 
return 0;
} | 
Partager