想问一下大家读取USB cy芯片的上位机程序是用什么函数来写的呢??小弟正在学习USB上位机的开发
谁有读取USB数据的代码啊 发我一份学习一下啊``
------解决方案--------------------
如果是 Windows 系统下,不必深入到驱动。只要知道是什么设备类和通讯协议就好了。
在网上有很多例子可以下载。但要先确定是哪一个设备类:Mass Storage, HID, CCID?
如果是 U 转串,那根本就不需要考虑 USB 的问题。会写串口通讯程序就好了。
------解决方案--------------------
同求,本人也找了下这方面的资料。
HDEVINFO info = SetupDiGetClassDevs(&m_GUID, //(LPGUID)&GUID_DEVINTERFACE_MCHPUSB,
NULL,
NULL,
DIGCF_PRESENT|DIGCF_DEVICEINTERFACE);
if(info==INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList(info);
return MPUSB_DEV_NO_INFO;
}// end if
// Get interface data for the requested instance
SP_DEVICE_INTERFACE_DATA intf_data;
intf_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
if(!SetupDiEnumDeviceInterfaces(info,
NULL,
&m_GUID, //(LPGUID)&GUID_DEVINTERFACE_MCHPUSB,
instance,
&intf_data))
{
SetupDiDestroyDeviceInfoList(info);
return MPUSB_DEV_INVALID_INST;
}// end if
// Get size of symbolic link
DWORD ReqLen;
SetupDiGetDeviceInterfaceDetail(info, &intf_data, NULL, 0, &ReqLen, NULL);
PSP_DEVICE_INTERFACE_DETAIL_DATA intf_detail = \
(PSP_DEVICE_INTERFACE_DETAIL_DATA)(new char[ReqLen]);
if( intf_detail == NULL)
{
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return MPUSB_DEV_NO_INFO;
}// end if
// Get symbolic link name
intf_detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
// sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) should equals 5.
// In C++ Builder, go to Project/Options/Advanced Compiler/Data Alignment
// and select "byte" align.
if(!SetupDiGetDeviceInterfaceDetail(info,
&intf_data,
intf_detail,
ReqLen,
NULL,
NULL))
{
SetupDiDestroyDeviceInfoList(info);
delete intf_detail;
return MPUSB_DEV_NO_INFO;
}// end if
SetupDiDestroyDeviceInfoList(info);
// attempt an asynchronous read operation
bResult = WriteFile(hDevHandle,pData,dwLen,&nBytesWritten,&gOverlapped);
bResult = DeviceIoControl(hDevHandle,
EP2_READ,
NULL,
0,
pData,
dwLen,
&nBytesRead,
&gOverlapped);
// attempt an asynchronous read operation
bResult = ReadFile(hDevHandle,pData,dwLen,&nBytesRead,&gOverlapped);
CancelIo(hDevHandle);
简单的运用,但复杂的,如何应用?还是迷茫。
------解决方案--------------------
------解决方案--------------------