应用程序
1.打开设备,并设置端点指针
do {
USBDevice->Open(d); // Open automatically calls Close() if necessary
usb_id = d;
vID = USBDevice->VendorID;
pID = USBDevice->ProductID;
d++;
} while ((d < devices ) && (vID != mVID) && (pID != mPID));
if(usb_id == devices)
AfxMessageBox("没有找到设备!",0);
else
{
int eptCount = USBDevice->EndPointCount();
for (int i=1; i<eptCount; i++)
{
bool bIn = ((USBDevice->EndPoints->Address & 0x80) == 0x80);
bool bBulk = (USBDevice->EndPoints->Attributes == 2);
if (bBulk && bIn) BulkInEpt = (CCyBulkEndPoint *) USBDevice->EndPoints;
if (bBulk && !bIn) BulkOutEpt = (CCyBulkEndPoint *) USBDevice->EndPoints;
}
}
2.BULK发送
OVERLAPPED outOvLap;
outOvLap.hEvent = CreateEvent(NULL, false, false, "CYUSB_OUT");
for(int i=0; i<512; i++)
outBuf = i;
LONG length = 512;
UCHAR *outContext = BulkOutEpt->BeginDataXfer(outBuf, length, &outOvLap);
BulkOutEpt->WaitForXfer(&outOvLap,100);//100ms
bool success;
success = BulkOutEpt->FinishDataXfer(outBuf, length, &outOvLap, outContext);
CloseHandle(outOvLap.hEvent);
3.BULK接收
OVERLAPPED inOvLap;
inOvLap.hEvent = CreateEvent(NULL, false, false, "CYUSB_IN");
ZeroMemory(inBuf, 512);
LONG length = 512;
UCHAR *inContext = BulkInEpt->BeginDataXfer(inBuf, length, &inOvLap);
BulkInEpt->WaitForXfer(&inOvLap,100); //100mS
bool success;
success = BulkInEpt->FinishDataXfer(inBuf, length, &inOvLap,inContext);
CloseHandle(inOvLap.hEvent);
文章评论(0条评论)
登录后参与讨论