我写了一个代码来访问FPGA上的LED。无论如何,我无法在Visual Studio中成功编译以下代码:
#ifdef STATS_LIBRARY_EXPORTS
# define LIBRARY_API __declspec(dllexport)
#else
# define LIBRARY_API __declspec(dllimport)
#endif
#include <windows.h>
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include "C:\Cypress\Cypress Suite USB 3.4.7\CyAPI\inc\CyAPI.h"
_declspec(dllexport) int excite_LED(bool start, int on) {
int i;
USB_Open();
for(i=0; i<100; i++) // blink the LEDs for a few seconds
{
USB_BulkWrite(2, &i, 1); // send one single byte (= the value of i) to FIFO2
Sleep(50); // and wait 50ms
BulkOutPipe2->XferData((PUCHAR)&i, len); // send one byte (the value of i) to FIFO2
//Send command to FPGA
//status = !BulkOutPipe2->XferData(fpgaCommunicator, fpgaCommunicatorBytes);
}
USB_Close();
}
我收到以下错误:
left of '->XferData' must point to class/struct/union/generic type
identifier "USB_Open" is undefined
identifier "USB_Close" is undefined
identifier "USB_BulkWrite" is undefined
identifier "len" is undefined
identifier "BulkOutPipe2" is undefined
cannot open source file "stdafx.h"
'USB_Open': identifier not found
'USB_Close': identifier not found
'USB_BulkWrite': identifier not found
'len': undeclared identifier
'BulkOutPipe2': undeclared identifier
如何修复我的代码以摆脱这些错误?
答案 0 :(得分:0)
BulkOutPipe2是许多示例中EndPoint 3的常见定义,但未在CyAPI.h中设置,因此您需要自己设置:
#define BulkOutPipe2 USBDevice->EndPoints[3]
您需要初始化: CCyUSBDevice * USBDevice = new CCyUSBDevice(NULL,...);
Len也没有定义:
LONG len= 512000;
USB_BulkWrite(和其他USB_)看起来像usb_bulk_write,它是libusb api的一部分。但是你试图使用CyApi(这是很多不同的),所以删除那些方法调用。