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

DCB

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

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

フィールド

フィールドサイズx64x86説明
DCBlengthDWORD4+0+0この構造体のバイト単位サイズ。使用前にsizeofで設定する必要がある。
BaudRateDWORD4+4+4通信のボーレートをbps単位で示す。
_bitfieldDWORD4+8+8fBinary・fParity・各種フロー制御フラグ等を格納するビットフィールド。
wReservedWORD2+12+12予約フィールド。0を設定する必要がある。
XonLimWORD2+14+14XON送信(受信再開)を行う受信バッファ下限バイト数を示す。
XoffLimWORD2+16+16XOFF送信(受信停止)を行う受信バッファ上限バイト数を示す。
ByteSizeBYTE1+18+181文字あたりのデータビット数を示す。通常4〜8。
ParityDCB_PARITY1+19+19パリティ方式を示す列挙値。なし・偶数・奇数・マーク・スペース。
StopBitsDCB_STOP_BITS1+20+20ストップビット数を示す列挙値。1・1.5・2を表す。
XonCharCHAR1+21+21XON文字(送受信再開)に使用する文字コード。
XoffCharCHAR1+22+22XOFF文字(送受信停止)に使用する文字コード。
ErrorCharCHAR1+23+23パリティエラー時に置換する文字コード。fErrorChar有効時のみ。
EofCharCHAR1+24+24データ終端を示す文字コード。
EvtCharCHAR1+25+25イベントを発生させる文字コード。
wReserved1WORD2+26+26予約フィールド。0を設定する。

各言語での定義

#include <windows.h>

