soqsoq2007-04-02 17:40
请教虚拟机下串口问题
我在虚拟机vmware下安了linux,用了串口,
arm写了一个写串口程序,linux下写了一个读串口程序,能成功的运行;
但在linux下写一个写串口程序,arm下写了一个读串口程序,就读不出数据来,怎么回事,是虚拟机有问题吗,只能写不能读?
程序:
//writetest.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int spfd;
int main()
{
char fname[16],*sbuf;
int retv,i,ncount=0;
struct termios oldtio;
int realdata=0;
spfd=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NONBLOCK);
//spfd=open("/dev/ttyS0",O_RDWR|O_NOCTTY);
if(spfd<0)
{
perror("open/dev/ttyS0");
return -1;
}
tcgetattr(spfd,&oldtio);
cfmakeraw(&oldtio);
cfsetispeed(&oldtio,B57600);
cfsetospeed(&oldtio,B57600);
tcsetattr(spfd,TCSANOW,&oldtio);
printf("ready for sending data...\n");
fname[0]='1';
fname[1]='2';
fname[2]='3';
fname[3]='\0';
retv=write(spfd,fname,4);
if(retv==-1)
perror("write");
printf("the number sent is %d\n",retv);
close(spfd);
return 0;
}
//readtest.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int spfd;
int main()
{
char hd[4];
int retv,i,ncount=0;
struct termios oldtio;
int realdata=0;
spfd=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NONBLOCK);
//spfd=open("/dev/ttyS0",O_RDWR|O_NOCTTY);
if(spfd<0)
{
perror("open/dev/ttyS0");
return -1;
}
printf("spfd%d\n",spfd);
tcgetattr(spfd,&oldtio);
cfmakeraw(&oldtio);
cfsetispeed(&oldtio,B57600);
cfsetospeed(&oldtio,B57600);
tcsetattr(spfd,TCSANOW,&oldtio);
printf("ready for receiving data...\n");
retv=read(spfd,hd,4);
/*
if(retv==-1)
{
perror("read");
return -1;
}
*/
printf("%d\n",retv);
printf("%s\n",hd);
close(spfd);
return 0;
}