一 驱动安装、cyapi.lib库的使用
1 接入开发板,安装驱动程序:在设备管理器中选中未识别的USB设备->更新驱动程序->选择驱动程序所在目录
2 安装Cypress SDK(下载地址:http://dlm.cypress.com.edgesuite.net/akdlm/downloadmanager/software/FX3SDKSetup_1.3.4.exe)
SDK中包含所有需要的库、头文件、帮助文档、案例等。
3 参考Cypress USBSuite Application Development Guide中C++ Library CyAPI.lib的使用教程,利用vs构建测试程序。
4 构建Visual C++ > Windows Forms Application工程时,vs2012版本不支持,解决方案:
1. Make a "CLR Empty Project". 2. Press Ctrl-Shift-A and create a Windows Form (under UI). 4. Inside the CPP file that is created, paste this code, replacing anything in square brackets except "[STAThread]" with the appropriate names:
5. Right click your project in the Solution Explorer and click Properties. 6. Under Configuration Properties > Linker > Advanced, change Entry Point to "main" (without quotation marks). 7. Under Configuration Properties > Linker > System, change SubSystem to "Windows (/SUBSYSTEM/WINDOWS)". |
或者
|
5 按照教程中操作完毕后,编译报如下错误:
1>MyForm.cpp(7): warning C4829: 函数 main 的参数可能不正确。请考虑使用“int main(Platform::Array<Platform::String^>^ argv)”
1> .NETFramework,Version=v4.5.AssemblyAttributes.cpp
1>MyForm.obj : error LNK2028: 无法解析的标记(0A00005C) "public: __thiscall CCyUSBDevice::CCyUSBDevice(void *,struct _GUID,int)" (??0CCyUSBDevice@@$$FQAE@PAXU_GUID@@H@Z),该标记在函数 "public: void __clrcall Project2::MyForm::GetDevice(void)" (?GetDevice@MyForm@Project2@@$$FQ$AAMXXZ) 中被引用
1>MyForm.obj : error LNK2028: 无法解析的标记(0A00005D) "public: unsigned char __thiscall CCyUSBDevice::DeviceCount(void)" (?DeviceCount@CCyUSBDevice@@$$FQAEEXZ),该标记在函数 "public: void __clrcall Project2::MyForm::GetDevice(void)" (?GetDevice@MyForm@Project2@@$$FQ$AAMXXZ) 中被引用
1>MyForm.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall CCyUSBDevice::CCyUSBDevice(void *,struct _GUID,int)" (??0CCyUSBDevice@@$$FQAE@PAXU_GUID@@H@Z),该符号在函数 "public: void __clrcall Project2::MyForm::GetDevice(void)" (?GetDevice@MyForm@Project2@@$$FQ$AAMXXZ) 中被引用
1>MyForm.obj : error LNK2019: 无法解析的外部符号 "public: unsigned char __thiscall CCyUSBDevice::DeviceCount(void)" (?DeviceCount@CCyUSBDevice@@$$FQAEEXZ),该符号在函数 "public: void __clrcall Project2::MyForm::GetDevice(void)" (?GetDevice@MyForm@Project2@@$$FQ$AAMXXZ) 中被引用
1>F:\test\Project2\Debug\Project2.exe : fatal error LNK1120: 4 个无法解析的外部命令
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========
6 新建x64调试器,重新编译,报如下错误:
1>------ 已启动全部重新生成: 项目: Project2, 配置: Debug x64 ------
1> MyForm.cpp
1>MyForm.cpp(7): warning C4829: 函数 main 的参数可能不正确。请考虑使用“int main(Platform::Array<Platform::String^>^ argv)”
1> .NETFramework,Version=v4.5.AssemblyAttributes.cpp
1>CyAPI.lib(CyAPI.obj) : error LNK2019: 无法解析的外部符号 __imp_SetupDiDestroyDeviceInfoList,该符号在函数 "public: unsigned char __cdecl CCyUSBDevice::DeviceCount(void)" (?DeviceCount@CCyUSBDevice@@QEAAEXZ) 中被引用
1>CyAPI.lib(CyAPI.obj) : error LNK2019: 无法解析的外部符号 __imp_SetupDiEnumDeviceInterfaces,该符号在函数 "public: unsigned char __cdecl CCyUSBDevice::DeviceCount(void)" (?DeviceCount@CCyUSBDevice@@QEAAEXZ) 中被引用
1>CyAPI.lib(CyAPI.obj) : error LNK2019: 无法解析的外部符号 __imp_SetupDiGetClassDevsA,该符号在函数 "public: unsigned char __cdecl CCyUSBDevice::DeviceCount(void)" (?DeviceCount@CCyUSBDevice@@QEAAEXZ) 中被引用
1>CyAPI.lib(CyAPI.obj) : error LNK2019: 无法解析的外部符号 __imp_SetupDiGetDeviceInterfaceDetailA,该符号在函数 "public: bool __cdecl CCyUSBDevice::CreateHandle(unsigned char)" (?CreateHandle@CCyUSBDevice@@QEAA_NE@Z) 中被引用
1>F:\test\Project2\x64\Debug\Project2.exe : fatal error LNK1120: 4 个无法解析的外部命令
========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========
7 在项目属性页 链接器->输入中加入 User32.Lib;setupapi.lib,编译通过,运行结果如下:
二 cyapi.lib的使用