📄 cyusbdll.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 + -