ホーム › Devices.SerialCommunication › SERIAL_BASIC_SETTINGS
SERIAL_BASIC_SETTINGS
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| Timeouts | SERIAL_TIMEOUTS | 20 | +0 | +0 | 読み書きのタイムアウト設定を保持するSERIAL_TIMEOUTS。 |
| HandFlow | SERIAL_HANDFLOW | 16 | +20 | +20 | フロー制御設定を保持するSERIAL_HANDFLOW。 |
| RxFifo | DWORD | 4 | +36 | +36 | 受信FIFOのトリガレベルをバイトで表す。 |
| TxFifo | DWORD | 4 | +40 | +40 | 送信FIFOのトリガレベルをバイトで表す。 |
各言語での定義
#include <windows.h>
// SERIAL_TIMEOUTS (x64 20 / x86 20 バイト)
typedef struct SERIAL_TIMEOUTS {
DWORD ReadIntervalTimeout;
DWORD ReadTotalTimeoutMultiplier;
DWORD ReadTotalTimeoutConstant;
DWORD WriteTotalTimeoutMultiplier;
DWORD WriteTotalTimeoutConstant;
} SERIAL_TIMEOUTS;
// SERIAL_HANDFLOW (x64 16 / x86 16 バイト)
typedef struct SERIAL_HANDFLOW {
DWORD ControlHandShake;
DWORD FlowReplace;
INT XonLimit;
INT XoffLimit;
} SERIAL_HANDFLOW;
// SERIAL_BASIC_SETTINGS (x64 44 / x86 44 バイト)
typedef struct SERIAL_BASIC_SETTINGS {
SERIAL_TIMEOUTS Timeouts;
SERIAL_HANDFLOW HandFlow;
DWORD RxFifo;
DWORD TxFifo;
} SERIAL_BASIC_SETTINGS;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERIAL_TIMEOUTS
{
public uint ReadIntervalTimeout;
public uint ReadTotalTimeoutMultiplier;
public uint ReadTotalTimeoutConstant;
public uint WriteTotalTimeoutMultiplier;
public uint WriteTotalTimeoutConstant;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERIAL_HANDFLOW
{
public uint ControlHandShake;
public uint FlowReplace;
public int XonLimit;
public int XoffLimit;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SERIAL_BASIC_SETTINGS
{
public SERIAL_TIMEOUTS Timeouts;
public SERIAL_HANDFLOW HandFlow;
public uint RxFifo;
public uint TxFifo;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SERIAL_TIMEOUTS
Public ReadIntervalTimeout As UInteger
Public ReadTotalTimeoutMultiplier As UInteger
Public ReadTotalTimeoutConstant As UInteger
Public WriteTotalTimeoutMultiplier As UInteger
Public WriteTotalTimeoutConstant As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SERIAL_HANDFLOW
Public ControlHandShake As UInteger
Public FlowReplace As UInteger
Public XonLimit As Integer
Public XoffLimit As Integer
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SERIAL_BASIC_SETTINGS
Public Timeouts As SERIAL_TIMEOUTS
Public HandFlow As SERIAL_HANDFLOW
Public RxFifo As UInteger
Public TxFifo As UInteger
End Structureimport ctypes
from ctypes import wintypes
class SERIAL_TIMEOUTS(ctypes.Structure):
_fields_ = [
("ReadIntervalTimeout", wintypes.DWORD),
("ReadTotalTimeoutMultiplier", wintypes.DWORD),
("ReadTotalTimeoutConstant", wintypes.DWORD),
("WriteTotalTimeoutMultiplier", wintypes.DWORD),
("WriteTotalTimeoutConstant", wintypes.DWORD),
]
class SERIAL_HANDFLOW(ctypes.Structure):
_fields_ = [
("ControlHandShake", wintypes.DWORD),
("FlowReplace", wintypes.DWORD),
("XonLimit", ctypes.c_int),
("XoffLimit", ctypes.c_int),
]
class SERIAL_BASIC_SETTINGS(ctypes.Structure):
_fields_ = [
("Timeouts", SERIAL_TIMEOUTS),
("HandFlow", SERIAL_HANDFLOW),
("RxFifo", wintypes.DWORD),
("TxFifo", wintypes.DWORD),
]#[repr(C)]
pub struct SERIAL_TIMEOUTS {
pub ReadIntervalTimeout: u32,
pub ReadTotalTimeoutMultiplier: u32,
pub ReadTotalTimeoutConstant: u32,
pub WriteTotalTimeoutMultiplier: u32,
pub WriteTotalTimeoutConstant: u32,
}
#[repr(C)]
pub struct SERIAL_HANDFLOW {
pub ControlHandShake: u32,
pub FlowReplace: u32,
pub XonLimit: i32,
pub XoffLimit: i32,
}
#[repr(C)]
pub struct SERIAL_BASIC_SETTINGS {
pub Timeouts: SERIAL_TIMEOUTS,
pub HandFlow: SERIAL_HANDFLOW,
pub RxFifo: u32,
pub TxFifo: u32,
}import "golang.org/x/sys/windows"
type SERIAL_TIMEOUTS struct {
ReadIntervalTimeout uint32
ReadTotalTimeoutMultiplier uint32
ReadTotalTimeoutConstant uint32
WriteTotalTimeoutMultiplier uint32
WriteTotalTimeoutConstant uint32
}
type SERIAL_HANDFLOW struct {
ControlHandShake uint32
FlowReplace uint32
XonLimit int32
XoffLimit int32
}
type SERIAL_BASIC_SETTINGS struct {
Timeouts SERIAL_TIMEOUTS
HandFlow SERIAL_HANDFLOW
RxFifo uint32
TxFifo uint32
}type
SERIAL_TIMEOUTS = record
ReadIntervalTimeout: DWORD;
ReadTotalTimeoutMultiplier: DWORD;
ReadTotalTimeoutConstant: DWORD;
WriteTotalTimeoutMultiplier: DWORD;
WriteTotalTimeoutConstant: DWORD;
end;
SERIAL_HANDFLOW = record
ControlHandShake: DWORD;
FlowReplace: DWORD;
XonLimit: Integer;
XoffLimit: Integer;
end;
SERIAL_BASIC_SETTINGS = record
Timeouts: SERIAL_TIMEOUTS;
HandFlow: SERIAL_HANDFLOW;
RxFifo: DWORD;
TxFifo: DWORD;
end;const SERIAL_TIMEOUTS = extern struct {
ReadIntervalTimeout: u32,
ReadTotalTimeoutMultiplier: u32,
ReadTotalTimeoutConstant: u32,
WriteTotalTimeoutMultiplier: u32,
WriteTotalTimeoutConstant: u32,
};
const SERIAL_HANDFLOW = extern struct {
ControlHandShake: u32,
FlowReplace: u32,
XonLimit: i32,
XoffLimit: i32,
};
const SERIAL_BASIC_SETTINGS = extern struct {
Timeouts: SERIAL_TIMEOUTS,
HandFlow: SERIAL_HANDFLOW,
RxFifo: u32,
TxFifo: u32,
};type
SERIAL_TIMEOUTS {.bycopy.} = object
ReadIntervalTimeout: uint32
ReadTotalTimeoutMultiplier: uint32
ReadTotalTimeoutConstant: uint32
WriteTotalTimeoutMultiplier: uint32
WriteTotalTimeoutConstant: uint32
SERIAL_HANDFLOW {.bycopy.} = object
ControlHandShake: uint32
FlowReplace: uint32
XonLimit: int32
XoffLimit: int32
SERIAL_BASIC_SETTINGS {.bycopy.} = object
Timeouts: SERIAL_TIMEOUTS
HandFlow: SERIAL_HANDFLOW
RxFifo: uint32
TxFifo: uint32struct SERIAL_TIMEOUTS
{
uint ReadIntervalTimeout;
uint ReadTotalTimeoutMultiplier;
uint ReadTotalTimeoutConstant;
uint WriteTotalTimeoutMultiplier;
uint WriteTotalTimeoutConstant;
}
struct SERIAL_HANDFLOW
{
uint ControlHandShake;
uint FlowReplace;
int XonLimit;
int XoffLimit;
}
struct SERIAL_BASIC_SETTINGS
{
SERIAL_TIMEOUTS Timeouts;
SERIAL_HANDFLOW HandFlow;
uint RxFifo;
uint TxFifo;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SERIAL_BASIC_SETTINGS サイズ: 44 バイト(x64)
dim st, 11 ; 4byte整数×11(構造体サイズ 44 / 4 切り上げ)
; Timeouts : SERIAL_TIMEOUTS (+0, 20byte) varptr(st)+0 を基点に操作(20byte:入れ子/配列)
; HandFlow : SERIAL_HANDFLOW (+20, 16byte) varptr(st)+20 を基点に操作(16byte:入れ子/配列)
; RxFifo : DWORD (+36, 4byte) st.9 = 値 / 値 = st.9 (lpoke/lpeek も可)
; TxFifo : DWORD (+40, 4byte) st.10 = 値 / 値 = st.10 (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global SERIAL_TIMEOUTS
#field int ReadIntervalTimeout
#field int ReadTotalTimeoutMultiplier
#field int ReadTotalTimeoutConstant
#field int WriteTotalTimeoutMultiplier
#field int WriteTotalTimeoutConstant
#endstruct
#defstruct global SERIAL_HANDFLOW
#field int ControlHandShake
#field int FlowReplace
#field int XonLimit
#field int XoffLimit
#endstruct
#defstruct global SERIAL_BASIC_SETTINGS
#field SERIAL_TIMEOUTS Timeouts
#field SERIAL_HANDFLOW HandFlow
#field int RxFifo
#field int TxFifo
#endstruct
stdim st, SERIAL_BASIC_SETTINGS ; NSTRUCT 変数を確保
st->RxFifo = 100
mes "RxFifo=" + st->RxFifo