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

SERIAL_STATUS

構造体
サイズx64: 20 バイト / x86: 20 バイト

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

フィールド

フィールドサイズx64x86説明
ErrorsDWORD4+0+0発生中の通信エラー要因を示すフラグの組み合わせ。
HoldReasonsDWORD4+4+4送信が保留されている理由を示すフラグの組み合わせ。
AmountInInQueueDWORD4+8+8受信キューに残っているバイト数を表す。
AmountInOutQueueDWORD4+12+12送信キューに残っているバイト数を表す。
EofReceivedBOOLEAN1+16+16EOF文字を受信したか否かを示す。
WaitForImmediateBOOLEAN1+17+17即時送信文字の送出待機中か否かを示す。

各言語での定義

#include <windows.h>

// SERIAL_STATUS  (x64 20 / x86 20 バイト)
typedef struct SERIAL_STATUS {
    DWORD Errors;
    DWORD HoldReasons;
    DWORD AmountInInQueue;
    DWORD AmountInOutQueue;
    BOOLEAN EofReceived;
    BOOLEAN WaitForImmediate;
} SERIAL_STATUS;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERIAL_STATUS
{
    public uint Errors;
    public uint HoldReasons;
    public uint AmountInInQueue;
    public uint AmountInOutQueue;
    [MarshalAs(UnmanagedType.U1)] public bool EofReceived;
    [MarshalAs(UnmanagedType.U1)] public bool WaitForImmediate;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SERIAL_STATUS
    Public Errors As UInteger
    Public HoldReasons As UInteger
    Public AmountInInQueue As UInteger
    Public AmountInOutQueue As UInteger
    <MarshalAs(UnmanagedType.U1)> Public EofReceived As Boolean
    <MarshalAs(UnmanagedType.U1)> Public WaitForImmediate As Boolean
End Structure
import ctypes
from ctypes import wintypes

class SERIAL_STATUS(ctypes.Structure):
    _fields_ = [
        ("Errors", wintypes.DWORD),
        ("HoldReasons", wintypes.DWORD),
        ("AmountInInQueue", wintypes.DWORD),
        ("AmountInOutQueue", wintypes.DWORD),
        ("EofReceived", ctypes.c_byte),
        ("WaitForImmediate", ctypes.c_byte),
    ]
#[repr(C)]
pub struct SERIAL_STATUS {
    pub Errors: u32,
    pub HoldReasons: u32,
    pub AmountInInQueue: u32,
    pub AmountInOutQueue: u32,
    pub EofReceived: u8,
    pub WaitForImmediate: u8,
}
import "golang.org/x/sys/windows"

type SERIAL_STATUS struct {
	Errors uint32
	HoldReasons uint32
	AmountInInQueue uint32
	AmountInOutQueue uint32
	EofReceived byte
	WaitForImmediate byte
}
type
  SERIAL_STATUS = record
    Errors: DWORD;
    HoldReasons: DWORD;
    AmountInInQueue: DWORD;
    AmountInOutQueue: DWORD;
    EofReceived: ByteBool;
    WaitForImmediate: ByteBool;
  end;
const SERIAL_STATUS = extern struct {
    Errors: u32,
    HoldReasons: u32,
    AmountInInQueue: u32,
    AmountInOutQueue: u32,
    EofReceived: u8,
    WaitForImmediate: u8,
};
type
  SERIAL_STATUS {.bycopy.} = object
    Errors: uint32
    HoldReasons: uint32
    AmountInInQueue: uint32
    AmountInOutQueue: uint32
    EofReceived: uint8
    WaitForImmediate: uint8
struct SERIAL_STATUS
{
    uint Errors;
    uint HoldReasons;
    uint AmountInInQueue;
    uint AmountInOutQueue;
    ubyte EofReceived;
    ubyte WaitForImmediate;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SERIAL_STATUS サイズ: 20 バイト(x64)
dim st, 5    ; 4byte整数×5(構造体サイズ 20 / 4 切り上げ)
; Errors : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; HoldReasons : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; AmountInInQueue : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; AmountInOutQueue : DWORD (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; EofReceived : BOOLEAN (+16, 1byte)  poke st,16,値  /  値 = peek(st,16)
; WaitForImmediate : BOOLEAN (+17, 1byte)  poke st,17,値  /  値 = peek(st,17)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global SERIAL_STATUS
    #field int Errors
    #field int HoldReasons
    #field int AmountInInQueue
    #field int AmountInOutQueue
    #field bool1 EofReceived
    #field bool1 WaitForImmediate
#endstruct

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