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 47 48 49 50 51 52
| #include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<errno.h>
#include<unistd.h>
#include<fcntl.h>
#include<termio.h>
#include <time.h>
#include <linux/serial.h>
int serial_open(char *serial_name, speed_t baud)
{
struct termios options;
int fd;
fd = open("/dev/ttyUSB0",O_RDWR);
tcgetattr(fd, &options);
printf("fd %d\n",fd);
cfsetospeed(&options, baud);
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
options.c_cflag &= ~CSIZE;
options.c_cflag |= CS8 | CLOCAL;
options.c_lflag = ICANON;
options.c_oflag &= ~OPOST;
tcsetattr(fd, TCSANOW, &options);
tcflush(fd, TCOFLUSH);
close(fd);
}
void serial_send(int serial_fd, char *data, int nbyte )
{
write(serial_fd, data, nbyte);
}
int main() {
int serial_fd;
char *device;
int nbyte = 28;
/* Open and configure serial port */
serial_fd = serial_open("/dev/ttyUSB0",B9600);
serial_send(serial_fd, device, nbyte);
printf("Ecrire la commande : \n");
scanf("%s",device);
sleep(6);
printf ("\nCommande envoyé %s\n",device);
sleep(6);
return 0;
} |
Partager