导航:首页 > 器材知识 > USB设备如何实现延时枚举

USB设备如何实现延时枚举

发布时间:2021-03-07 18:02:20

❶ 怎么把所有的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 (!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

❷ linux 下如何实现USB设备重新枚举

umount,mount,umount,mount....巴拉巴拉

❸ usb的芯片上的枚举过程是怎样的

{
Sleep(1);
cout<<"ticket 1:"<<ticket--<<endl;
SetEvent(g_hEvent); //设置为有信号(没内有被申容请)
}
else
{SetEvent(g_hEvent); //设置为有信号(没有被申请)
break;
}
}

❹ usb设备端枚举,11个标准请求函数实体,6个类请求函数实体

您好,一旦获悉有新设备连接上来,主机就会发送一系列的请求(Resqusts)给设备所挂载到的hub,再由hub建立起一条连接主机(Host)和设备(Device)之间的通信通道。然后主机以控制传输(Control Transfer)的方式,通过端点0(Endpoint 0)对设备发送各种请求,设备收到主机发来的请求后回复相应的信息,进行枚举(Enumerate)操作。所有的USB设备必须支持标准请求(StandardRequests),控制传输方式(Control Transfer)和端点0(Endpoint 0)。
在讲解枚举之前,先大概说说USB的一种传输模式——控制传输。这种传输在USB中是非常重要的,它要保证数据的正确性,在设备的枚举过程中都是使用控制传输的。控制传输分为三个阶段:①建立阶段。②数据阶段。③确认阶段。
建立(setup)阶段:都是由USB主机发起,它是一个setup数据包,里面包含一些数据请求的命令以及一些数据。如果建立阶段是输入请求,那么数据阶段就要输入数据;如果建立阶段是输出请求,那么数据阶段就要输出数据。如果在数据阶段,即便不需要传送数据,也要发一个0长度的数据包。数据阶段过后就是确认阶段。确认阶段刚好跟数据阶段相反,如果是输入请求,则它是一个输出数据包;如果是输出请求,则它是一个输入数据包。确认阶段用来确认数据的正确传输。

❺ HID设备在USB的枚举过程

http://www.docin.com/p-293839161.html
论文来的源2.9节有介绍,

❻ usb host怎么做才能开始设备枚举

做过,刚搞出来了,但是时钟问有题,用RCC_Getclock函数串口输出系统时钟,发现都是不对的。专后来属在官网下载了一个stm32f2xx专用的时钟配置工具,配置好后直接生成了system_stm32f2xx.c然后替代原来的就可以正常枚举了。stm32f2xx.h中的外部时钟定义HSE_Value也要改为实际用的晶振频率可是插上我的8GU盘,枚举完成后直接进入Unrecoverederrorstate,还是想找固件的问题,后来看到有人说兼容性问题,找了个1G的U盘,插上去直接就可以读写文件了。。这两天正在搞兼容性,还有官方的FATFS没有加长文件名支持,很多小写字母都变大写了,到时候用原子哥的内存管理让他支持长文件名。

❼ usb设备没有驱动程序情况下能否完成枚举

是的先要安装驱动,还有你用的bus hound版本是多少的?可能需要更新了。

❽ usb hid设备从枚举到打开花费多长时间

时间应该不长挺快的啊

❾ 怎么利用USB接口走非USB协议完成枚举

一旦获悉有新设备连接上来,主机就会发送一系列的请求(Resqusts)给设备所挂载到的hub,再由hub建立起一条连接主机(Host)和设备(Device)之间的通信通道。然后主机以控制传输(Control Transfer)的方式,通过端点0(Endpoint 0)对设备发送各种请求,设备收到主机发来的请求后回复相应的信息,进行枚举(Enumerate)操作。所有的USB设备必须支持标准请求(StandardRequests),控制传输方式(Control Transfer)和端点0(Endpoint 0)。

在讲解枚举之前,先大概说说USB的一种传输模式——控制传输。这种传输在USB中是非常重要的,它要保证数据的正确性,在设备的枚举过程中都是使用控制传输的。控制传输分为三个阶段:①建立阶段。②数据阶段。③确认阶段。

建立(setup)阶段:都是由USB主机发起,它是一个setup数据包,里面包含一些数据请求的命令以及一些数据。如果建立阶段是输入请求,那么数据阶段就要输入数据;如果建立阶段是输出请求,那么数据阶段就要输出数据。如果在数据阶段,即便不需要传送数据,也要发一个0长度的数据包。数据阶段过后就是确认阶段。确认阶段刚好跟数据阶段相反,如果是输入请求,则它是一个输出数据包;如果是输出请求,则它是一个输入数据包。确认阶段用来确认数据的正确传输。

❿ 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 (!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

阅读全文

与USB设备如何实现延时枚举相关的资料

热点内容
steam令牌换设备了怎么办 浏览:246
新生测听力仪器怎么看结果 浏览:224
化学试验排水集气法的实验装置 浏览:156
家用水泵轴承位置漏水怎么回事 浏览:131
羊水镜设备多少钱一台 浏览:125
机械制图里型钢如何表示 浏览:19
测定空气中氧气含量实验装置如图所示 浏览:718
超声波换能器等级怎么分 浏览:800
3万轴承是什么意思 浏览:110
鑫旺五金制品厂 浏览:861
苏州四通阀制冷配件一般加多少 浏览:153
江北全套健身器材哪里有 浏览:106
水表阀门不开怎么办 浏览:109
花冠仪表盘怎么显示时速 浏览:106
洗砂机多少钱一台18沃力机械 浏览:489
超声波碎石用什么材料 浏览:607
组装实验室制取二氧化碳的简易装置的方法 浏览:165
怎么知道天然气充不了阀门关闭 浏览:902
公司卖旧设备挂什么科目 浏览:544
尚叶五金机电 浏览:59