这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » [原创]请进——VxWorks串口通讯

共1条 1/1 1 跳转至

[原创]请进——VxWorks串口通讯

菜鸟
2006-08-20 22:51:30     打赏

请各位帮忙指点,以下是代码和错误:

/*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 sfd; /*串口设备文件描述符*/
int accept_com2_ID,send_com2_ID;

/* pre_declaration */
int open_com2 ( ) ;
int config_com2 ( void ) ;
int accept_com2 ( void ) ;
int send_com2 ( void ) ;
// void close ( ) ;
void task1()
{
open_com2();
config_com2();
accept_com2_ID = taskSpawn ("accept", 100, 0, 20000, \
accept_com2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
send_com2_ID = taskSpawn ("send", 100, 0, 20000, \
send_com2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
FOREVER taskDelay(60);
}
/* 打开串口*/

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

{
//int sfd;
/*line 43:*/ sfd = open("/tyCo/1",O_RDWR,0); //打开串口并返回串口设备文件描述符

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

{printf("You can’t open port com1 !");}

}

/* 配置串口*/

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

{
ioctl(sfd,FIOSETOPTIONS,OPT_LINE); //设置串口工作模式为行模式:LINE_MODE
/*OPT_LINE is incleded in iolib.h*/

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

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

//ioctl(sfd,SIO_HW_OPTS_SET,CS8|STOPB|PARENB|PARODD); //设置 8 位数据位,2位停止位,带校验位,奇校验
ioctl (sfd, FIOSETOPTIONS,OPT_ECHO | OPT_CRMOD | OPT_TANDEM | OPT_7_BIT);
}

/* 串口接收数据 */

int accept_com2(void) //从串口1接收数据函数

{
while(1)

{
char *accept_buf;

/*line 77*/ FD_ZERO(&fds_data);//位码置零

FD_SET(sfd,&fds_data);//初始化位码

width=sfd +1; //这里应该如何运用?

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

/*line 85*/ if(select(width,&fds_data,NULL,NULL,NULL)==ERROR)

return(ERROR);

read(sfd, accept_buf,sizeof(accept_buf)); //从串口读字符

printf("accept message is : %s \n\n", accept_buf); //输出接收到的信息
}

}

/* 串口发送数据 */

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

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

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

if(select(width,NULL,&data_fds,NULL,NULL)==ERROR)

return(ERROR) ;

/*line 109*/ if(FD_ISSET(sfd,&data_fds)) //检查串口准备好就向串口写数据

write(sfd,send_buf,sizeof(send_buf)) ;

}

/*关闭串口*/

/*void close()
{
close(sfd);
}
*/
错误提示如下,请帮忙看一下,谢谢!
comment -DCPU_7TDMI_T -DARMMMU=ARMMMU_NONE -DARMCACHE=ARMCACHE_KS32C -c ..\task1.c
"..\task1.c", line 43: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 43: error (dcc:1245): illegal character: 254 (octal)
"..\task1.c", line 43: error (dcc:1633): parse error near '2'
"..\task1.c", line 43: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 43: error (dcc:1245): illegal character: 254 (octal)
"..\task1.c", line 109: warning (dcc:1740): macro `FD_ISSET': argument count does not matc
h. expected 2 but given 1
"..\task1.c", line 77: error (dcc:1525): identifier fds_data not declared
"..\task1.c", line 81: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 81: error (dcc:1245): illegal character: 275 (octal)
"..\task1.c", line 81: error (dcc:1525): identifier sfd not declared
"..\task1.c", line 81: error (dcc:1633): parse error near 'sfd'
"..\task1.c", line 81: warning (dcc:1519): expression not used!
"..\task1.c", line 85: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 85: error (dcc:1245): illegal character: 254 (octal)
"..\task1.c", line 85: error (dcc:1525): identifier width not declared
"..\task1.c", line 85: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 85: error (dcc:1245): illegal character: 254 (octal)
"..\task1.c", line 85: error (dcc:1769): the called object is not a function
"..\task1.c", line 85: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 85: error (dcc:1245): illegal character: 254 (octal)
"..\task1.c", line 85: error (dcc:1245): illegal character: 243 (octal)
"..\task1.c", line 85: fatal error (dcc:1553): too many errors, good bye
make: *** [task1.o] Error 0x1

Done.




关键词: 原创     请进     VxWorks     串口     通讯     #incl    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]