C vxworks串行端口读取超时

C vxworks串行端口读取超时,c,vxworks,C,Vxworks,我正在使用安装在UEIPAC 600 1-G机箱上的vxworks。我正在尝试从串行端口读取数据。这是我的密码 void read_serial(int n){ /* store number of bytes read = int n*/ int num=0; /* hold the file descriptor */ int fd = 0; /* dev name from iosDevShow output */ char dev_name[] = "/tyCo/0"; /*

我正在使用安装在UEIPAC 600 1-G机箱上的vxworks。我正在尝试从串行端口读取数据。这是我的密码

void read_serial(int n){
/* store number of bytes read = int n*/  
int num=0;
/* hold the file descriptor */ 
int fd = 0; 
/* dev name from iosDevShow output */ 
char dev_name[] = "/tyCo/0"; 
/* buffer to receive read */ 
char re[n]; 
/* length of string to read */ 
int re_len = n; 
/* open the device for reading. */ 
fd = open( "/tyCo/0", O_RDWR, 0); 
num = read( fd, re, re_len); /* read */ 
close( fd ); /* close */ 
printf("number of bytes read %d\n",num); /* display bytes read*/
printf("displaying the bytes read: %s\n",re);
}
当我运行它时,它只是超时,直到我点击键盘输入,然后像这样输出

number of bytes read 1
displaying the bytes read:
 Pp

如何修复此问题以正确读取串行端口

不检查是否已成功打开串行端口

fd = open( "/tyCo/0", O_RDWR, 0); 
if (fd < 0) {
    /* handle the error */
}
fd=open(“/tyCo/0”,O_RDWR,0);
如果(fd<0){
/*处理错误*/
}
您不检查从串行端口读取是否成功

num = read( fd, re, re_len); /* read */ 
if (num < 0) {
    /* handle the error */
}
num=read(fd,re,re_len);/*阅读*/
if(num<0){
/*处理错误*/
}
您假设从串行端口读取将产生一个可打印的字符串,这可能是不正确的。当您打印从串行端口读取的数据时,您可能应该以十六进制转储数据,以便确定提取了哪些字节值

for (int i = 0; i < num; ++i) {
    printf(" %02x", re[i]);
}
putchar('\n');
for(int i=0;i
fd=open(…)返回的值是多少?你必须检查这一点,而不是盲目地进行下去。我还想知道char dev_name[]=“/tyCo/0”的意义是什么当您甚至不使用它打开时。并且,在发送到
printf
之前,您是否在
re
的末尾放置了
nul
终止符?