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

不能獲取USB port的連結信息

尚未結案
sampuspeng
一般會員


發表:1
回覆:0
積分:0
註冊:2007-12-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-12-27 13:50:10 IP:210.21.xxx.xxx 訂閱
各位先進:
小弟初涉USB應用程序,在獲取hub的port口連結信息時遇到麻煩,請各位指教。程序的步驟大致如下:
1.獲取USBHostController的handle
AnsiString strName;
char cstrName[50]={'\0'};
strName=strName.sprintf("\\\\.\\HCD%d",nHC);
strcpy(cstrName,strName.c_str());
CreateFile(cstrName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
2.獲取roothub的名稱
ULONG nBytes;
USB_ROOT_HUB_NAME hubname ,*phubname;
//First DeviceIoControl is to get root_hub_name 's true length,however ,hubname is only one byte (constrait by USB_ROOT_HUB_NAME type )this time
if(!DeviceIoControlhHostController,IOCTL_USB_GET_ROOT_HUB_NAME,NULL,0,&hubname,sizeof(hubname),&nBytes,NULL))
{
return false;
}
nBytes=hubname.ActualLength;
phubname=(USB_ROOT_HUB_NAME *)malloc(nBytes);
if(!phubname) return false;
//Second DeviceIoControl is to get root_hub_name and put it into memory allocated.
if(DeviceIoControl(hHostController,IOCTL_USB_GET_ROOT_HUB_NAME,NULL,0,phubname,nBytes,&nBytes,NULL))
{
strRH=String(phubname->RootHubName);
free(phubname);
return true;
}
free(phubname);
3.獲取roothub的handle
char cstrHubName[100]={'\0'};
strHubName="\\\\.\\" strHubName;
strcpy(cstrHubName,strHubName.c_str());
CreateFile(cstrHubName,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
4.獲取roothub的port口數
ULONG nBytes;
info->ConnectionIndex=nPort;
DeviceIoControl(hHub,IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,info,nBytes,info,nBytes,&nBytes,NULL);
5.獲取port口的連結信息
ULONG nBytes;
info->ConnectionIndex=nPort;
DeviceIoControl(hHub,IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,info,nBytes,info,nBytes,&nBytes,NULL);


第1-4步都能正確得到結果,但是第五步DeviceIOControl始終返回false,找不到任何連結設備。事實上我的電腦上插著一些USB設備-鍵盤、鼠標、ez usb-fx2開發板等

請各位不吝賜教。

ikk
尊榮會員


發表:4
回覆:413
積分:768
註冊:2003-06-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-02-26 12:15:42 IP:140.116.xxx.xxx 訂閱
第4與第5是一樣的function? 結果不一樣?

===================引 用 sampuspeng 文 章===================
4.獲取roothub的port口數
ULONG nBytes;
info->ConnectionIndex=nPort;
DeviceIoControl(hHub,IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,info,nBytes,info,nBytes,&nBytes,NULL);
5.獲取port口的連結信息
ULONG nBytes;
info->ConnectionIndex=nPort;
DeviceIoControl(hHub,IOCTL_USB_GET_NODE_CONNECTION_INFORMATION,info,nBytes,info,nBytes,&nBytes,NULL);

------
FPGA驗證, FPGA開發平台, http://smims.com
系統時間:2024-04-26 16:45:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!