ホーム › Devices.Usb › USB_HUB_PORT_INFORMATION
USB_HUB_PORT_INFORMATION
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| DeviceState | USB_DEVICE_STATE | 4 | +0 | +0 | ポートに接続されたデバイスの状態フラグ。 |
| PortNumber | WORD | 2 | +4 | +4 | ハブ上の物理ポート番号。 |
| DeviceAddress | WORD | 2 | +6 | +6 | デバイスに割り当てられたバスアドレス。 |
| ConnectionIndex | DWORD | 4 | +8 | +8 | 接続インデックス(1始まりのポート番号)。 |
| ConnectionStatus | USB_CONNECTION_STATUS | 4 | +12 | +12 | ポートの接続状態を示す列挙値。 |
各言語での定義
#include <windows.h>
// USB_DEVICE_STATE (x64 4 / x86 4 バイト)
#pragma pack(push, 1)
typedef struct USB_DEVICE_STATE {
DWORD _bitfield;
} USB_DEVICE_STATE;
#pragma pack(pop)
// USB_HUB_PORT_INFORMATION (x64 16 / x86 16 バイト)
#pragma pack(push, 1)
typedef struct USB_HUB_PORT_INFORMATION {
USB_DEVICE_STATE DeviceState;
WORD PortNumber;
WORD DeviceAddress;
DWORD ConnectionIndex;
USB_CONNECTION_STATUS ConnectionStatus;
} USB_HUB_PORT_INFORMATION;
#pragma pack(pop)using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_DEVICE_STATE
{
public uint _bitfield;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_HUB_PORT_INFORMATION
{
public USB_DEVICE_STATE DeviceState;
public ushort PortNumber;
public ushort DeviceAddress;
public uint ConnectionIndex;
public int ConnectionStatus;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_DEVICE_STATE
Public _bitfield As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_HUB_PORT_INFORMATION
Public DeviceState As USB_DEVICE_STATE
Public PortNumber As UShort
Public DeviceAddress As UShort
Public ConnectionIndex As UInteger
Public ConnectionStatus As Integer
End Structureimport ctypes
from ctypes import wintypes
class USB_DEVICE_STATE(ctypes.Structure):
_pack_ = 1
_fields_ = [
("_bitfield", wintypes.DWORD),
]
class USB_HUB_PORT_INFORMATION(ctypes.Structure):
_pack_ = 1
_fields_ = [
("DeviceState", USB_DEVICE_STATE),
("PortNumber", ctypes.c_ushort),
("DeviceAddress", ctypes.c_ushort),
("ConnectionIndex", wintypes.DWORD),
("ConnectionStatus", ctypes.c_int),
]#[repr(C, packed(1))]
pub struct USB_DEVICE_STATE {
pub _bitfield: u32,
}
#[repr(C, packed(1))]
pub struct USB_HUB_PORT_INFORMATION {
pub DeviceState: USB_DEVICE_STATE,
pub PortNumber: u16,
pub DeviceAddress: u16,
pub ConnectionIndex: u32,
pub ConnectionStatus: i32,
}import "golang.org/x/sys/windows"
type USB_DEVICE_STATE struct {
_bitfield uint32
}
type USB_HUB_PORT_INFORMATION struct {
DeviceState USB_DEVICE_STATE
PortNumber uint16
DeviceAddress uint16
ConnectionIndex uint32
ConnectionStatus int32
}type
USB_DEVICE_STATE = packed record
_bitfield: DWORD;
end;
USB_HUB_PORT_INFORMATION = packed record
DeviceState: USB_DEVICE_STATE;
PortNumber: Word;
DeviceAddress: Word;
ConnectionIndex: DWORD;
ConnectionStatus: Integer;
end;const USB_DEVICE_STATE = extern struct {
_bitfield: u32,
};
const USB_HUB_PORT_INFORMATION = extern struct {
DeviceState: USB_DEVICE_STATE,
PortNumber: u16,
DeviceAddress: u16,
ConnectionIndex: u32,
ConnectionStatus: i32,
};type
USB_DEVICE_STATE {.packed.} = object
_bitfield: uint32
USB_HUB_PORT_INFORMATION {.packed.} = object
DeviceState: USB_DEVICE_STATE
PortNumber: uint16
DeviceAddress: uint16
ConnectionIndex: uint32
ConnectionStatus: int32align(1)
struct USB_DEVICE_STATE
{
uint _bitfield;
}
align(1)
struct USB_HUB_PORT_INFORMATION
{
USB_DEVICE_STATE DeviceState;
ushort PortNumber;
ushort DeviceAddress;
uint ConnectionIndex;
int ConnectionStatus;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USB_HUB_PORT_INFORMATION サイズ: 16 バイト(x64)
dim st, 4 ; 4byte整数×4(構造体サイズ 16 / 4 切り上げ)
; DeviceState : USB_DEVICE_STATE (+0, 4byte) varptr(st)+0 を基点に操作(4byte:入れ子/配列)
; PortNumber : WORD (+4, 2byte) wpoke st,4,値 / 値 = wpeek(st,4)
; DeviceAddress : WORD (+6, 2byte) wpoke st,6,値 / 値 = wpeek(st,6)
; ConnectionIndex : DWORD (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; ConnectionStatus : USB_CONNECTION_STATUS (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global USB_DEVICE_STATE, pack=1
#field int _bitfield
#endstruct
#defstruct global USB_HUB_PORT_INFORMATION, pack=1
#field USB_DEVICE_STATE DeviceState
#field short PortNumber
#field short DeviceAddress
#field int ConnectionIndex
#field int ConnectionStatus
#endstruct
stdim st, USB_HUB_PORT_INFORMATION ; NSTRUCT 変数を確保
st->PortNumber = 100
mes "PortNumber=" + st->PortNumber