m_idVendor = 0x4448;
m_idProduct = 0x5916;
m_pBus = NULL;
m_pDevice = NULL;
m_pDeviceHandle = NULL;
// 初始化usb
usb_init();
usb_find_busses();
usb_find_devices();
usb_set_debug(255);
BOOL bGet = FALSE;
for (m_pBus = usb_get_busses(); m_pBus; m_pBus = m_pBus->next)
{
for (m_pDevice = m_pBus->devices; m_pDevice; m_pDevice = m_pDevice->next)
{
if(m_pDevice->descriptor.idVendor == m_idVendor && m_pDevice->descriptor.idProduct == m_idProduct)
{
bGet = TRUE;
break;
}
}
}
if (!bGet)
return communicateNotGetVIDAndPID;
m_pDeviceHandle = usb_open(m_pDevice);
if (m_pDeviceHandle == INVALID_HANDLE_VALUE)
return communicateOpenUSBError;
if (usb_set_configuration(m_pDeviceHandle, 1) != 0)
return communicateOpenUSBError;
if (usb_claim_interface(m_pDeviceHandle, 0) != 0)
return communicateOpenUSBError;
m_idVendor = 0x4448;
m_idProduct = 0x5916;
int nSendBytes = usb_bulk_write(m_pDeviceHandle, m_nSendEndPoint, (char*)pSendBuffer, nSendCount, m_nTimeout);
int nRecvBytes = usb_bulk_read(m_pDeviceHandle, m_nRecvEndPoint, (char*)pRecvBuffer, nRecvCount, m_nTimeout);
int nClose = usb_close(m_pDeviceHandle);