線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:8670
推到 Plurk!
推到 Facebook!

delphi read/write usb device (by hid classes)

尚未結案
wzjych
一般會員


發表:2
回覆:0
積分:0
註冊:2005-07-13

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-13 22:59:53 IP:218.18.xxx.xxx 未訂閱
everyone: how to read/write usb device with delphi language,I try to use windows API function to realize,but when i call SetupDiEnumDeviceInterfaces,it always fail,i don't know why?where can i find the delphi program the follows is my program procedure TForm1.Button1Click(Sender: TObject); var gGuid:TGuid; ghDevInfo:HDEVINFO; MemberIndex:DWORD; DeviceInterfaceData:TSPDeviceInterfaceData; ifDetail:PSPDeviceInterfaceData; length:DWORD; begin HidD_GetHidGuid(gGuid); ghDevInfo:=SetupDiGetClassDevs(@gGuid,nil,0,DIGCF_PRESENT OR DIGCF_INTERFACEDEVICE); if (ghDevInfo=nil) then begin showmessage('ERROR,the program will exit'); exit; end else begin showmessage('SUCCESS'); end; DeviceInterfaceData.cbSize:=sizeof(DeviceInterfaceData); //showmessage(inttostr(DeviceInterfaceData.cbSize)); if (SetupDiEnumDeviceInterfaces(ghDevInfo,0,gGuid,MemberIndex,DeviceInterfaceData)=False) then begin showmessage('can't find hid device'); if MemberIndex<>0 then showmessage(inttostr(MemberIndex)); end; SetupDiGetDeviceInterfaceDetail(ghDevInfo,@DeviceInterfaceData,nil,0,@length,nil); ...... end; although i plug a hid device,the funcion SetupDiEnumDeviceInterfaces always return fail,i don't know why? wzjych
------
wzjych
deity
尊榮會員


發表:90
回覆:876
積分:678
註冊:2003-05-09

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-14 10:17:51 IP:218.15.xxx.xxx 未訂閱
wzjych您好:
 if (SetupDiEnumDeviceInterfaces(ghDevInfo,0,gGuid,MemberIndex,DeviceInterfaceData)=False) then
    begin
      showmessage('can"t find hid device'); //改'为"
      if MemberIndex<>0 then
        showmessage(inttostr(MemberIndex));
    end;
小弟对usb device的读取没实践过,不过您可以参考下面: http://delphi.ktop.com.tw/topic.php?topic_id=38317 http://delphi.ktop.com.tw/topic.php?topic_id=63380 hope helpful! ============================ 为什么经过多年以后,得失的过程如此冷漠 ============================
lsu
一般會員


發表:1
回覆:14
積分:3
註冊:2003-03-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-17 17:29:16 IP:218.56.xxx.xxx 未訂閱
http://www.efg2.com/Lab/Library/Delphi/IO/PortIO.htm
pcboy
版主


發表:177
回覆:1838
積分:1463
註冊:2004-01-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-11-01 10:10:27 IP:61.220.xxx.xxx 訂閱
小弟編譯後出現下面錯誤, 請問是否要 uses 甚麼? 或者放甚麼元件? 或要做其他事情 ?
[Error] Unit1.pas(29): Undeclared identifier: 'HDEVINFO'
[Error] Unit1.pas(31): Undeclared identifier: 'TSPDeviceInterfaceData'
[Error] Unit1.pas(32): Undeclared identifier: 'PSPDeviceInterfaceData'
[Error] Unit1.pas(35): Undeclared identifier: 'HidD_GetHidGuid'
[Error] Unit1.pas(36): Undeclared identifier: 'SetupDiGetClassDevs'
[Error] Unit1.pas(36): Undeclared identifier: 'DIGCF_PRESENT'
[Error] Unit1.pas(36): Undeclared identifier: 'DIGCF_INTERFACEDEVICE'
[Warning] Unit1.pas(36): Combining signed and unsigned types - widened both operands
[Error] Unit1.pas(37): Operator not applicable to this operand type
[Error] Unit1.pas(47): Missing operator or semicolon
[Error] Unit1.pas(49): Undeclared identifier: 'SetupDiEnumDeviceInterfaces'
[Error] Unit1.pas(55): Undeclared identifier: 'SetupDiGetDeviceInterfaceDetail'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
------
能力不足,求助於人;有能力時,幫幫別人;如果您滿意答覆,請適時結案!

子曰:問有三種,不懂則問,雖懂有疑則問,雖懂而想知更多則問!
編輯記錄
pcboy 重新編輯於 2007-11-01 10:11:05, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-12-17 17:00:09 IP:125.215.xxx.xxx 訂閱
<code>
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, ExtCtrls, StdCtrls;

type
TForm1 = class(TForm)
Label1: TLabel;
private
{ Private declarations }
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WMDeviceChange (var Msg: TMessage);
var
myMsg : String;
begin
Case Msg.WParam of
32768:
begin
myMsg :='U盘插入';
Label1.Caption:=myMsg
end;
32772:
begin
myMsg :='U盘拔出';
Label1.Caption:=myMsg;
end;
end;
end;

end.


希望对你有用。
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
HUNK999
初階會員


發表:9
回覆:35
積分:28
註冊:2009-07-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2009-08-17 13:50:23 IP:220.130.xxx.xxx 訂閱
2009 .Net HID library C++ VB C#
http://sites.google.com/site/hidlibrary/
yazoo571
一般會員


發表:5
回覆:3
積分:1
註冊:2005-03-24

發送簡訊給我
#7 引用回覆 回覆 發表時間:2010-02-19 09:32:16 IP:59.120.xxx.xxx 訂閱
系統時間:2024-04-27 5:14:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!