#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <sys/stat.h>

#define _POSIX_SOURCE 1
#define MODEMDEVICE "/dev/ttyS1" 

int interrupt_num = 0;

void signal_handler_IO(int stat);

int main()
{
	int res;
	unsigned char buf[MAXDATASIZE];
		
	int fd;
	struct termios newtio;
	struct sigaction saio; /* signal action */

	/* Port OPEN */
	fd = open(MODEMDEVICE,O_RDWR|O_NOCTTY|O_NDELAY);
	if(fd<0)
	{
		printf("fd open ERROR!\n");
		return 0;
	}

printf("port open seccess : fd = %d\n",fd); /* install the signal handler */ saio.sa_handler = signal_handler_IO; sigemptyset(&saio.sa_mask); saio.sa_flags = 0; saio.sa_restorer = NULL; sigaction(SIGIO,&saio,NULL); /* signal SIGIO ON */ fcntl(fd,F_SETOWN,getpid()); /* make fd async */ fcntl(fd,F_SETFL,FASYNC); /* port setting */ tcgetattr(fd,&newtio); cfsetispeed(&newtio,B9600); cfsetospeed(&newtio,B9600); newtio.c_cflag |= (CLOCAL|CREAD|CS8); newtio.c_lflag &= ~(ICANON|ECHO|ECHOE|ISIG); tcflush(fd,TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); .................. .................. while(1) { while(interrupt_num > 0)
{ res = read(fd,buf,MAXDATASIZE); interrupt_num -= 1; ................. } ................ } }
/*************************************************************** * signal_handler_IO() ***************************************************************/ void signal_handler_IO(int stat) { printf("received SIGIO signal.\n"); interrupt_num += 1; }
신고
블로그 이미지

꽃중년

불만있으면 떠나라...

Tag ,

티스토리 툴바