Public Const GENERIC_READ As Long = &H80000000 ' 読み取り
Public Const GENERIC_WRITE As Long = &H40000000 ' 書き込み
Public Const OPEN_EXISTING As Long = 3 ' 既存ファイルを開く
Public Const INVALID_HANDLE_VALUE As Long = -1 ' 失敗
' タイムアウト構造体
Public Type COMMTIMEOUTS
ReadIntervalTimeout As Long ' 連続受信時の間隔
ReadTotalTimeoutMultiplier As Long ' 1文字受信の時間
ReadTotalTimeoutConstant As Long ' 受信時間の定数
WriteTotalTimeoutMultiplier As Long ' 1文字送信の時間
WriteTotalTimeoutConstant As Long ' 送信時間の定数
End Type
' 通信リソース開く
Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _
ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long _
) As Long
' ポートから入力
Public Declare Function ReadFile Lib "kernel32" ( _
ByVal hFile As Long, _
lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, _
lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Long _
) As Long
' ポートへ出力
Public Declare Function WriteFile Lib "kernel32" ( _
ByVal hFile As Long, _
lpBuffer As Any, _
ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, _
ByVal lpOverlapped As Long _
) As Long
' タイムアウトの設定
Public Declare Function SetCommTimeouts Lib "kernel32" ( _
ByVal hFile As Long, _
lpCommTimeouts As COMMTIMEOUTS _
) As Long
' 通信リソース閉じる
Public Declare Function CloseHandle Lib "kernel32" ( _
ByVal hObject As Long _
) As Long |