CyAPI编写程序基础入门

1.首先要建立一个USB设备对象

CCyUSBDevice *USBDevice = new CCyUSBDev(Handle);

2.然后就该是打开USB设备了

如果只有一个USB设备
USBDevice->open(0) //打开0号USB设备

如果要判断,可以:

 if(! USBDevice->open(0)) //打开失败

                      {messagebox("USB未连接");}

如果连接有多个USB设备,那么可以枚举所有的USB,用到DeviceCount()函数;执行USBDevice->DeviceCount()后,返回所连接的USB设备个数:

 if (USBDevice->DeviceCount())   //保证至少有一个USB设备连接
    {
        for (i = 0; i < USBDevice->DeviceCount(); i++)    //枚举所有USB设备
        {
            USBDevice->Open(i);                                     //打开第i号USB设备

            m_DeviceListComBox.AddString(USBDevice->DeviceName);   //所选择的当前设备名
        }

    }

3.端点设置

【1】首先获取所用的端点数目

   int epts = USBDevice->EndPointCount();

EndPointCount();函数返回当前所用的端点数+1,也就是包含了控制端点。例如在固件接口描述符Interface Descriptor中设置Number of end points项(第5项)的值为4,则epts的值为4+1=5

[2] 定义端点指针

  CCyUSBEndPoint *endpt;  

CCyUSBEndPoint 建立一个端点对象,可建立所有的端点类型,控制端点,bulk端点,ISO端点等;

【3】开始枚举端点,并获得其属性:端点号,传输方向

   for (i=1; i<epts; i++)
{    
    endpt = USBDevice->EndPoints[i];    //EndPoints-端点列表,最大16.EndPoints[0]指向控制端点( CCyControlEndPoint)
        //未使用的端点设置为NULL

    if (endpt->Attribut
CyAPI原版资料, CyAPI.lib provides a simple, powerful C++ programming interface to USB devices. More specifically, it is a C++ class library that provides a high-level programming interface to the CyUsb3.sys device driver. The library is only able to communicate with USB devices that are served by (i.e. bound to) this driver. Rather than communicate with the driver via Windows API calls such as SetupDiXxxx and DeviceIoControl, applications can call simpler CyAPI methods such as Open, Close, and XferData to communicate with these USB devices. To use the library, you need to include the header file, CyAPI.h, in files that access the CCyUSBDevice class. In addition, the statically linked CyAPI.lib file must be linked to your project. Versions of the .lib files are available for use with Microsoft Visual Studio 2008. The library employs a Device and EndPoints use model. To use the library you must create an instance of the CCyUSBDevice class using the new keyword. A CCyUSBDevice object knows how many USB devices are attached to the CyUsb3.sys driver and can be made to abstract any one of those devices at a time by using the Open method. An instance of CCyUSBDevice exposes several methods and data members that are device-specific, such as DeviceName, DevClass, VendorID, ProductID, and SetAltIntfc. When a CCyUSBDevice object is open to an attached USB device, its endpoint members provide an interface for performing data transfers to and from the device's endpoints. Endpoint-specific data members and methods such as MaxPktSize, TimeOut, bIn, Reset and XferData are only accessible through endpoint members of a CCyUSBDevice object. In addition to its simplicity, the class library facilitates creation of sophisticated applications as well. The CCyUSBDevice constructor automatically registers the application for Windows USB Plug and Play event notification. This allows your application to support "hot plugging" of devices. Also, the asynchronous BeginDataXfer/WaitForXfer/FinishDataXfer methods allow queuing of multiple data transfer requests on a single endpoint, thus enabling high performance data streaming from the application level
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值