怎樣讀取USB盤符的相關信息?

LiangWu25 2005-03-16 12:30:19
當我判斷出一個盤符為USB盤符時,我怎樣做才能得到它的相關信息:VID,PID,型號?
Thanks!
...全文
520 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
LiangWu25 2005-03-25
  • 打赏
  • 举报
回复
xingtong(白清):
如要招聘,請另行開貼!
LiangWu25 2005-03-23
  • 打赏
  • 举报
回复
究竟怎样才能取得一个USB盘符的相关硬件信息呢?
roger_ding 2005-03-23
  • 打赏
  • 举报
回复
不是每个USB都有Serial Number的,而且即使有也不是唯一的
LiuMang2005 2005-03-21
  • 打赏
  • 举报
回复
up
LiangWu25 2005-03-21
  • 打赏
  • 举报
回复
up
LiangWu25 2005-03-17
  • 打赏
  • 举报
回复
up
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
這個工具顯示的Serial Number不是我的USB設備定義的Serial Number,看來我要放棄這種做法了。謝謝大家,希望大家再幫忙頂頂。
ahjoe 2005-03-16
  • 打赏
  • 举报
回复
我曾写过这样的代码,不在手边,晚上回去找找。
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
ly_liuyang(Liu Yang),謝謝你,這個工具可以找到我要的USB信息,不過你能否提供部分源碼嗎?而且這個工具給了我一個提示,我先看看能否通過Serail Number來確定設備路徑。Thanks!
ly_liuyang 2005-03-16
  • 打赏
  • 举报
回复
这个工具能满足你需要么?
http://ly.activepower.net/projects/DriverInfo.exe

http://lysoft.7u7.net
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
我現在需要的結果是,當一般的U盤和我的USB設備都插入PC時,我的程序能夠區分哪個USB盤符是我的USB設備,而且有一點就是這個USB設備沒有自己的PC驅動,是用的操作系統的通用驅動。
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
ly_liuyang(Liu Yang),查找注冊表的方式我已經放棄了。我現在使用的USB設備,調用的是通用的USB驅動,我沒辦法根據注冊表中對應的GUID來定位設備路徑,也不知道怎樣取設備信息。
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
呵呵,回復半天發不出去,一發就發兩個。
ly_liuyang 2005-03-16
  • 打赏
  • 举报
回复
上面的是USB红外设备,与U盘有关系的?

注册表有部分U盘信息的

完整的需要驱动支持,考虑使用WinDriver来开发吧

http://lysoft.7u7.net
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
謝謝aiirii(ari-求职广州中)。在解壓后的文件中uuirtdrv.dll是一個什么樣的Dll?另外,我看了你貼的代碼,我覺得這個Dll把讀取USB信息的地方封裝起來了,加在本地代碼中不是很安全。我現在的想路是,用CreateFile取得驅動器句柄,再用DeviceIoControl取得USB盤符信息,但是DeviceIoControl這個API中的控制碼不知道是如何定義的?在這篇文章中有一些相關內容:http://blog.csdn.net/bhw98/archive/2003/05/27/19664.aspx,
但是它的那個控制碼IOCTL_STORAGE_QUERY_PROPERTY不知道是怎么在定義。
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
謝謝aiirii(ari-求??州中)。在解壓后的文件中uuirtdrv.dll是一個什么樣的Dll?另外,我看了你貼的代碼,我覺得這個Dll把讀取USB信息的地方封裝起來了,我覺得不是很安全。我現在的想路是,用CreateFile取得驅動器句柄,再用DeviceIoControl取得USB盤符信息,但是DeviceIoControl這個API中的控制碼不知道是如何定義的?在這篇文章中有一些相關內容:http://blog.csdn.net/bhw98/archive/2003/05/27/19664.aspx,
但是它的那個控制碼IOCTL_STORAGE_QUERY_PROPERTY不知道是怎么在定義。
aiirii 2005-03-16
  • 打赏
  • 举报
回复
procedure TUIRT.closeUIRT;
begin
if FDrvHandle <> 0 then
UUIRTClose(FDrvHandle);
end;

// ---------------------------------------------------------------

procedure TUIRT.transmit(IRCode: string);
var
res: longint;
IRCodeFormat: longint;
begin

If FDrvHandle = 0 then
raise Exception.Create('(TUIRT.transmit) UIRT communication handle is null.');

