Blame view

SerialWebsocket/main.c 609 Bytes
787d9fce   thubert   Ajout des fichier...
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
  /*
   * Test on serial device
   */
  
  ////
  // Include files
  ////
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <termios.h>
  
  #include "serial.h"
  
  ////
  // Constants
  ////
  #define         SERIAL_DEVICE           "/dev/ttyACM0"
  
  ////
  // Global variables
  ////
  
  ////
  // Main function
  ////
  
  int main(void){
  int c=0;
  int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH);
  serialConfig(sd,B9600);
  if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); }
  int i;
  for(i=0;i<8;i++){
    if(read(sd,&c,sizeof(char))!=1){ perror("main.read"); exit(-1); }
    printf("%02x\n",c);
    }
  serialClose(sd);
  exit(0);
  }