首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > VFP >

usb hid设备数据读取方法,该如何处理

2012-03-30 
usb hid设备数据读取方法试了很多,由于本的vfp水平有限,没有把别人的示例转换成vfp可用的,直接对hid.dll,s

usb hid设备数据读取方法
试了很多,由于本的vfp水平有限,没有把别人的示例转换成vfp可用的,直接对hid.dll,setupapi.dll的调用也都有问题,所以请求高手们出手帮助。这里是一个别人做好的程序,希望能把vb的示例转成vfp的,或者有高手直接对原来的hid.dll,setupapi.dll进行封装。示例地址:http://d.download.csdn.net/down/1483288/inhaos。

[解决办法]
已收到楼主的短消息。。

仔细看了下说明文件,提供有C接口和C++接口,dkfdtf调用的是C++的接口,而在vfp中只能用C接口,C的结构如下:

#pragma pack (push, 4)
typedef struct {
char *DeviceName; // Device name
char *Manufacturer; // Manufacturer
char *SerialNumber; // Serial number
unsigned int VendorID; // Vendor ID
unsigned int ProductID; // Product ID
int InputReportLen; // Length of HID input report (bytes)
int OutputReportLen; // Length of HID output report (bytes)
int Interface; // Interface
int Collection; // Collection 
} mdeviceList2;
#pragma pack (pop,4)

因此,代码要这样写:


Clear 
Declare long GetList in "UsbHidApi.dll" ; 
long VendorID, long ProductID, ; 
string Manufacturer, string SerialNumber, string DeviceName, ; 
string @DeviceList, long MaxDevices 

Declare long malloc in msvcrt.dll long
Declare long free in msvcrt.dll as free2 long

MaxDevices=20

DeviceName=malloc(50 * MaxDevices)
Manufacturer=malloc(50 * MaxDevices)
SerialNumber=malloc(20 * MaxDevices)
*准备pList
pList =""
For x=0 to MaxDevices-1
pList =pList + BinToC(DeviceName+x*50,"4rs")+;
BinToC(Manufacturer +x*50,"4rs")+;
BinToC(SerialNumber +x*20,"4rs")+;
replicate(chr(0), 36-12) 
EndFor 
VendorID=0xFFFF 
ProductID=0xFFFF 
*设备数量
nDevCount = GetList(VendorID, ProductID, NULL, NULL, NULL, @pList ,MaxDevices) 
?"设备数量",nDevCount 

*把名字取出来
Declare long strcpy in msvcrt.dll string@, long
cName=Space(50)
cManu=Space(50)
cNum=Space(20)

For x=0 to nDevCount -1
strcpy(@cName,DeviceName+x*50)
strcpy(@cManu,Manufacturer+x*50)
strcpy(@cNum,SerialNumber +x*20)


?"第"+Transform(x+1)+"个设备",Replicate("=",70)
?"DeviceName",Alltrim(cName)
?"Manufacturer",Alltrim(cManu)
?"SerialNumber",Alltrim(cNum)


?"VendorID",CToBin(Substr(pList,x*36+12+1,4),"4rs")
?"ProductID",CToBin(Substr(pList,x*36+12+5,4),"4rs")
?"InputReportLen",CToBin(Substr(pList,x*36+12+9,4),"4rs")
?"OutputReportLen",CToBin(Substr(pList,x*36+12+13,4),"4rs")
?"Interface",CToBin(Substr(pList,x*36+12+17,4),"4rs")
?"Collection",CToBin(Substr(pList,x*36+12+21,4),"4rs")
EndFor 

free2(DeviceName)
free2(Manufacturer)
free2(SerialNumber)



因此,so,,可惜,,,

楼主自己试一下,有不明之处再联系。
[解决办法]
按 vb 的用法重写了一下,楼主试试看,如果还是不行就没办法了:


#define MAX_DEVICES 10

Declare Long GetList in UsbHidApi.dll ;
Long VendorID, Long ProductID, ;
Long Manufacturer, Long SerialNumber, Long DeviceName, ;
String @DeviceList, Long MaxDevices
Declare Long GlobalAlloc in WIN32API Long uFlags, Long dwBytes
Declare Long GlobalFree in WIN32API Long hMem

Local Array laDevList[MAX_DEVICES]

m.pDevList = ''
For m.ii = 1 To MAX_DEVICES
m.laDevList[m.ii] = GlobalAlloc(0x40, 150)
m.pDevList = m.pDevList ;
+ BinToC(m.laDevList[m.ii], 'rs') ;
+ BinToC(m.laDevList[m.ii] + 50, 'rs') ;
+ BinToC(m.laDevList[m.ii] + 100, 'rs') ;


+ Replicate(Chr(0), 24)
EndFor
m.lnFoundNums = GetList(0xffff, 0xffff, 0, 0, 0, @ m.pDevList, MAX_DEVICES)
Clear
? '找到的设备数:' + Transform(m.lnFoundNums)
For m.ii = 1 To MAX_DEVICES
m.cDevContext = Sys(2600, m.laDevList[m.ii], 150)
GlobalFree( m.laDevList[m.ii] )
? 'Device ' + Transform(m.ii) + ':' ;
+ 0h0d0a09 + 'DeviceName: ' + Trim(Substr(m.cDevContext, 1, 50), Chr(0)) ;
+ 0h0d0a09 + 'Manufacturer: ' + Trim(Substr(m.cDevContext, 51, 50), Chr(0)) ;
+ 0h0d0a09 + 'SerialNumber: ' + Trim(Substr(m.cDevContext, 101, 50), Chr(0)) ;
+ 0h0d0a
EndFor

热点排行