串口收发的怪异问题求助
vxworks5.5.1+s3c2440平台
在使用串口读写时,出现如下的问题,能够正常接收,但是无法发送数据
代码如下:
static int fd;static SEM_ID dataSemId;int taskIdOne, taskIdTwo;char sendBuf[] = "$GPRMC,A*20\r\n";int tty_receive(){ int width; struct fd_set readFds; char tch = 0; int recfd = 0; recfd = fd; while(1) { FD_ZERO(&readFds); FD_SET(recfd, &readFds); width = recfd + 1; if(select(width, &readFds,NULL,NULL,NULL) == ERROR) { logMsg("select() error!\n", 1,2,3,4,5,6); return(ERROR); } if(FD_ISSET(recfd, &readFds)) { if (read(recfd, &tch, 1) == 0) { logMsg("read() error!\n", 1,2,3,4,5,6); return(ERROR); } if ('$' == tch) { semGive (dataSemId); // --> 触发发送 } } } close(recfd); return 1;}int tty2_send(void){ int bytes_out; int writeFd = 0; /*writeFd = open("/tyCo/2", O_RDWR, 0);*/ // 注1 writeFd = fd; // 注2 if (writeFd < 0) { logMsg("open serial error!\n", 1,2,3,4,5,6); return(ERROR); } else logMsg("open serial succeed!\n", 1,2,3,4,5,6); while(1) { semTake (dataSemId, WAIT_FOREVER); bytes_out = write(writeFd, sendBuf, strlen(sendBuf)); if (bytes_out == 0) { logMsg("write error() - bytes_out = 0.\n", 1,2,3,4,5,6); return(ERROR); } else { logMsg("output chars total: %d\n", bytes_out,2,3,4,5,6); // 注3 } } return 1;}int app(){ dataSemId = semBCreate (SEM_Q_FIFO, SEM_EMPTY); if (NULL == dataSemId) { logMsg("create bianry sem error\n", 1,2,3,4,5,6); return(ERROR); } fd = open("/tyCo/2", O_RDWR, 0); if (fd < 0) { logMsg("app(): open serial error\n", 1,2,3,4,5,6); return(ERROR); } else logMsg("app(): open serial succeed - fd(%d)\n", fd,2,3,4,5,6); if (ioctl(fd, FIOSETOPTIONS, OPT_RAW) == ERROR) { logMsg("ioctl(OPT_RAW) ERROR!\n", 1,2,3,4,5,6); return(ERROR); } if (ioctl(fd, FIOBAUDRATE, 115200) == ERROR) { logMsg("ioctl(115200) ERROR!\n", 1,2,3,4,5,6); return(ERROR); } if (ioctl(fd, SIO_HW_OPTS_SET, CS8) == ERROR) { logMsg("ioctl(CS8) ERROR!\n", 1,2,3,4,5,6); return(ERROR); } if (taskIdOne = taskSpawn("comrec",90,0x100,2000,(FUNCPTR)tty_receive, 0,0,0,0,0,0,0,0,0,0) == ERROR) { logMsg("Error in spawning task comrec\n", 1,2,3,4,5,6); return(ERROR); } if (taskIdTwo = taskSpawn("comsend",90,0x100,2000,(FUNCPTR)tty2_send, 0,0,0,0,0,0,0,0,0,0) == ERROR) { logMsg("Error in spawning task comsend\n", 1,2,3,4,5,6); return(ERROR); } return(OK);}void close_com(void){ taskDelete(taskIdOne); taskDelete(taskIdTwo); semDelete(dataSemId); close(fd);}