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

📄 cyusbdll.cpp

📁 一本关于控制系统仿真的书的程序 1、文件夹1中的程序是书中的一些仿真。 2、文件2中的是最近做的预测控制、PID控制及逻辑控制的对比综合研究。 3、文件夹3中是与maltab通信的数据采集板的设
💻 CPP
字号:
// AddDll.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "CyUsbDll.h"
#include <windows.h>
#include "CyAPI.h"
#include <stdio.h>

//定义最大缓冲区长度,要和单片机的设置一致
//#define BuffSize 512 

int  __stdcall  SendData(int nLen, unsigned char OutBuf[])

{
	CCyUSBDevice  *USBDevice = new  CCyUSBDevice();  

	if(!USBDevice->DeviceCount())
		{
		    printf("没有找到驱动!\n");
	    	return 0;
		}

    OVERLAPPED outOvLap; 
	outOvLap.hEvent  = CreateEvent(NULL, false, false, "CYUSB_OUT");
	LONG  length = nLen; 
	UCHAR  *outContext = USBDevice->BulkOutEndPt->BeginDataXfer(OutBuf, length, &outOvLap); 
	USBDevice->BulkOutEndPt->WaitForXfer(&outOvLap, 100); 
	USBDevice->BulkOutEndPt->FinishDataXfer(OutBuf, length, &outOvLap,outContext); 
	CloseHandle(outOvLap.hEvent); 
	return 1;
}
//计算机接收数据,单片机发送数据
//接收长度为nLen的数据
int  __stdcall  ReceData(int nLen, unsigned char inBuf[])
{
   	CCyUSBDevice  *USBDevice = new  CCyUSBDevice();  

	if(!USBDevice->DeviceCount())
	{
		printf("没有找到驱动!\n");
		return 0;
	}
    OVERLAPPED inOvLap; 
	inOvLap.hEvent   = CreateEvent(NULL, false, false, "CYUSB_IN"); 
	
    ZeroMemory(inBuf, nLen); 
	LONG  length = nLen; 
    UCHAR  *inContext = USBDevice->BulkInEndPt->BeginDataXfer(inBuf, length, &inOvLap); 
    USBDevice->BulkInEndPt->WaitForXfer(&inOvLap,100); 
    USBDevice->BulkInEndPt->FinishDataXfer(inBuf, length, &inOvLap,inContext); 
    CloseHandle(inOvLap.hEvent); 
	//inBuf[5]=55;//此句为测试语句
    return 1;
}

⌨️ 快捷键说明

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