USB上位机通信:CyAPI
2021-06-11 00:02
int epts = USBDevice->EndPointCount();//获取端点
CCyUSBEndPoint *endpt;//定义端点指针
for (i=1; i
endpt = USBDevice->EndPoints[i]; //EndPoints-端点列表,最大16.EndPoints[0]指向控制端点( CCyControlEndPoint)
//未使用的端点设置为NULL
if (endpt->Attributes == 2)
{
sprintf(s, "0x%02X", endpt->Address);
if (endpt->Address & 0x80) //Address--判断传输方向in or out 0x8_-in;0x0_-out
{
m_InEndptComBox.AddString(s); //最高位为8,in端点,添加到in组合框
m_InEndptComBox.SetItemData(m_InEndptComBox.GetCount()-1,i);
}
else
{
m_OutEndptComBox.AddString(s); //否则,最高位为0,out端点,添加到out组合框
m_OutEndptComBox.SetItemData(m_OutEndptComBox.GetCount()-1,i);
}
}
}
CCyUSBDevice *USBDevice =new CCyUSBDevice(m_hWnd); //USB设备
USBDevice->Open(0); //打开0号设备,
CCyUSBEndPoint *endpt = USBDevice->EndPointOf(0X82); //使用端点2,in传输