vxworks串口通信 帮帮忙啊!!!

gcdxlb 2008-04-18 09:27:40
本人初学VxWorks,前不久刚安装了虚拟机,运行也正常,WDB_COMM_END
现在想试一个与串口进行通信的例子,我所用的程序在下面,编译下载都没有问题,串口助手也打开并且

设置了,
可是依次运行open_com1,config_com1和send_com1后串口却没有反应(没有任何显示),要写向串口的数

据却在shell下显示了,
不知这是什么原因呢?对串口的操作不就是对文件的操作吗?
拜托各位大虾和斑竹一定帮帮忙啊,能说的详细些就更好了,谢谢、谢谢、谢谢了!!!!!!!

/*uart.c--serious transimiting or receiving*/

/*头文件*/

#include <vxWorks.h>
#include "strLib.h"
#include <string.h>
#include <sioLib.h>
#include <ioLib.h>
#include <stdio.h>
#include <ioctl.h>
#include <selectLib.h>
#include <taskLib.h >
#include "types/vxTypesOld.h"

/* global variables */

int width;
int fd; /*串口设备文件描述符*/
int accept_com1_ID,send_com1_ID;
struct fd_set fds_data;
struct fd_set data_fds;
/* pre_declaration */
int open_com1 ( ) ;
int config_com1 ( void ) ;
int accept_com1 ( void ) ;
int send_com1 ( void ) ;
extern STATUS close(fd);



/* 打开串口*/

int open_com1() /*打开串口2函数 */

{
int fd;
fd = open("/tyCo/0",O_CREAT|O_RDWR,0); /*打开串口并返回串口设备文件描述符*/

if(fd==ERROR) /*如果不能打开串口1则打印出错信息*/

printf("You can’t open port com1!\n");
else printf("open Com1 successfully!\n");

}

/* 配置串口*/

int config_com1(void) /*串口1配置函数*/

{
ioctl(fd,FIOSETOPTIONS,OPT_LINE); /*设置串口工作模式为行模式:LINE_MODE */


/*OPT_LINE is incleded in iolib.h*/

ioctl(fd,FIOBAUDRATE,9600); /*设置串口波特率为9600bps*/

ioctl(fd,FIOFLUSH,0); /*清空输入输出缓冲*/

ioctl(fd,SIO_HW_OPTS_SET,CS8|STOPB|PARENB|PARODD); /*设置 8 位数据位,2位停止位

,带校验位,奇校验*/
ioctl (fd, FIOSETOPTIONS,OPT_ECHO | OPT_CRMOD | OPT_TANDEM | OPT_7_BIT);
printf("set options successfully\n");
}

/* 串口接收数据 */



/* 串口发送数据 */

int send_com1(void) /*向串口1发送数据函数*/

{
char *send_buf ="Hello,Data had accept!"; /*待发送数据*/

write(fd,send_buf,strlen(send_buf));

/*任务阻塞等待写串口准备完毕*/


}

/*关闭串口*/

extern STATUS close(fd)
{
close(fd);
}
...全文
1097 8 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluehydra 2008-05-08
  • 打赏
  • 举报
回复
这错误有点低级吧 =_=
UltraBejing 2008-05-01
  • 打赏
  • 举报
回复
接分是王道!
gcdxlb 2008-04-25
  • 打赏
  • 举报
回复
谢谢各位的帮忙了,全局文件描述符确实是有问题,而且还发现了原来我所用机器的串口有问题。唉,机器太古老了!
再次谢谢各位了!
rogerzzhang 2008-04-22
  • 打赏
  • 举报
回复
既然定义了全局的fd变量,为何又在open_com1时定义了一个局部变量呢?

这样的话,config_com1,send_com1等的操作对象fd都是未被初始化的,自然不行了。
ganyong2000 2008-04-20
  • 打赏
  • 举报
回复
把你的iosFdShow, devs之类的信息贴出来。
可能是全局文件描述符的问题
gcdxlb 2008-04-20
  • 打赏
  • 举报
回复
太感谢你的帮忙了!!!
在shell下的运行情况是这样的:

///// ///// ///// ///// ///// |
///// ///// ///// ///// ///// |
///// ///// ///// ///// ///// |
///// ///// ///// ///// ///// |
////// ////// ////// ////// ////// |
////// ////// ////// ////// ////// | T O R N A D O
///// ///// ///// ///// ///// |
///// ///// ///// ///// ///// |
///// ///// ///// ///// ///// | Development System
//// //// //// //// //// |
//// //// //// //// //// |
//// //// //// //// //// | Host Based Shell
//// //// //// //// //// |
//// //// //// //// //// |
/// /// /// /// /// | Version 2.2
/// /// /// /// /// |
// // // // // |
// // // // // |
// // // // // |
// // // // // |

Copyright 1995-2002 Wind River Systems, Inc.

C++ Constructors/Destructors Strategy is AUTOMATIC

-> open_com1
open Com1 successfully!
value = 24 = 0x18
-> config_com1
set options successfully
value = 25 = 0x19
-> send_com1
Hello,Data had accept!
-> iosFdShow
fd name drv
3 /pcConsole/0 2
4 (socket) 5
5 /vio/1 9
6 /tyCo/0 1
7 /vio/2 9
8 /tyCo/0 1
9 /tyCo/0 1
value = 0 = 0x0
-> devs
drv name
0 /null
1 /tyCo/0
1 /tyCo/1
2 /pcConsole/0
2 /pcConsole/1
4 /fd0
6 as:
9 /vio
value = 0 = 0x0
->
发帖
VxWorks

2156

社区成员

xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
帖子事件
创建了帖子
2008-04-18 09:27
社区公告
暂无公告