IRCodeFormat := UUIRTDRV_IRFMT_UUIRT;
res := UUIRTTransmitIR(FDrvHandle,
PChar(IRCode),
IRCodeFormat,
1,
0,
0,
0,
0);

if res = 0 then
raise Exception.Create('(TUIRT.transmit) UIRT transmit failed.');
end;

http://www.usbuirt.com/latestAPIDriver.zip
aiirii 2005-03-16
  • 打赏
  • 举报
回复
procedure TUIRT.openUIRT;
var
drvAPIVersion: longint;
drvDLLVersion: longint;
res: longint;
dllErr: longint;
sErrMsg: string;
// tlp: TLongPtr;
begin

// Get USB-UIRT *driver* information. Note that this call does not actually
// communicate with the USB-UIRT hardware. Instead, its purpose is solely to
// retrieve version information about the API *driver*. This and GetDrvVersion are
// the only API calls (besides UUIRTOpen) which can be performed without a driver
// handle (prior to opening the driver via UUIRTOpen).
res := UUIRTGetDrvInfo(drvAPIVersion);
if res = 0 then
raise Exception.Create('(TUIRT.open) Unable to retrieve uuirtdrv version!');

// Check the API version. This Application is written to be compatible with
// driver API version 1.0 (0x100)
if drvAPIVersion <> $100 then
raise Exception.Create('(TUIRT.open) Invalid uuirtdrv version!');

// Get the Driver DLL Revision #. This is necessary for this VB app since it this
// app relies on a newer feature of the LearnIR() function which does not block. This
// new non-blocking ability is only available in DLL versions 2.6.1 or later.
// note: This API call does not exist in versions prior to 2.6.1, so we use try/except
// to trap this condition.
res := 0;

try
res := UUIRTGetDrvVersion(drvDLLVersion);
except
On E: Exception do; // Swallow exception.
end;

if (res = 0) or (drvDLLVersion < 2610) then
raise Exception.Create(
'(TUIRT.open) This application requires USB-UIRT API driver DLL (UUIRTDRV.DLL) version 2.6.1 or later. ' +
CRLF +
'Please verify you are running the latest API DLL and that you''re using the latest version of USB-UIRT firmware!' +
CRLF +
'If the problem persists, contact Technical Support!');

// Open a communications link with the USB-UIRT...
// Obtain a handle to the USB-UIRT via the UUIRTOpen call. if successful, a handle
// is returned which we *must* use in all subsequent APi calls.
FDrvHandle := UUIRTOpen();

// FDrvHandle := 0;
// FUIRTCommThread := TUIRTCommThread.Create(Self);

// if Open call failed, we will be returned an INVALID_HANDLE_VALUE and need to look
// at the error to determine what went wrong...
if FDrvHandle = INVALID_HANDLE_VALUE then
begin
// Get the last DLL error using the WIN API GetLastError() call.
dllErr := GetLastError();

if dllErr = UUIRTDRV_ERR_NO_DLL then
sErrMsg := ('Unable to find USB-UIRT Driver. Please make sure driver is Installed!')
else if dllErr = UUIRTDRV_ERR_NO_DEVICE then
sErrMsg := ('Unable to connect to USB-UIRT device! Please ensure device is connected to the computer!')
else if dllErr = UUIRTDRV_ERR_NO_RESP then
sErrMsg := ('Unable to communicate with USB-UIRT device! Please check connections and try again. if you still have problems, try unplugging and reconnecting your USB-UIRT. if problem persists, contact Technical Support!')
else if dllErr = UUIRTDRV_ERR_VERSION then
sErrMsg := ('Your USB-UIRT//s firmware is not compatible with this API DLL. Please verify you are running the latest API DLL and that you//re using the latest version of USB-UIRT firmware! if problem persists, contact Technical Support!')
else
sErrMsg := ('Unable to initialize USB-UIRT (unknown error)!');

raise Exception.Create('(TUIRT.open) ' + sErrMsg);
end
else
begin
// NOTE!!!: Learn function sample code and associated callback usage is not implemented yet.

// if Open was successful, we//ll want to register a receive callback function
// for the USB-UIRT API to call each time an IR code is received.
// res = UUIRTSetReceiveCallback(hDrvHandle, AddressOf IRReceiveCallback, Me);
end;
end;
aiirii 2005-03-16
  • 打赏
  • 举报
回复
沒測試,看能不能用:

unit UIRT;

interface

uses SysUtils, Classes, Windows, SyncObjs;

// USB-UIRT DLL API Constants...
const
CRLF: string = '\r\n';

