当前位置:首页 » 生产设备 » 如何枚举usb设备

如何枚举usb设备

发布时间: 2021-02-04 19:05:56

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驱动编程方面的书吧,不是一两句就能解决。

热点内容
线切割怎么导图 发布:2021-03-15 14:26:06 浏览:709
1台皮秒机器多少钱 发布:2021-03-15 14:25:49 浏览:623
焊接法兰如何根据口径配螺栓 发布:2021-03-15 14:24:39 浏览:883
印章雕刻机小型多少钱 发布:2021-03-15 14:22:33 浏览:395
切割机三五零木工貝片多少钱 发布:2021-03-15 14:22:30 浏览:432
加工盗砖片什么榉好 发布:2021-03-15 14:16:57 浏览:320
北洋机器局制造的银元什么样 发布:2021-03-15 14:16:52 浏览:662
未来小七机器人怎么更新 发布:2021-03-15 14:16:33 浏览:622
rexroth加工中心乱刀怎么自动调整 发布:2021-03-15 14:15:05 浏览:450
机械键盘的键帽怎么选 发布:2021-03-15 14:15:02 浏览:506