빠른 답변 감사드립니다.
아직 모르는게 있어서 한번 더 물어보려고 합니다. 귀찮게 해드려서 죄송합니다 ㅜㅜ
UART를 통해 통신하는 예제가 있는지요 (교재에는 아무리 찾아봐도 찾을수가 없네요..)
#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);
sleep(4);
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
}
현재 이렇게 해서 테스트를 해보았는데 제대로 동작이 되지 않고 있습니다..
|