如何枚舉usb設備
A. usb設備端枚舉,11個標准請求函數實體,6個類請求函數實體
您好,一旦獲悉有新設備連接上來,主機就會發送一系列的請求(Resqusts)給設備所掛載到的hub,再由建立起一條連接主機(Host)和設備(Device)之間的通信通道。然後主機以控制傳輸(Control Transfer)的方式,通過端點0(Endpoint 0)對設備發送各種請求,設備收到主機發來的請求後回復相應的信息,進行枚舉(Enumerate)操作。所有的USB設備必須支持標准請求(StandardRequests),控制傳輸方式(Control Transfer)和端點0(Endpoint 0)。
在講解枚舉之前,先大概說說USB的一種傳輸模式——控制傳輸。這種傳輸在USB中是非常重要的,它要保證數據的正確性,在設備的枚舉過程中都是使用控制傳輸的。控制傳輸分為三個階段:①建立階段。②數據階段。③確認階段。
建立(setup)階段:都是由USB主機發起,它是一個setup數據包,裡麵包含一些數據請求的命令以及一些數據。如果建立階段是輸入請求,那麼數據階段就要輸入數據;如果建立階段是輸出請求,那麼數據階段就要輸出數據。如果在數據階段,即便不需要傳送數據,也要發一個0長度的數據包。數據階段過後就是確認階段。確認階段剛好跟數據階段相反,如果是輸入請求,則它是一個輸出數據包;如果是輸出請求,則它是一個輸入數據包。確認階段用來確認數據的正確傳輸。
B. 如何通過枚舉設備來判斷我的USB已經處在連接狀態
您好,一旦獲悉有新設備連接上來,主機就會發送一系列的請求(Resqusts)給設備所掛載到的hub,再由hub建立起一條連接主機(Host)和設備(Device)之間的通信通道。然後主機以控制傳輸(ControlTransfer)的方式,通過端點0(Endpoint0)對設備發送各種請求,設備收到主機發來的請求後回復相應的信息,進行枚舉(Enumerate)操作。所有的USB設備必須支持標准請求(StandardRequests),控制傳輸方式(ControlTransfer)和端點0(Endpoint0)。在講解枚舉之前,先大概說說USB的一種傳輸模式——控制傳輸。這種傳輸在USB中是非常重要的,它要保證數據的正確性,在設備的枚舉過程中都是使用控制傳輸的。控制傳輸分為三個階段:①建立階段。②數據階段。③確認階段。建立(setup)階段:都是由USB主機發起,它是一個setup數據包,裡麵包含一些數據請求的命令以及一些數據。如果建立階段是輸入請求,那麼數據階段就要輸入數據;如果建立階段是輸出請求,那麼數據階段就要輸出數據。如果在數據階段,即便不需要傳送數據,也要發一個0長度的數據包。數據階段過後就是確認階段。確認階段剛好跟數據階段相反,如果是輸入請求,則它是一個輸出數據包;如果是輸出請求,則它是一個輸入數據包。確認階段用來確認數據的正確傳輸。
C. Linux下怎麼枚舉usb設備
http://jingyan..com/article/fd8044fa3608eb5031137a04.html
-供參考
D. usb設備枚舉
有現成的,希望對你有所幫助
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
// EnumDevice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <guiddef.h>
#include <windows.h>
#include <setupapi.h>
#include <vector>
#include <iostream>
using namespace std;
//U盤 interface class GUID
GUID IID_CLASS_WCEUSBS ={0xa5dcbf10, 0x6530, 0x11d2, 0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed};
BOOL SearchDevice(vector<wstring> &vDevicePath)
{
BOOL bRes = FALSE;
LPGUID pInterfaceGuid = &IID_CLASS_WCEUSBS;
HDEVINFO hDeviceInfo = SetupDiGetClassDevs( pInterfaceGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (INVALID_HANDLE_VALUE == hDeviceInfo)
{
goto Exit;
}
// enum device interface
SP_DEVICE_INTERFACE_DATA spDevInterData; //a structure of device interface data
memset(&spDevInterData, 0x00, sizeof(SP_DEVICE_INTERFACE_DATA));
spDevInterData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
DWORD dwIndex = 0;
while (TRUE)
{
if (!faces( hDeviceInfo,
NULL,
pInterfaceGuid,
dwIndex,
&spDevInterData))
{
if (ERROR_NO_MORE_ITEMS == GetLastError())
{
OutputDebugStringW(L"No more interface");
}
else
{
OutputDebugStringW(L"SetupDiEnumDeviceInterfaces Error");
}
goto Exit;
}
// get length of interface detail info
DWORD dwRequiredLength = 0; //for getting length of inter face detail data
if (!( hDeviceInfo,
&spDevInterData,
NULL,
0,
&dwRequiredLength,
NULL))
{
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
OutputDebugStringW(L"calculate require length");
//goto Exit;
}
}
// get interface detail info
PSP_DEVICE_INTERFACE_DETAIL_DATA pSpDIDetailData; //a pointer to interface detail data
pSpDIDetailData = NULL;
pSpDIDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRequiredLength);
if(NULL == pSpDIDetailData)
{
OutputDebugStringW(L"HeapAlloc Memory Failed");
if (!SetupDiDestroyDeviceInfoList(hDeviceInfo))
{
OutputDebugStringW(L"SetupDiDestroyDeviceInfoList Error");
}
goto Exit;
}
pSpDIDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!( hDeviceInfo,
&spDevInterData,
pSpDIDetailData,
dwRequiredLength,
&dwRequiredLength,
NULL))
{
OutputDebugStringW(L" Error");
goto Exit;
}
wstring wcsDevicePath = pSpDIDetailData->DevicePath;
vDevicePath.push_back(wcsDevicePath);
if (NULL != pSpDIDetailData)
{
HeapFree(GetProcessHeap(), 0, pSpDIDetailData);
pSpDIDetailData = NULL;
}
dwIndex++;
}
if (!SetupDiDestroyDeviceInfoList(hDeviceInfo))
{
OutputDebugStringW(L"SetupDiDestroyDeviceInfoList Error");
}
bRes = TRUE;
Exit:
return bRes;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<wstring> vDevicePath;
SearchDevice(vDevicePath);
vector<wstring>::iterator iter;
for (iter = vDevicePath.begin(); iter != vDevicePath.end(); ++iter)
{
wcout << (*iter).c_str() << endl;
}
system("pause");
return 0;
}
// stdafx.cpp : source file that includes just the standard includes
// EnumDevice.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
E. 怎麼把所有的window所有usb設備的guid枚舉出來
有現成的,希望對你有所幫助
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
// EnumDevice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <guiddef.h>
#include <windows.h>
#include <setupapi.h>
#include <vector>
#include <iostream>
using namespace std;
//U盤 interface class GUID
GUID IID_CLASS_WCEUSBS ={0xa5dcbf10, 0x6530, 0x11d2, 0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed};
BOOL SearchDevice(vector<wstring> &vDevicePath)
{
BOOL bRes = FALSE;
LPGUID pInterfaceGuid = &IID_CLASS_WCEUSBS;
HDEVINFO hDeviceInfo = SetupDiGetClassDevs( pInterfaceGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (INVALID_HANDLE_VALUE == hDeviceInfo)
{
goto Exit;
}
// enum device interface
SP_DEVICE_INTERFACE_DATA spDevInterData; //a structure of device interface data
memset(&spDevInterData, 0x00, sizeof(SP_DEVICE_INTERFACE_DATA));
spDevInterData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
DWORD dwIndex = 0;
while (TRUE)
{
if (!SetupDiEnumDeviceInterfaces( hDeviceInfo,
NULL,
pInterfaceGuid,
dwIndex,
&spDevInterData))
{
if (ERROR_NO_MORE_ITEMS == GetLastError())
{
OutputDebugStringW(L"No more interface");
}
else
{
OutputDebugStringW(L"SetupDiEnumDeviceInterfaces Error");
}
goto Exit;
}
// get length of interface detail info
DWORD dwRequiredLength = 0; //for getting length of inter face detail data
if (!( hDeviceInfo,
&spDevInterData,
NULL,
0,
&dwRequiredLength,
NULL))
{
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
OutputDebugStringW(L"calculate require length");
//goto Exit;
}
}
// get interface detail info
PSP_DEVICE_INTERFACE_DETAIL_DATA pSpDIDetailData; //a pointer to interface detail data
pSpDIDetailData = NULL;
pSpDIDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRequiredLength);
if(NULL == pSpDIDetailData)
{
OutputDebugStringW(L"HeapAlloc Memory Failed");
if (!SetupDiDestroyDeviceInfoList(hDeviceInfo))
{
OutputDebugStringW(L"SetupDiDestroyDeviceInfoList Error");
}
goto Exit;
}
pSpDIDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!( hDeviceInfo,
&spDevInterData,
pSpDIDetailData,
dwRequiredLength,
&dwRequiredLength,
NULL))
{
OutputDebugStringW(L" Error");
goto Exit;
}
wstring wcsDevicePath = pSpDIDetailData->DevicePath;
vDevicePath.push_back(wcsDevicePath);
if (NULL != pSpDIDetailData)
{
HeapFree(GetProcessHeap(), 0, pSpDIDetailData);
pSpDIDetailData = NULL;
}
dwIndex++;
}
if (!SetupDiDestroyDeviceInfoList(hDeviceInfo))
{
OutputDebugStringW(L"SetupDiDestroyDeviceInfoList Error");
}
bRes = TRUE;
Exit:
return bRes;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<wstring> vDevicePath;
SearchDevice(vDevicePath);
vector<wstring>::iterator iter;
for (iter = vDevicePath.begin(); iter != vDevicePath.end(); ++iter)
{
wcout << (*iter).c_str() << endl;
}
system("pause");
return 0;
}
// stdafx.cpp : source file that includes just the standard includes
// EnumDevice.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
F. 如何枚舉出所有USB設備中找到U盤,並取得其邏輯盤符
有現成的,希望對你有所幫助
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
// EnumDevice.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <guiddef.h>
#include <windows.h>
#include <setupapi.h>
#include <vector>
#include <iostream>
using namespace std;
//U盤 interface class GUID
GUID IID_CLASS_WCEUSBS ={0xa5dcbf10, 0x6530, 0x11d2, 0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed};
BOOL SearchDevice(vector<wstring> &vDevicePath)
{
BOOL bRes = FALSE;
LPGUID pInterfaceGuid = &IID_CLASS_WCEUSBS;
HDEVINFO hDeviceInfo = SetupDiGetClassDevs( pInterfaceGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if (INVALID_HANDLE_VALUE == hDeviceInfo)
{
goto Exit;
}
// enum device interface
SP_DEVICE_INTERFACE_DATA spDevInterData; //a structure of device interface data
memset(&spDevInterData, 0x00, sizeof(SP_DEVICE_INTERFACE_DATA));
spDevInterData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
DWORD dwIndex = 0;
while (TRUE)
{
if (!eviceInterfaces( hDeviceInfo,
NULL,
pInterfaceGuid,
dwIndex,
&spDevInterData))
{
if (ERROR_NO_MORE_ITEMS == GetLastError())
{
OutputDebugStringW(L"No more interface");
}
else
{
OutputDebugStringW(L"SetupDiEnumDeviceInterfaces Error");
}
goto Exit;
}
// get length of interface detail info
DWORD dwRequiredLength = 0; //for getting length of inter face detail data
if (!( hDeviceInfo,
&spDevInterData,
NULL,
0,
&dwRequiredLength,
NULL))
{
if (ERROR_INSUFFICIENT_BUFFER != GetLastError())
{
OutputDebugStringW(L"calculate require length");
//goto Exit;
}
}
// get interface detail info
PSP_DEVICE_INTERFACE_DETAIL_DATA pSpDIDetailData; //a pointer to interface detail data
pSpDIDetailData = NULL;
pSpDIDetailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwRequiredLength);
if(NULL == pSpDIDetailData)
{
OutputDebugStringW(L"HeapAlloc Memory Failed");
if (!SetupDiDestroyDeviceInfoList(hDeviceInfo))
{
OutputDebugStringW(L"SetupDiDestroyDeviceInfoList Error");
}
goto Exit;
}
pSpDIDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (!( hDeviceInfo,
&spDevInterData,
pSpDIDetailData,
dwRequiredLength,
&dwRequiredLength,
NULL))
{
OutputDebugStringW(L" Error");
goto Exit;
}
wstring wcsDevicePath = pSpDIDetailData->DevicePath;
vDevicePath.push_back(wcsDevicePath);
if (NULL != pSpDIDetailData)
{
HeapFree(GetProcessHeap(), 0, pSpDIDetailData);
pSpDIDetailData = NULL;
}
dwIndex++;
}
if (!SetupDiDestroyDeviceInfoList(hDeviceInfo))
{
OutputDebugStringW(L"SetupDiDestroyDeviceInfoList Error");
}
bRes = TRUE;
Exit:
return bRes;
}
int _tmain(int argc, _TCHAR* argv[])
{
vector<wstring> vDevicePath;
SearchDevice(vDevicePath);
vector<wstring>::iterator iter;
for (iter = vDevicePath.begin(); iter != vDevicePath.end(); ++iter)
{
wcout << (*iter).c_str() << endl;
}
system("pause");
return 0;
}
// stdafx.cpp : source file that includes just the standard includes
// EnumDevice.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
G. HID設備在USB的枚舉過程
http://www.docin.com/p-293839161.html
論文抄的2.9節有介紹,
H. usb host怎麼做才能開始設備枚舉
做過,剛搞出來了,但是時鍾問有題,用RCC_Getclock函數串口輸出系統時鍾,發現都是不對的。後來內在官網下載了一個容stm32f2xx專用的時鍾配置工具,配置好後直接生成了system_stm32f2xx.c然後替代原來的就可以正常枚舉了。stm32f2xx.h中的外部時鍾定義HSE_Value也要改為實際用的晶振頻率可是插上我的8GU盤,枚舉完成後直接進入Unrecoverederrorstate,還是想找固件的問題,後來看到有人說兼容性問題,找了個1G的U盤,插上去直接就可以讀寫文件了。。這兩天正在搞兼容性,還有官方的FATFS沒有加長文件名支持,很多小寫字母都變大寫了,到時候用原子哥的內存管理讓他支持長文件名。
I. 枚舉USB設備,找到了需要的設備,如何去打開設備
出現USB不能和電腦連接有以下幾情況,同時包括解決打開的方法:
1、開始內——運行容devmgmt.msc(或者右擊我的電腦——屬性)—— 設備管理器——通用串列匯流排控制器---右擊啟用處於停用狀態的USB驅動,啟用即可!
2、 開始--運行里輸入regedit 進入注冊表--[HKEY-LOCAL-MACHINE/SYSTEM/CurrentContolset/Services/USBSTOR]在雙擊右邊start,4為禁止,3為開啟。
3、開機進入BIOS的USB設置,找到Integrated Peripherals Option (外部設備選項),然後進去把裡面有關USB項的值設定為Enable。保存後退重啟電腦,即可開啟!
4、開始——設置——控制面板——程序——看有沒有安裝USB控制大師、超級巡警等usb控制軟體,找到軟體打開進行設置,或者刪除軟體。
J. Linux下如何枚舉usb設備
列出USB設置可以用命令lsusb。
其它不太清楚,感覺你應該看linux驅動編程方面的書吧,不是一兩句就能解決。
