testSerial.c 1.02 KB
#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>  /* UNIX standard function definitions */
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */


// Lecture port série

typedef int serialPort;
serialPort SerialLib_open(const char * portPath);

int main(int argc, char **argv) {
   serialPort p = SerialLib_open("/dev/ttyAMA0"); 
   char buffer[1];
	printf("ouverture reussi\n");

while(1){

printf("lecture d'un caractere\n");
   read(p, buffer ,1);
   

   printf("Message recu: %s \n",buffer);
}
   return 0;
}

/**
 * Ouverture du port 
 * 
 *
 */
serialPort SerialLib_open(const char * serialPortPath) {
   int fd; 

   fd = open(serialPortPath, O_RDWR | O_NOCTTY);
   if (fd == -1) {
      
      printf("Could not open the serial port : %s - ", serialPortPath);
   }else {
      fcntl(fd, F_SETFL, 0);
   }
   return (serialPort)fd;
}