|
我按照你说的那些操作进行了试验,现在控制台是没有发信息了 但是我现在用我的一个程序,打开串口0
fd = open("/dev/tqc2440_serial0",O_RDWR | O_NOCTTY | O_SYNC);
printf("fd is %d\n",fd);
这个fd永远是“-1”,为什么呢?
我把我的代码贴上面来
//通过板子向PC发数据的程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
int main()
{
//char buff[8]={0x68,0x01,0x25,0x23,0x45,0x78,0x26,0x16};
char buff[8]={"Good!\n"};
int fd,c,res,nsize = 0;
int i=0;
struct termios oldtio,newtio;
//fd = open("/dev/tqc2440_serial1",O_RDWR | O_NOCTTY | O_SYNC);
while(1)
{
//fd = open("/dev/ttyS0",O_RDWR | O_NOCTTY | O_SYNC);
fd = open("/dev/tqc2440_serial0",O_RDWR | O_NOCTTY | O_SYNC);
printf("fd is %d\n",fd);
tcgetattr(fd, &oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = B115200 | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_oflag &= ~OPOST;
newtio.c_lflag = 1;
cfsetispeed(&newtio,B115200);
cfsetospeed(&newtio,B115200);
tcflush(fd, TCIOFLUSH);
tcsetattr(fd, TCSANOW, &newtio);
nsize=write(fd,buff,8);
fcntl(fd,F_SETFL,FNDELAY);
if(nsize<0)
{
perror("Write wrong");
return;
}
tcsetattr(fd, TCSANOW, &oldtio);
close(fd);
sleep(1);
}
} |
|