CYUSB68013主机程序开发

来源:互联网 发布:数据存储计量单位 编辑:程序博客网 时间:2024/06/04 23:15
  1. 先在电脑上安装Cypress的USB驱动,并获得驱动对应的API。这里使用的是Cypress Suite USB 3.4.7版本的驱动。
  2. 建立VS2012 win32控制台程序,并添加ALT头文件。
    这里写图片描述
    这里写图片描述
  3. VS2012包含头文件和库文件。
    这里写图片描述
  4. 此时编译无法通过,因为头文件和库路径都未指定。将头文件和库文件复制到工程目录下,然后用在
    DEBUG->solution Properties选项卡中设定头文件和库文件路径。
    这里写图片描述
    这里写图片描述

  5. 在C/C++ -> General -> Additional Include Directories下添加头文件路径。
    在Linker -> general -> Additional Library Directories中添加库文件路径。
    在Linker -> Input -> Additional Dependencies中填写库名称。
    注意在编辑路径时最好使用宏定义的路径,方便项目在其他电脑中运行。路径的宏定义可在Macros选项卡下查看。
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述

  6. 至此工程就建好了,按F7编译无误后就可以开发自己的程序了。
  7. 在写程序时首先要创建USBDevice对象,然后设定端点指针。在进行数据传输前先判断USB设备是否open,数据传输结束后记得close USB设备。最后记得delete USB设备,释放内存。
// USB_example1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "CyAPI.h"int _tmain(int argc, _TCHAR* argv[]){    CCyUSBDevice *USBDevice = new CCyUSBDevice(NULL);    CCyControlEndPoint *ept = USBDevice->ControlEndPt;    if(!USBDevice->IsOpen())    {        printf("Device not ok!");        return 255;    }    ept->ReqType = REQ_VENDOR;    ept->Target = TGT_DEVICE;    ept->Direction = DIR_TO_DEVICE;    ept->ReqCode = 0xbb;    ept->Value = 0;    ept->Index = 0;    PUCHAR buf = new UCHAR[2];    ZeroMemory(buf,2);    long len = 2;    buf[0] = 0xc3;    buf[1] = 0x88;    ept->XferData(buf,len);    USBDevice->Close();    delete USBDevice;    return 0;}
原创粉丝点击