恳求指教!!对qnx下串口通信程序一窍不通

我将linux下的串口通信程序放在qnx下进行使用。但是write函数在写端口的时候感觉是阻塞了。我在Ubuntu下运行这个程序,在qnx 下使用cat /dev/ser1能收到信息(不管加没加回车)。但是在qnx下,必须加了回车Ubuntu才能连续收到信息。我参考了网上的资料,应该是把回车响应之类的特性关了。
但是,看了论坛上的帖子我感觉qnx不是这样来写串口程序的,网上搜索相关教程也搜索不到,只好在这里向大家讨教了,请大家指教下我!!感谢!!!!
下面是代码:
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <termios.h>

int serial_open(void)
{
int fp;
fp = open("/dev/ser1",O_RDWR | O_NOCTTY | O_NDELAY);
if(-1 == fp)
{
perror(“can’t open serial port one”);
exit(-1);
}
fcntl(fp,F_SETFL,0);
return fp;
}

void set_speed(int fp,int speed)
{
int status;
struct termios Opt;
tcgetattr(fp,&Opt);
tcflush(fp,TCIOFLUSH);
cfsetispeed(&Opt,speed);
cfsetospeed(&Opt,speed);
Opt.c_cflag |= CLOCAL;
status = tcsetattr(fp,TCSANOW,&Opt);
if(status != 0)
{
perror(“tcsetattr fp”);
return;
}
tcflush(fp,TCIOFLUSH);
}

int set_Parity(int fd,int databits,int stopbits,int parity)
{
struct termios options;
if(tcgetattr(fd,&options) != 0)
{
perror(“SetupSerial 1”);
return -1;
}
options.c_cflag &= ~CSIZE;
switch(databits)
{
case 7:
options.c_cflag |= CS7;
break;
case 8:
options.c_cflag |= CS8;
break;
default:
printf(“unsupport data size\n”);
return -1;
}
switch(parity)
{
case ‘n’:
case ‘N’:
options.c_cflag &= ~PARENB;//clear parity enable
options.c_iflag &= ~INPCK;//enable parity checking
break;
case ‘o’:
case ‘O’:
options.c_cflag |= (PARODD | PARENB);//奇校验
options.c_iflag |= INPCK;//disable parity checking
break;
case ‘e’:
case ‘E’:
options.c_cflag |= PARENB;//enable parity
options.c_cflag &= ~PARODD;//偶校验
options.c_iflag |= INPCK;//disable parity checking
break;
case ‘s’:
case ‘S’:
options.c_cflag &= ~PARENB;
options.c_cflag &= ~CSTOPB;
break;
default:
printf(“unsupported parity\n”);
return -1;
}
switch(stopbits)
{
case 1:
options.c_cflag &= ~CSTOPB;
break;
case 2:
options.c_cflag |= CSTOPB;
break;
default:
printf(“unsupported stop bits\n”);
return -1;
}
if(parity != ‘n’)
options.c_iflag |= INPCK;
tcflush(fd,TCIFLUSH);
options.c_cc[VTIME] = 150;
options.c_cc[VMIN] = 0;
//set r/w mode
options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);//input
options.c_oflag &= ~OPOST;//output
if(tcsetattr(fd,TCSANOW,&options) != 0)
{
perror(“SetupSerial 3”);
return -1;
}
return 1;
}

int main(int argc, char *argv[]) {
int fp,maxfdp;
struct fd_set fds;
printf(“Hello World\n”);
printf(“Now will open a serial port.\n”);
fp = serial_open();//open serial port
set_speed(fp,B9600);//set baud speed value
if(-1 == set_Parity(fp,8,1,‘N’))
{
printf(“set parity error”);
exit(0);
}
while(1)
{
FD_ZERO(&fds);
FD_SET(fp,&fds);
maxfdp = fp + 1;
switch(select(maxfdp,NULL,&fds,NULL,NULL))
{
case -1:
printf(“select error\n”);
exit(-1);
case 0:
break;
default:
if(FD_ISSET(fp,&fds))
{
write(fp,"(fzb)\n",6);
}
break;
}
}
close(fp);
return EXIT_SUCCESS;
}

今天在实际的机器上测试了一下,发现可以连续的发送数据。因为我关闭了控制符号使用原始模式发送。所以没有加回车都可以用。看来上面的问题在虚拟机中会出现。