Linux下编写的C,arm-linux-gcc 之后下载到了开发板里,可是在开发板终端输入./receive,没任何反应
/**********************************************
*****name:receive.c*******************************
*****Description:Receive data from Serial_Port****
*****Data:***************************************/
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<termios.h>
#include"math.h"
#define max_buffer_size 100
int fd,s;
int open_serial(int k)
{
if(k==0)
{
fd=open("/dev/ttySAC0",O_RDWR|O_NOCTTY);
perror("open /dev/ttySAC0");
}
else
{
fd=open("/dev/ttySAC3",O_RDWR|O_NOCTTY);
perror("open /dev/ttySAC3");
}
if(fd==-1)
return -1;
else
return 0;
}
int main()
{
char hd[max_buffer_size],*rbuf;
int flag_close,retv,i,ncount='0';
struct termios opt;
int realdata='0';
open_serial(0);
tcgetattr(fd,&opt);
cfmakeraw(&opt);
cfsetispeed(&opt,B115200);
cfsetospeed(&opt,B115200);
tcsetattr(fd,TCSANOW,&opt);
rbuf="hd";
printf("ready for receiving data...\n");
retv=read(fd,rbuf,1);
if(retv==-1)
{
perror("read");
}
while(*rbuf!='\n')
{
ncount+=1;
rbuf++;
retv=read(fd,rbuf,1);
if(retv==-1)
{
perror("read");
}
}
printf("the data recdeived is:\n");
for(i=0;i<ncount;i++)
{
printf("%c",hd[i]);
}
printf("\n");
flag_close=close(fd);
if(flag_close==-1)
printf("Close the Deceive failur!\n");
return 0;
}
|