Win32 API 日本語リファレンス
ホームDevices.Usb › USB_30_HUB_DESCRIPTOR

USB_30_HUB_DESCRIPTOR

構造体
サイズx64: 12 バイト / x86: 12 バイトパッキング1

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
bLengthBYTE1+0+0このディスクリプタのサイズをバイト単位で示す。
bDescriptorTypeBYTE1+1+1ディスクリプタ種別。USB3.0ハブは0x2A。
bNumberOfPortsBYTE1+2+2ハブが持つダウンストリームポート数を示す。
wHubCharacteristicsWORD2+3+3電源管理・過電流保護等のハブ特性ビットフラグを示す。
bPowerOnToPowerGoodBYTE1+5+5ポート電源投入から安定までの時間を2ms単位で示す。
bHubControlCurrentBYTE1+6+6ハブコントローラの最大消費電流をmA単位で示す。
bHubHdrDecLatBYTE1+7+7ハブパケットヘッダのデコード遅延を示す。
wHubDelayWORD2+8+8ハブの遅延をナノ秒単位で示す。
DeviceRemovableWORD2+10+10各ポートのデバイス着脱可否を表すビットマスク。

各言語での定義

#include <windows.h>

// USB_30_HUB_DESCRIPTOR  (x64 12 / x86 12 バイト)
#pragma pack(push, 1)
typedef struct USB_30_HUB_DESCRIPTOR {
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bNumberOfPorts;
    WORD wHubCharacteristics;
    BYTE bPowerOnToPowerGood;
    BYTE bHubControlCurrent;
    BYTE bHubHdrDecLat;
    WORD wHubDelay;
    WORD DeviceRemovable;
} USB_30_HUB_DESCRIPTOR;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_30_HUB_DESCRIPTOR
{
    public byte bLength;
    public byte bDescriptorType;
    public byte bNumberOfPorts;
    public ushort wHubCharacteristics;
    public byte bPowerOnToPowerGood;
    public byte bHubControlCurrent;
    public byte bHubHdrDecLat;
    public ushort wHubDelay;
    public ushort DeviceRemovable;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_30_HUB_DESCRIPTOR
    Public bLength As Byte
    Public bDescriptorType As Byte
    Public bNumberOfPorts As Byte
    Public wHubCharacteristics As UShort
    Public bPowerOnToPowerGood As Byte
    Public bHubControlCurrent As Byte
    Public bHubHdrDecLat As Byte
    Public wHubDelay As UShort
    Public DeviceRemovable As UShort
End Structure
import ctypes
from ctypes import wintypes

class USB_30_HUB_DESCRIPTOR(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("bLength", ctypes.c_ubyte),
        ("bDescriptorType", ctypes.c_ubyte),
        ("bNumberOfPorts", ctypes.c_ubyte),
        ("wHubCharacteristics", ctypes.c_ushort),
        ("bPowerOnToPowerGood", ctypes.c_ubyte),
        ("bHubControlCurrent", ctypes.c_ubyte),
        ("bHubHdrDecLat", ctypes.c_ubyte),
        ("wHubDelay", ctypes.c_ushort),
        ("DeviceRemovable", ctypes.c_ushort),
    ]
#[repr(C, packed(1))]
pub struct USB_30_HUB_DESCRIPTOR {
    pub bLength: u8,
    pub bDescriptorType: u8,
    pub bNumberOfPorts: u8,
    pub wHubCharacteristics: u16,
    pub bPowerOnToPowerGood: u8,
    pub bHubControlCurrent: u8,
    pub bHubHdrDecLat: u8,
    pub wHubDelay: u16,
    pub DeviceRemovable: u16,
}
import "golang.org/x/sys/windows"

type USB_30_HUB_DESCRIPTOR struct {
	bLength byte
	bDescriptorType byte
	bNumberOfPorts byte
	wHubCharacteristics uint16
	bPowerOnToPowerGood byte
	bHubControlCurrent byte
	bHubHdrDecLat byte
	wHubDelay uint16
	DeviceRemovable uint16
}
type
  USB_30_HUB_DESCRIPTOR = packed record
    bLength: Byte;
    bDescriptorType: Byte;
    bNumberOfPorts: Byte;
    wHubCharacteristics: Word;
    bPowerOnToPowerGood: Byte;
    bHubControlCurrent: Byte;
    bHubHdrDecLat: Byte;
    wHubDelay: Word;
    DeviceRemovable: Word;
  end;
const USB_30_HUB_DESCRIPTOR = extern struct {
    bLength: u8,
    bDescriptorType: u8,
    bNumberOfPorts: u8,
    wHubCharacteristics: u16,
    bPowerOnToPowerGood: u8,
    bHubControlCurrent: u8,
    bHubHdrDecLat: u8,
    wHubDelay: u16,
    DeviceRemovable: u16,
};
type
  USB_30_HUB_DESCRIPTOR {.packed.} = object
    bLength: uint8
    bDescriptorType: uint8
    bNumberOfPorts: uint8
    wHubCharacteristics: uint16
    bPowerOnToPowerGood: uint8
    bHubControlCurrent: uint8
    bHubHdrDecLat: uint8
    wHubDelay: uint16
    DeviceRemovable: uint16
align(1)
struct USB_30_HUB_DESCRIPTOR
{
    ubyte bLength;
    ubyte bDescriptorType;
    ubyte bNumberOfPorts;
    ushort wHubCharacteristics;
    ubyte bPowerOnToPowerGood;
    ubyte bHubControlCurrent;
    ubyte bHubHdrDecLat;
    ushort wHubDelay;
    ushort DeviceRemovable;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USB_30_HUB_DESCRIPTOR サイズ: 12 バイト(x64)
dim st, 3    ; 4byte整数×3(構造体サイズ 12 / 4 切り上げ)
; bLength : BYTE (+0, 1byte)  poke st,0,値  /  値 = peek(st,0)
; bDescriptorType : BYTE (+1, 1byte)  poke st,1,値  /  値 = peek(st,1)
; bNumberOfPorts : BYTE (+2, 1byte)  poke st,2,値  /  値 = peek(st,2)
; wHubCharacteristics : WORD (+3, 2byte)  wpoke st,3,値  /  値 = wpeek(st,3)
; bPowerOnToPowerGood : BYTE (+5, 1byte)  poke st,5,値  /  値 = peek(st,5)
; bHubControlCurrent : BYTE (+6, 1byte)  poke st,6,値  /  値 = peek(st,6)
; bHubHdrDecLat : BYTE (+7, 1byte)  poke st,7,値  /  値 = peek(st,7)
; wHubDelay : WORD (+8, 2byte)  wpoke st,8,値  /  値 = wpeek(st,8)
; DeviceRemovable : WORD (+10, 2byte)  wpoke st,10,値  /  値 = wpeek(st,10)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global USB_30_HUB_DESCRIPTOR, pack=1
    #field byte bLength
    #field byte bDescriptorType
    #field byte bNumberOfPorts
    #field short wHubCharacteristics
    #field byte bPowerOnToPowerGood
    #field byte bHubControlCurrent
    #field byte bHubHdrDecLat
    #field short wHubDelay
    #field short DeviceRemovable
#endstruct

stdim st, USB_30_HUB_DESCRIPTOR        ; NSTRUCT 変数を確保
st->bLength = 100
mes "bLength=" + st->bLength