小弟要搞清楚linux环境下232通信的一段程序:
#include     <stdio.h>      /*标准输入输出定义*/
#include     <string.h>     
#include     <malloc.h>
#include     <sys/types.h>  
#include     <sys/stat.h>   
#include     <fcntl.h>      /*文件控制定义*/
#include     <unistd.h>     /*Unix 标准函数定义*/
#include     <termios.h>    /*PPSIX 终端控制定义*/
#include     <math.h>
int spfd;
int main()
{
char fname[16],hd[16],*rbuf;
int retv,i,j,k,ncount=0;
struct termios oldtio;
int realdata=0;
spfd=open("/dev/ttyS1",O_RDWR|O_NOCTTY);
perror("open /dev/ttyS1");
if(spfd<0) return -1;
tcgetattr(spfd,&oldtio);
cfmakeraw(&oldtio);
cfsetispeed(&oldtio,B19200);
cfsetospeed(&oldtio,B19200);
tcsetattr(spfd,TCSANOW,&oldtio);
rbuf=&hd[0];
printf("ready for receving data...\n");
retv=read(spfd,rbuf,1);
if(retv==-1)  
perror("read");
while(*rbuf!='\0')  
{   
ncount+=1;   
rbuf++;    
retv=read(spfd,rbuf,1);  
printf("Number received is %d\n",retv);      }
for(i=0;i<(ncount);i++)  
{    k=1;   
for(j=(ncount-i);j>1;j--)  
{      
k=k*10;   }   
printf("%d,%d,%d,\n",(hd[i]-48),k,i);
realdata+=(hd[i]-48)*k;   }  
printf("compleye receiving the data %d\n",realdata);  
close(spfd);   
return 0;}

求助程序注释,功能。
感激![em18]