#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main()
{
FILE *spfd;
char hd[16];
int retv=0;
//int i,ncount=0;
struct termios oldtio;
//int realdata=0;
spfd=fopen( "/dev/ttySAC0 ","r");
//spfd=open( "/dev/ttySAC0 ",O_RDWR|O_NOCTTY);
if(spfd == NULL)
{
perror( "fopen /dev/ttySAC0");
return -1;
}
printf( "the discriptor of file is %d\n ",fileno(spfd));
tcgetattr(fileno(spfd),&oldtio);
cfmakeraw(&oldtio);
cfsetispeed(&oldtio,B115200);
cfsetospeed(&oldtio,B115200);
tcsetattr(fileno(spfd),TCSANOW,&oldtio);
printf( "ready for receiving data...\n ");
retv=fread(hd,sizeof(char),16,spfd);
printf( "the number received is %d\n ",retv);
printf( "/dev/ttySAC0 received message :%s\n ",hd);
fclose(spfd);
return 0;
}
在板子上运行却显示: no such file or directory。
但是在虚拟机里用echo ok > /dev/usb0
在minicom里输入 cat /dev/ttySAC0 却能收到消息。请教各位,怎样才能让ARMread到消息,ARM端的设备符号是什么。
下面是我在linux上运行的写串口的程序:
int main()
{
//int spfd;
FILE *spfd;
char fname[16];
//char *sbuf;
int retv=0;
//int i,ncount=0;
struct termios oldtio;
//int realdata=0;
spfd=fopen( "/dev/ttyUSB0 ","w+");
//spfd=open( "/dev/ttyS0 ",O_RDWR|O_NOCTTY|O_NONBLOCK);
if(spfd == NULL)
{
perror( "fopen /dev/ttyUSB0 ");
return -1;
}
tcgetattr(fileno(spfd),&oldtio);
cfmakeraw(&oldtio);
cfsetispeed(&oldtio,B115200);
cfsetospeed(&oldtio,B115200);
tcsetattr(fileno(spfd),TCSANOW,&oldtio);
printf( "ready for sending data...\n ");
fname[0]= '1';
fname[1]= '2';
fname[2]= '6';
fname[3]= '\0';
//retv=write(spfd,fname,4);
printf("sending : %s \n",fname);
retv = fwrite(fname,sizeof(char),strlen(fname)+1,spfd);
if(retv==-1)
perror( "write ");
printf( "the number sent is %d\n ",retv);
fclose(spfd);
return 0;
}