Last active
December 18, 2015 01:29
-
-
Save aborilov/5703954 to your computer and use it in GitHub Desktop.
write to serial port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <termios.h> | |
#include <fcntl.h> | |
#include <sys/ioctl.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#define BAUDRATE B9600 | |
#define DEVICE "/dev/ttySP2" | |
main(){ | |
printf("hello"); | |
int fd; | |
struct termios opt; | |
fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY); | |
if ( fd < 0 ){ | |
perror(DEVICE); | |
} | |
unsigned char data[200] = "Hellodkslnkfndkslakdjaskldjaskldjasasdasdasd"; | |
opt.c_cflag = B9600 | CS8 | CLOCAL | CREAD; | |
opt.c_iflag = IGNPAR; | |
opt.c_lflag = 0; | |
opt.c_oflag = 0; | |
opt.c_cc[VMIN] = 0; //Minimum bytes available | |
opt.c_cc[VTIME] = 0; | |
tcflush(fd, TCIFLUSH); | |
tcsetattr (fd, TCSANOW, &opt); | |
while(1){ | |
printf("Sending\n"); | |
int sended = write(fd, &data, 20); | |
tcflush(fd, TCIOFLUSH); | |
sleep(1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment