|
|
|
|
 如何进行串口中断采集 - worthing [ 2005-10-28 15:37 | 1,161 byte(s)]
 select - mu-chun [ 2005-11-02 14:25 | 0 byte(s)]
|
|
|
|
[Original]
[Print]
[Top]
|
当串口接收到一定量的数据后,触发中断,对数据进行采集。目前看到的例子都是定时采集或者while循环采集数据:
int main(int argc, char **argv)
{
int fd;
int nread;
char buff[512];
struct termios oldtio,newtio;
char *dev ="/dev/ttyS1";
if ( (fd = open(dev,O_RDWR | O_NOCTTY ))<0)
{
printf("Can't Open Serial Port!
");
return -1;
}
tcgetattr(fd,&oldtio); /* save current serial port settings */
setTermios(&newtio,B115200);
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
write(fd,"Hello
",7);
while(1)
{
while((nread = read(fd,buff,512))>0)
{
buff[nread]=' ';
printf("%s
",buff);
write(fd,"Hello
",7);
}
}
tcsetattr(fd,TCSANOW,&oldtio);
close(fd);
}
当串口收到数据触发中断如何进行编程?
|
|
|
[Original]
[Print]
[Top]
|
|
|