INVALID_HANDLE_VALUE: integer = -1;
ERROR_IO_PENDING: integer = 997;
UUIRTDRV_ERR_NO_DEVICE: integer = $20000001;
UUIRTDRV_ERR_NO_RESP: integer = $20000002;
UUIRTDRV_ERR_NO_DLL: integer = $20000003;
UUIRTDRV_ERR_VERSION: integer = $20000004;

UUIRTDRV_CFG_LEDRX: integer = $1;
UUIRTDRV_CFG_LEDTX: integer = $2;
UUIRTDRV_CFG_LEGACYRX: integer = $4;

UUIRTDRV_IRFMT_UUIRT: integer = $0;
UUIRTDRV_IRFMT_PRONTO: integer = $10;

UUIRTDRV_IRFMT_LEARN_FORCERAW: integer = $100;
UUIRTDRV_IRFMT_LEARN_FORCESTRUC: integer = $200;
UUIRTDRV_IRFMT_LEARN_FORCEFREQ: integer = $400;
UUIRTDRV_IRFMT_LEARN_FREQDETECT: integer = $800;

UUIRTDRV_IRFMT_TRANSMIT_DC: integer = $80;

type
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Structure definitions:

// Define a structure for received IR codes.
// Received IR codes are 12-ASCII bytes longint, and are passed via a callback
// as a null-terminted string. Since VB handles strings differently, we
// define a byte array and convert it to a VB string inside the callback function.
tIRCode = record
codeData: array[0..15] of byte;
end;
TDynamicIRCodeArray = array of tIRCode;

// Define a structure to hold UUINFO data for the UUIRTGetUUIRTInfo function call...
tUuInfo = record
fwVersion: longint;
protVersion: longint;
fwDateDay: byte;
fwDateMonth: byte;
fwDateYear: byte;
end;
TDynamicUuInfoArray = array of tUuInfo;

TUIRTCommThread = class;

TUIRT = class
private
FDrvHandle: longint; // Handle used to communicate with the UIRT.
FUIRTCommThread: TUIRTCommThread;
protected
// Open the UIRT and get version information from it.
procedure openUIRT;
procedure closeUIRT;
public
constructor Create;
destructor Destroy; override;

procedure transmit(IRCode: string);
end;

TUIRTCommThread = class(TThread)
protected
FUIRT: TUIRT;
public
constructor Create(uirt: TUIRT);
procedure Execute; override;
end;

implementation

type
TLongPtr = ^longint;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// USB-UIRT DLL API Function Declarations....

// function UUIRTGetDrvInfo(var uVersion: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetDrvVersion';
function UUIRTGetDrvInfo(var uVersion: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetDrvInfo';

function UUIRTGetDrvVersion(var uVersion: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetDrvVersion';

function UUIRTOpen : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTOpen';

// function UUIRTOpen : TLongPtr; stdcall; external 'uuirtdrv.dll' name 'UUIRTOpen';

function UUIRTClose(hHandle: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTClose';

function UUIRTGetUUIRTInfo(hHandle: longint; var UuInfo: tUuInfo) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetUUIRTInfo';

function UUIRTGetUUIRTConfig(hHandle: longint; var uConfig: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTGetUUIRTConfig';

function UUIRTSetUUIRTConfig(hHandle: longint; uConfig: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTSetUUIRTConfig';

function UUIRTTransmitIR(
hHandle: longint;
sIRCode: PChar;
uCodeFormat: longint;
uRepeatCount: longint;
uInactivityWaitTime: longint;
hEvent: longint;
reserved0: longint;
reserved1: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTTransmitIR';

function UUIRTLearnIR(
hHandle: longint;
uCodeFormat: longint;
szIRCode: longint;
pProgressProc: longint;
userData: longint;
var pAbort: boolean;
uParam1: longint;
hEvent: longint;
reserved0: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTLearnIR';

function UUIRTSetReceiveCallback(
hHandle: longint;
pReceiveProc: longint;
userData: longint) : longint; stdcall; external 'uuirtdrv.dll' name 'UUIRTSetReceiveCallback';


// ---------------------------------------------------------------

constructor TUIRT.Create;
begin
inherited Create;

openUIRT;
end;

destructor TUIRT.Destroy;
begin
closeUIRT;

inherited Destroy;
end;
LiangWu25 2005-03-16
  • 打赏
  • 举报
回复
up
加载更多回复(1)

2,640

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 硬件/系统
社区管理员
  • 硬件/系统社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