RS232통신을 하는데 스코프로 측정하니 RX,TX 신호가 안잡힙니다
프로그램입니다. NON-CANONICAL 동기
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/types.h>
#include <linux/serial.h>
#include <termios.h>
#include <sys/signal.h>
#include <sys/types.h>
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
int main(int argc, char **argv)
{
struct termios oldtio,newtio;
volatile int fd;
int txemptystate;
char buf[255];
//OPEN COM2 PORT
fd=open("/dev/ttyS1",O_RDWR | O_NOCTTY );
if(fd<0)
{
//OPEN FILE FAILED
printf("can't open serial port 0\n");
return -1;
}
//통신환경 설정
tcgetattr(fd,&oldtio); //현재 설정을 oldtio에 저장
//NON-CANONICAL
memset(&newtio,0,sizeof(newtio));
newtio.c_cflag = B9600 | CS8 | CLOCAL |CREAD ;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VMIN]=5;
newtio.c_cc[VTIME]=0;
tcflush(fd,TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
memset(buf,c,32);
buf[32]=0;
write(fd,buf,32);
printf("DATA : [%s]\n",buf);
while(1)
{
ioctl(fd,TIOCSERGETLSR,&txemptystate);
if(txemptystate) break;
}
sleep(1);
while(STOP==FALSE)
{
res=read(fd,buf,255);
buf[res]=0;
printf(":%s:%d\n",buf,res);
if (buf[0]=='z') STOP=TRUE;
}
tcsetattr(fd,TCSANOW,&oldtio);
close(fd);
return 0;
}
댓글 달기