// DCB  (x64 28 / x86 28 バイト)
typedef struct DCB {
    DWORD DCBlength;
    DWORD BaudRate;
    DWORD _bitfield;
    WORD wReserved;
    WORD XonLim;
    WORD XoffLim;
    BYTE ByteSize;
    DCB_PARITY Parity;
    DCB_STOP_BITS StopBits;
    CHAR XonChar;
    CHAR XoffChar;
    CHAR ErrorChar;
    CHAR EofChar;
    CHAR EvtChar;
    WORD wReserved1;
} DCB;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DCB
{
    public uint DCBlength;
    public uint BaudRate;
    public uint _bitfield;
    public ushort wReserved;
    public ushort XonLim;
    public ushort XoffLim;
    public byte ByteSize;
    public byte Parity;
    public byte StopBits;
    public sbyte XonChar;
    public sbyte XoffChar;
    public sbyte ErrorChar;
    public sbyte EofChar;
    public sbyte EvtChar;
    public ushort wReserved1;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DCB
    Public DCBlength As UInteger
    Public BaudRate As UInteger
    Public _bitfield As UInteger
    Public wReserved As UShort
    Public XonLim As UShort
    Public XoffLim As UShort
    Public ByteSize As Byte
    Public Parity As Byte
    Public StopBits As Byte
    Public XonChar As SByte
    Public XoffChar As SByte
    Public ErrorChar As SByte
    Public EofChar As SByte
    Public EvtChar As SByte
    Public wReserved1 As UShort
End Structure
import ctypes
from ctypes import wintypes

class DCB(ctypes.Structure):
    _fields_ = [
        ("DCBlength", wintypes.DWORD),
        ("BaudRate", wintypes.DWORD),
        ("_bitfield", wintypes.DWORD),
        ("wReserved", ctypes.c_ushort),
        ("XonLim", ctypes.c_ushort),
        ("XoffLim", ctypes.c_ushort),
        ("ByteSize", ctypes.c_ubyte),
        ("Parity", ctypes.c_ubyte),
        ("StopBits", ctypes.c_ubyte),
        ("XonChar", ctypes.c_byte),
        ("XoffChar", ctypes.c_byte),
        ("ErrorChar", ctypes.c_byte),
        ("EofChar", ctypes.c_byte),
        ("EvtChar", ctypes.c_byte),
        ("wReserved1", ctypes.c_ushort),
    ]
#[repr(C)]
pub struct DCB {
    pub DCBlength: u32,
    pub BaudRate: u32,
    pub _bitfield: u32,
    pub wReserved: u16,
    pub XonLim: u16,
    pub XoffLim: u16,
    pub ByteSize: u8,
    pub Parity: u8,
    pub StopBits: u8,
    pub XonChar: i8,
    pub XoffChar: i8,
    pub ErrorChar: i8,
    pub EofChar: i8,
    pub EvtChar: i8,
    pub wReserved1: u16,
}
import "golang.org/x/sys/windows"

type DCB struct {
	DCBlength uint32
	BaudRate uint32
	_bitfield uint32
	wReserved uint16
	XonLim uint16
	XoffLim uint16
	ByteSize byte
	Parity byte
	StopBits byte
	XonChar int8
	XoffChar int8
	ErrorChar int8
	EofChar int8
	EvtChar int8
	wReserved1 uint16
}
type
  DCB = record
    DCBlength: DWORD;
    BaudRate: DWORD;
    _bitfield: DWORD;
    wReserved: Word;
    XonLim: Word;
    XoffLim: Word;
    ByteSize: Byte;
    Parity: Byte;
    StopBits: Byte;
    XonChar: Shortint;
    XoffChar: Shortint;
    ErrorChar: Shortint;
    EofChar: Shortint;
    EvtChar: Shortint;
    wReserved1: Word;
  end;
const DCB = extern struct {
    DCBlength: u32,
    BaudRate: u32,
    _bitfield: u32,
    wReserved: u16,
    XonLim: u16,
    XoffLim: u16,
    ByteSize: u8,
    Parity: u8,
    StopBits: u8,
    XonChar: i8,
    XoffChar: i8,
    ErrorChar: i8,
    EofChar: i8,
    EvtChar: i8,
    wReserved1: u16,
};
type
  DCB {.bycopy.} = object
    DCBlength: uint32
    BaudRate: uint32
    _bitfield: uint32
    wReserved: uint16
    XonLim: uint16
    XoffLim: uint16
    ByteSize: uint8
    Parity: uint8
    StopBits: uint8
    XonChar: int8
    XoffChar: int8
    ErrorChar: int8
    EofChar: int8
    EvtChar: int8
    wReserved1: uint16
struct DCB
{
    uint DCBlength;
    uint BaudRate;
    uint _bitfield;
    ushort wReserved;
    ushort XonLim;
    ushort XoffLim;
    ubyte ByteSize;
    ubyte Parity;
    ubyte StopBits;
    byte XonChar;
    byte XoffChar;
    byte ErrorChar;
    byte EofChar;
    byte EvtChar;
    ushort wReserved1;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DCB サイズ: 28 バイト(x64)
dim st, 7    ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; DCBlength : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; BaudRate : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; _bitfield : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; wReserved : WORD (+12, 2byte)  wpoke st,12,値  /  値 = wpeek(st,12)
; XonLim : WORD (+14, 2byte)  wpoke st,14,値  /  値 = wpeek(st,14)
; XoffLim : WORD (+16, 2byte)  wpoke st,16,値  /  値 = wpeek(st,16)
; ByteSize : BYTE (+18, 1byte)  poke st,18,値  /  値 = peek(st,18)
; Parity : DCB_PARITY (+19, 1byte)  poke st,19,値  /  値 = peek(st,19)
; StopBits : DCB_STOP_BITS (+20, 1byte)  poke st,20,値  /  値 = peek(st,20)
; XonChar : CHAR (+21, 1byte)  poke st,21,値  /  値 = peek(st,21)
; XoffChar : CHAR (+22, 1byte)  poke st,22,値  /  値 = peek(st,22)
; ErrorChar : CHAR (+23, 1byte)  poke st,23,値  /  値 = peek(st,23)
; EofChar : CHAR (+24, 1byte)  poke st,24,値  /  値 = peek(st,24)
; EvtChar : CHAR (+25, 1byte)  poke st,25,値  /  値 = peek(st,25)
; wReserved1 : WORD (+26, 2byte)  wpoke st,26,値  /  値 = wpeek(st,26)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global DCB
    #field int DCBlength
    #field int BaudRate
    #field int _bitfield
    #field short wReserved
    #field short XonLim
    #field short XoffLim
    #field byte ByteSize
    #field byte Parity
    #field byte StopBits
    #field byte XonChar
    #field byte XoffChar
    #field byte ErrorChar
    #field byte EofChar
    #field byte EvtChar
    #field short wReserved1
#endstruct

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