
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 1.44 KB | hits: 16 | expires: Never
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <string.h>
int main()
{
int fd;
struct termios options;
int n;
char buff[15]="";
/* Open Port */
fd = open("/dev/ttySAC1", O_RDWR | O_NOCTTY | O_NDELAY); /* <--- YOUR PORT */
if(fd == -1) {
printf("ERROR Open Serial Port!");
}
/* Serial Configuration */
tcgetattr(fd, &options); // Get Current Config
cfsetispeed(&options, B9600); // Set Baud Rate
cfsetospeed(&options, B9600);
options.c_cflag = (options.c_cflag & ~CSIZE) | CS8;
options.c_iflag = IGNBRK;
options.c_lflag = 0;
options.c_oflag = 0;
options.c_cflag |= CLOCAL | CREAD;
options.c_cc[VMIN] = 1;
options.c_cc[VTIME] = 5;
options.c_iflag &= ~(IXON|IXOFF|IXANY);
options.c_cflag &= ~(PARENB | PARODD);
/* Save The Configure */
tcsetattr(fd, TCSANOW, &options);
/* Flush the input (read) buffer */
tcflush(fd,TCIOFLUSH);
printf ("\ntest point 1\n");
write(fd,"R",4);
printf ("\ntest point 2\n");
/* Flush the input (read) buffer */
printf ("\ntest point 3\n");
tcflush(fd,TCIOFLUSH);
printf ("\ntest point 4\n");
write(fd,"S",4);
usleep(50);
printf ("\ntest point 5\n");
read(fd,buff,10); // Read Data From Serial Port
printf ("\ntest point 6\n : %s : \n",buff); // Print Out
close(fd); // Close Port
return 0; // End Program
}