????д????Linux?豸?????е????????????I/0????ν???????????I/O??????????I/O????????????????????????????????????????????豸???????????????
???????????????
???????????? ?? ?????????豸???????????????????????????????????????????????в??????????????????????? ?????????????????????????
?????????????? ???????????豸???????????????????????????????????????????????в?????????????ó?????????select?????ò??????????豸???????????????????????豸?????? poll??????С?
???????????????
????????????????????
????char buf;
????fd = open("/dev/ttyS1"??O_RDWR);
????.....
????res = read(fd??&buf??1);
????//???????????????????????????????????????
????if(res == 1)
????{
????printf("%c/n"??buf);
????}
?????????????????????
????char buf;
????fd = open("/dev/ttyS1"??O_RDWR|O_NONBLOCK);
????//O_NONBLOCK ?????????
????.....
????while(read(fd??&buf??1)!=1);
????//????????????????????????????
????printf("%c/n"??buf);
???????????????????????????????????????????????????????????????I/O?????????ò?????????select()??poll()?????ò????????豸???????????????select()??poll()??????????????豸?????е?poll()?????????á????????в????????????????????????????????
??????ò??select()??????
????int select(int numfds??fd_set *readfds??fd_set *writefds??fd_set *exceptionfds??
????struct timeval *timeout); numfds ???????????????????????????1????select()????timeout????????????????????????????
??????ó??????
#inlcude------
main()
{
int fd??num;
char rd_ch[BUFFER_LEN];
fd_set rfds??wfds;
//??д???????????
//????????????/dev/globalfifo?豸???
fd=open("/dev/globalfifo"??O_RDWR|O_NONBLOCK);
if(fd != -1)
{
//FIFO ????
if(ioctl(fd??FIFO_CLEAR??0) < 0)
{
printf("ioctl cmd failed /n");
}
while(1)
{
FD_ZERO(&rfds);
FD_ZERO(&wfds);
FD_SET(fd??&rfds);
FD_SET(fd??&wfds);
select(fd+1??&rfds??&wfds??null??null);
}
}
}