Blame view

projetSC/test.c 1.17 KB
1f48dd44   mdelapor   mise en ligne du ...
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
  #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;
  }