#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/ttyUSB1"); /* The serial port of the raspberry pi */
   char buffer[16];
   buffer[15] = "";
   read(p, buffer ,15);
//while(1){
//read(p,buffer,15);
   printf("Message recu: %s n",buffer);
//}
   return 0;
}

/**
 * Open the specified serial port
 * and return the associated file descriptor
 *
 */
serialPort SerialLib_open(const char * serialPortPath) {
   int fd; /* File descriptor for the port */
printf("test3/n");
   fd = open(serialPortPath, O_RDWR | O_NOCTTY);
   if (fd == -1) {
      /* Error opening the serial port */
      printf("Could not open the serial port : %s - ", serialPortPath);
   }else {
      fcntl(fd, F_SETFL, 0);
   }
   return (serialPort)fd;
} 
