ホーム › Devices.Usb › USB_NODE_CONNECTION_INFORMATION
USB_NODE_CONNECTION_INFORMATION
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| ConnectionIndex | DWORD | 4 | +0 | +0 | 問い合わせ対象のハブポート番号を示す。 |
| DeviceDescriptor | USB_DEVICE_DESCRIPTOR | 18 | +4 | +4 | 接続デバイスのデバイスディスクリプタを格納する。 |
| CurrentConfigurationValue | BYTE | 1 | +22 | +22 | 現在選択中のコンフィギュレーション値を示す。 |
| LowSpeed | BOOLEAN | 1 | +23 | +23 | デバイスがロースピードか示す真偽値。 |
| DeviceIsHub | BOOLEAN | 1 | +24 | +24 | 接続デバイスがハブか示す真偽値。 |
| DeviceAddress | WORD | 2 | +25 | +25 | デバイスのバスアドレスを示す。 |
| NumberOfOpenPipes | DWORD | 4 | +27 | +27 | 開いているパイプの数を示す。 |
| ConnectionStatus | USB_CONNECTION_STATUS | 4 | +31 | +31 | ポートの接続状態を示すUSB_CONNECTION_STATUS列挙値。 |
| PipeList | USB_PIPE_INFO | 11 | +35 | +35 | 各パイプの情報を格納するUSB_PIPE_INFO配列。 |
各言語での定義
#include <windows.h>
// USB_DEVICE_DESCRIPTOR (x64 18 / x86 18 バイト)
#pragma pack(push, 1)
typedef struct USB_DEVICE_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
WORD bcdUSB;
BYTE bDeviceClass;
BYTE bDeviceSubClass;
BYTE bDeviceProtocol;
BYTE bMaxPacketSize0;
WORD idVendor;
WORD idProduct;
WORD bcdDevice;
BYTE iManufacturer;
BYTE iProduct;
BYTE iSerialNumber;
BYTE bNumConfigurations;
} USB_DEVICE_DESCRIPTOR;
#pragma pack(pop)
// USB_ENDPOINT_DESCRIPTOR (x64 7 / x86 7 バイト)
#pragma pack(push, 1)
typedef struct USB_ENDPOINT_DESCRIPTOR {
BYTE bLength;
BYTE bDescriptorType;
BYTE bEndpointAddress;
BYTE bmAttributes;
WORD wMaxPacketSize;
BYTE bInterval;
} USB_ENDPOINT_DESCRIPTOR;
#pragma pack(pop)
// USB_PIPE_INFO (x64 11 / x86 11 バイト)
#pragma pack(push, 1)
typedef struct USB_PIPE_INFO {
USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
DWORD ScheduleOffset;
} USB_PIPE_INFO;
#pragma pack(pop)
// USB_NODE_CONNECTION_INFORMATION (x64 46 / x86 46 バイト)
#pragma pack(push, 1)
typedef struct USB_NODE_CONNECTION_INFORMATION {
DWORD ConnectionIndex;
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
BYTE CurrentConfigurationValue;
BOOLEAN LowSpeed;
BOOLEAN DeviceIsHub;
WORD DeviceAddress;
DWORD NumberOfOpenPipes;
USB_CONNECTION_STATUS ConnectionStatus;
USB_PIPE_INFO PipeList[1];
} USB_NODE_CONNECTION_INFORMATION;
#pragma pack(pop)using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_DEVICE_DESCRIPTOR
{
public byte bLength;
public byte bDescriptorType;
public ushort bcdUSB;
public byte bDeviceClass;
public byte bDeviceSubClass;
public byte bDeviceProtocol;
public byte bMaxPacketSize0;
public ushort idVendor;
public ushort idProduct;
public ushort bcdDevice;
public byte iManufacturer;
public byte iProduct;
public byte iSerialNumber;
public byte bNumConfigurations;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_ENDPOINT_DESCRIPTOR
{
public byte bLength;
public byte bDescriptorType;
public byte bEndpointAddress;
public byte bmAttributes;
public ushort wMaxPacketSize;
public byte bInterval;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_PIPE_INFO
{
public USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
public uint ScheduleOffset;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_NODE_CONNECTION_INFORMATION
{
public uint ConnectionIndex;
public USB_DEVICE_DESCRIPTOR DeviceDescriptor;
public byte CurrentConfigurationValue;
[MarshalAs(UnmanagedType.U1)] public bool LowSpeed;
[MarshalAs(UnmanagedType.U1)] public bool DeviceIsHub;
public ushort DeviceAddress;
public uint NumberOfOpenPipes;
public int ConnectionStatus;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public USB_PIPE_INFO[] PipeList;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_DEVICE_DESCRIPTOR
Public bLength As Byte
Public bDescriptorType As Byte
Public bcdUSB As UShort
Public bDeviceClass As Byte
Public bDeviceSubClass As Byte
Public bDeviceProtocol As Byte
Public bMaxPacketSize0 As Byte
Public idVendor As UShort
Public idProduct As UShort
Public bcdDevice As UShort
Public iManufacturer As Byte
Public iProduct As Byte
Public iSerialNumber As Byte
Public bNumConfigurations As Byte
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_ENDPOINT_DESCRIPTOR
Public bLength As Byte
Public bDescriptorType As Byte
Public bEndpointAddress As Byte
Public bmAttributes As Byte
Public wMaxPacketSize As UShort
Public bInterval As Byte
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_PIPE_INFO
Public EndpointDescriptor As USB_ENDPOINT_DESCRIPTOR
Public ScheduleOffset As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_NODE_CONNECTION_INFORMATION
Public ConnectionIndex As UInteger
Public DeviceDescriptor As USB_DEVICE_DESCRIPTOR
Public CurrentConfigurationValue As Byte
<MarshalAs(UnmanagedType.U1)> Public LowSpeed As Boolean
<MarshalAs(UnmanagedType.U1)> Public DeviceIsHub As Boolean
Public DeviceAddress As UShort
Public NumberOfOpenPipes As UInteger
Public ConnectionStatus As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public PipeList() As USB_PIPE_INFO
End Structureimport ctypes
from ctypes import wintypes
class USB_DEVICE_DESCRIPTOR(ctypes.Structure):
_pack_ = 1
_fields_ = [
("bLength", ctypes.c_ubyte),
("bDescriptorType", ctypes.c_ubyte),
("bcdUSB", ctypes.c_ushort),
("bDeviceClass", ctypes.c_ubyte),
("bDeviceSubClass", ctypes.c_ubyte),
("bDeviceProtocol", ctypes.c_ubyte),
("bMaxPacketSize0", ctypes.c_ubyte),
("idVendor", ctypes.c_ushort),
("idProduct", ctypes.c_ushort),
("bcdDevice", ctypes.c_ushort),
("iManufacturer", ctypes.c_ubyte),
("iProduct", ctypes.c_ubyte),
("iSerialNumber", ctypes.c_ubyte),
("bNumConfigurations", ctypes.c_ubyte),
]
class USB_ENDPOINT_DESCRIPTOR(ctypes.Structure):
_pack_ = 1
_fields_ = [
("bLength", ctypes.c_ubyte),
("bDescriptorType", ctypes.c_ubyte),
("bEndpointAddress", ctypes.c_ubyte),
("bmAttributes", ctypes.c_ubyte),
("wMaxPacketSize", ctypes.c_ushort),
("bInterval", ctypes.c_ubyte),
]
class USB_PIPE_INFO(ctypes.Structure):
_pack_ = 1
_fields_ = [
("EndpointDescriptor", USB_ENDPOINT_DESCRIPTOR),
("ScheduleOffset", wintypes.DWORD),
]
class USB_NODE_CONNECTION_INFORMATION(ctypes.Structure):
_pack_ = 1
_fields_ = [
("ConnectionIndex", wintypes.DWORD),
("DeviceDescriptor", USB_DEVICE_DESCRIPTOR),
("CurrentConfigurationValue", ctypes.c_ubyte),
("LowSpeed", ctypes.c_byte),
("DeviceIsHub", ctypes.c_byte),
("DeviceAddress", ctypes.c_ushort),
("NumberOfOpenPipes", wintypes.DWORD),
("ConnectionStatus", ctypes.c_int),
("PipeList", USB_PIPE_INFO * 1),
]#[repr(C, packed(1))]
pub struct USB_DEVICE_DESCRIPTOR {
pub bLength: u8,
pub bDescriptorType: u8,
pub bcdUSB: u16,
pub bDeviceClass: u8,
pub bDeviceSubClass: u8,
pub bDeviceProtocol: u8,
pub bMaxPacketSize0: u8,
pub idVendor: u16,
pub idProduct: u16,
pub bcdDevice: u16,
pub iManufacturer: u8,
pub iProduct: u8,
pub iSerialNumber: u8,
pub bNumConfigurations: u8,
}
#[repr(C, packed(1))]
pub struct USB_ENDPOINT_DESCRIPTOR {
pub bLength: u8,
pub bDescriptorType: u8,
pub bEndpointAddress: u8,
pub bmAttributes: u8,
pub wMaxPacketSize: u16,
pub bInterval: u8,
}
#[repr(C, packed(1))]
pub struct USB_PIPE_INFO {
pub EndpointDescriptor: USB_ENDPOINT_DESCRIPTOR,
pub ScheduleOffset: u32,
}
#[repr(C, packed(1))]
pub struct USB_NODE_CONNECTION_INFORMATION {
pub ConnectionIndex: u32,
pub DeviceDescriptor: USB_DEVICE_DESCRIPTOR,
pub CurrentConfigurationValue: u8,
pub LowSpeed: u8,
pub DeviceIsHub: u8,
pub DeviceAddress: u16,
pub NumberOfOpenPipes: u32,
pub ConnectionStatus: i32,
pub PipeList: [USB_PIPE_INFO; 1],
}import "golang.org/x/sys/windows"
type USB_DEVICE_DESCRIPTOR struct {
bLength byte
bDescriptorType byte
bcdUSB uint16
bDeviceClass byte
bDeviceSubClass byte
bDeviceProtocol byte
bMaxPacketSize0 byte
idVendor uint16
idProduct uint16
bcdDevice uint16
iManufacturer byte
iProduct byte
iSerialNumber byte
bNumConfigurations byte
}
type USB_ENDPOINT_DESCRIPTOR struct {
bLength byte
bDescriptorType byte
bEndpointAddress byte
bmAttributes byte
wMaxPacketSize uint16
bInterval byte
}
type USB_PIPE_INFO struct {
EndpointDescriptor USB_ENDPOINT_DESCRIPTOR
ScheduleOffset uint32
}
type USB_NODE_CONNECTION_INFORMATION struct {
ConnectionIndex uint32
DeviceDescriptor USB_DEVICE_DESCRIPTOR
CurrentConfigurationValue byte
LowSpeed byte
DeviceIsHub byte
DeviceAddress uint16
NumberOfOpenPipes uint32
ConnectionStatus int32
PipeList [1]USB_PIPE_INFO
}type
USB_DEVICE_DESCRIPTOR = packed record
bLength: Byte;
bDescriptorType: Byte;
bcdUSB: Word;
bDeviceClass: Byte;
bDeviceSubClass: Byte;
bDeviceProtocol: Byte;
bMaxPacketSize0: Byte;
idVendor: Word;
idProduct: Word;
bcdDevice: Word;
iManufacturer: Byte;
iProduct: Byte;
iSerialNumber: Byte;
bNumConfigurations: Byte;
end;
USB_ENDPOINT_DESCRIPTOR = packed record
bLength: Byte;
bDescriptorType: Byte;
bEndpointAddress: Byte;
bmAttributes: Byte;
wMaxPacketSize: Word;
bInterval: Byte;
end;
USB_PIPE_INFO = packed record
EndpointDescriptor: USB_ENDPOINT_DESCRIPTOR;
ScheduleOffset: DWORD;
end;
USB_NODE_CONNECTION_INFORMATION = packed record
ConnectionIndex: DWORD;
DeviceDescriptor: USB_DEVICE_DESCRIPTOR;
CurrentConfigurationValue: Byte;
LowSpeed: ByteBool;
DeviceIsHub: ByteBool;
DeviceAddress: Word;
NumberOfOpenPipes: DWORD;
ConnectionStatus: Integer;
PipeList: array[0..0] of USB_PIPE_INFO;
end;const USB_DEVICE_DESCRIPTOR = extern struct {
bLength: u8,
bDescriptorType: u8,
bcdUSB: u16,
bDeviceClass: u8,
bDeviceSubClass: u8,
bDeviceProtocol: u8,
bMaxPacketSize0: u8,
idVendor: u16,
idProduct: u16,
bcdDevice: u16,
iManufacturer: u8,
iProduct: u8,
iSerialNumber: u8,
bNumConfigurations: u8,
};
const USB_ENDPOINT_DESCRIPTOR = extern struct {
bLength: u8,
bDescriptorType: u8,
bEndpointAddress: u8,
bmAttributes: u8,
wMaxPacketSize: u16,
bInterval: u8,
};
const USB_PIPE_INFO = extern struct {
EndpointDescriptor: USB_ENDPOINT_DESCRIPTOR,
ScheduleOffset: u32,
};
const USB_NODE_CONNECTION_INFORMATION = extern struct {
ConnectionIndex: u32,
DeviceDescriptor: USB_DEVICE_DESCRIPTOR,
CurrentConfigurationValue: u8,
LowSpeed: u8,
DeviceIsHub: u8,
DeviceAddress: u16,
NumberOfOpenPipes: u32,
ConnectionStatus: i32,
PipeList: [1]USB_PIPE_INFO,
};type
USB_DEVICE_DESCRIPTOR {.packed.} = object
bLength: uint8
bDescriptorType: uint8
bcdUSB: uint16
bDeviceClass: uint8
bDeviceSubClass: uint8
bDeviceProtocol: uint8
bMaxPacketSize0: uint8
idVendor: uint16
idProduct: uint16
bcdDevice: uint16
iManufacturer: uint8
iProduct: uint8
iSerialNumber: uint8
bNumConfigurations: uint8
USB_ENDPOINT_DESCRIPTOR {.packed.} = object
bLength: uint8
bDescriptorType: uint8
bEndpointAddress: uint8
bmAttributes: uint8
wMaxPacketSize: uint16
bInterval: uint8
USB_PIPE_INFO {.packed.} = object
EndpointDescriptor: USB_ENDPOINT_DESCRIPTOR
ScheduleOffset: uint32
USB_NODE_CONNECTION_INFORMATION {.packed.} = object
ConnectionIndex: uint32
DeviceDescriptor: USB_DEVICE_DESCRIPTOR
CurrentConfigurationValue: uint8
LowSpeed: uint8
DeviceIsHub: uint8
DeviceAddress: uint16
NumberOfOpenPipes: uint32
ConnectionStatus: int32
PipeList: array[1, USB_PIPE_INFO]align(1)
struct USB_DEVICE_DESCRIPTOR
{
ubyte bLength;
ubyte bDescriptorType;
ushort bcdUSB;
ubyte bDeviceClass;
ubyte bDeviceSubClass;
ubyte bDeviceProtocol;
ubyte bMaxPacketSize0;
ushort idVendor;
ushort idProduct;
ushort bcdDevice;
ubyte iManufacturer;
ubyte iProduct;
ubyte iSerialNumber;
ubyte bNumConfigurations;
}
align(1)
struct USB_ENDPOINT_DESCRIPTOR
{
ubyte bLength;
ubyte bDescriptorType;
ubyte bEndpointAddress;
ubyte bmAttributes;
ushort wMaxPacketSize;
ubyte bInterval;
}
align(1)
struct USB_PIPE_INFO
{
USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
uint ScheduleOffset;
}
align(1)
struct USB_NODE_CONNECTION_INFORMATION
{
uint ConnectionIndex;
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
ubyte CurrentConfigurationValue;
ubyte LowSpeed;
ubyte DeviceIsHub;
ushort DeviceAddress;
uint NumberOfOpenPipes;
int ConnectionStatus;
USB_PIPE_INFO[1] PipeList;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USB_NODE_CONNECTION_INFORMATION サイズ: 46 バイト(x64)
dim st, 12 ; 4byte整数×12(構造体サイズ 46 / 4 切り上げ)
; ConnectionIndex : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; DeviceDescriptor : USB_DEVICE_DESCRIPTOR (+4, 18byte) varptr(st)+4 を基点に操作(18byte:入れ子/配列)
; CurrentConfigurationValue : BYTE (+22, 1byte) poke st,22,値 / 値 = peek(st,22)
; LowSpeed : BOOLEAN (+23, 1byte) poke st,23,値 / 値 = peek(st,23)
; DeviceIsHub : BOOLEAN (+24, 1byte) poke st,24,値 / 値 = peek(st,24)
; DeviceAddress : WORD (+25, 2byte) wpoke st,25,値 / 値 = wpeek(st,25)
; NumberOfOpenPipes : DWORD (+27, 4byte) lpoke st,27,値 / 値 = lpeek(st,27)
; ConnectionStatus : USB_CONNECTION_STATUS (+31, 4byte) lpoke st,31,値 / 値 = lpeek(st,31)
; PipeList : USB_PIPE_INFO (+35, 11byte) varptr(st)+35 を基点に操作(11byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global USB_DEVICE_DESCRIPTOR, pack=1
#field byte bLength
#field byte bDescriptorType
#field short bcdUSB
#field byte bDeviceClass
#field byte bDeviceSubClass
#field byte bDeviceProtocol
#field byte bMaxPacketSize0
#field short idVendor
#field short idProduct
#field short bcdDevice
#field byte iManufacturer
#field byte iProduct
#field byte iSerialNumber
#field byte bNumConfigurations
#endstruct
#defstruct global USB_ENDPOINT_DESCRIPTOR, pack=1
#field byte bLength
#field byte bDescriptorType
#field byte bEndpointAddress
#field byte bmAttributes
#field short wMaxPacketSize
#field byte bInterval
#endstruct
#defstruct global USB_PIPE_INFO, pack=1
#field USB_ENDPOINT_DESCRIPTOR EndpointDescriptor
#field int ScheduleOffset
#endstruct
#defstruct global USB_NODE_CONNECTION_INFORMATION, pack=1
#field int ConnectionIndex
#field USB_DEVICE_DESCRIPTOR DeviceDescriptor
#field byte CurrentConfigurationValue
#field bool1 LowSpeed
#field bool1 DeviceIsHub
#field short DeviceAddress
#field int NumberOfOpenPipes
#field int ConnectionStatus
#field USB_PIPE_INFO PipeList 1
#endstruct
stdim st, USB_NODE_CONNECTION_INFORMATION ; NSTRUCT 変数を確保
st->ConnectionIndex = 100
mes "ConnectionIndex=" + st->ConnectionIndex