⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comreceive.c

📁 vxworks下串口通信的、程序
💻 C
字号:
#include "vxWorks.h"  /*for vxworks OS*/
#include "stdioLib.h"
#include "ioLib.h"
#include "stdio.h"
#include "ioctl.h"
#include "selectLib.h"
#include "types/vxTypesOld.h"
#include "strLib.h"
#include "string.h"
#include "sioLib.h"
#include "drv\hdisk\ataDrv.h"

void CreatHardDrive();
void Comreceive(void);
void Portinit(void);
int fdd;
FILE *fpp;
int num;
int len;
char accept_buf[1000];
int width;
fd_set fds_data;



void Comreceive(void)
{
	
	/*CreatHardDrive();*/
	
	fdd=open("/tyCo/0",O_RDWR,0);
	
	Portinit();

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

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

	fpp=fopen("/ata0a/com.txt","a+b");

	if(fpp==NULL)printf("openfile erorr");

while(1)
{	
	FD_ZERO(&fds_data);

	FD_SET(fdd,&fds_data);

	width=fdd+1;
if(select(width,&fds_data,NULL,NULL,NULL)==ERROR)printf("ERROR");

num=read(fdd,accept_buf,sizeof(accept_buf));

printf("accept message is : %s \n\n", accept_buf);

len=fwrite(accept_buf,num,1,fpp);

printf("num=%d\n",num);
printf("len=%d\n",len);
}
}
/*void CreatHardDrive()
{
   BLK_DEV *pBlkDev; 
   pBlkDev = ataDevCreate(0, 0, 0, 0);                        
   usrAtaConfig(0, 0, "/ata0"); 
}*/
void Portinit(void)
{ioctl(fdd,FIOSETOPTIONS,OPT_LINE);  
ioctl(fdd,FIOBAUDRATE,9600);      

ioctl(fdd,FIOFLUSH,0);
ioctl(fdd,SIO_HW_OPTS_SET,CS8|STOPB|PARENB|PARODD);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -