linux下的C语言编程串口问题
程序代码:int main(void)
{
int fd,i=0,j=0,fasong,getdata,Flag;
unsigned char pre_sen[4]={0x01,0x84,0x00,0x43};//数据获取发送
unsigned char pre_rec[10];
struct termios newtio;
fd=open(DATA_COM,O_RDWR);
if(fd==-1)
{
return -1;
}
bzero( &newtio, sizeof( newtio ) );//配置串口
newtio.c_cflag |= CLOCAL | CREAD;
newtio.c_cflag &= ~PARENB;
newtio.c_cflag &= ~CSTOPB;
newtio.c_cflag &= ~CSIZE;
newtio.c_cflag |= CS8;
cfsetispeed(&newtio, B9600);
cfsetospeed(&newtio, B9600);
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 0;
tcflush(fd,TCIFLUSH);
if((tcsetattr(fd,TCSANOW,&newtio))!=0)
{
perror("com set error");
return -1;
}
fasong=write(fd,pre_sen,sizeof(pre_sen));//写
if(fasong<0){
printf("write failed");
}
for(j=0;j<4;j++)
printf("send:%x\n",pre_sen[j]);
getdata=read(fd,pre_rec,sizeof(pre_rec));
for(i=0;i<10;i++)
printf("%x\n",pre_rec[i]);
printf("\n%d",getdata);
close(fd);
}为什么write()函数写不进去呢?求大神指点







