Visual Basic 中学校 掲示板 投稿の管理
タグのない投稿を抽出
統計
RSS
Visual Basic 中学校
投稿一覧
RS232C データ受信のタイミングでプログラムを動かす
この投稿へのリンク
https://keijiban.umayadia.com/ThreadDetail.aspx?ThreadId=20720#CommentId55662
この投稿の削除
削除パスワード
削除する
コメント本文
投稿者
ザボン
 (社会人)
投稿日時
2014/12/1 14:18:03
標準モジュール
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 hCom As Long
Public Declare Function GetCommState Lib "kernel32" (ByVal hCom As Long, ByRef lpDCB As DCBstructure) As Long
Public Declare Function BuildCommDCB Lib "kernel32" Alias "BuildCommDCBA" (ByVal lpDef As String, ByRef lpDCB As DCBstructure) As Long
Public Declare Function SetCommState Lib "kernel32" (ByVal hCom As Long, ByRef lpDCB As DCBstructure) As Long
Public Type DCBstructure
DCBlength As Long
BaudRate As Long
Flags As Long
XonLim As Integer
XoffLim As Integer
ByteSize As Byte
Parity As Byte
StopBits As Byte
XonChar As Byte
XoffChar As Byte
ErrorChar As Byte
EofChar As Byte
EvtChar As Byte
wReserved2 As Integer
End Type
' Comm Baud Rate indices
Public Const CBR_110 = 110
Public Const CBR_300 = 300
Public Const CBR_600 = 600
Public Const CBR_1200 = 1200
Public Const CBR_2400 = 2400
Public Const CBR_4800 = 4800
Public Const CBR_9600 = 9600
Public Const CBR_14400 = 14400
Public Const CBR_19200 = 19200
Public Const CBR_38400 = 38400
Public Const CBR_56000 = 56000
Public Const CBR_57600 = 57600
Public Const CBR_115200 = 115200
Public Const CBR_128000 = 128000
Public Const CBR_256000 = 256000
Public Const DTR_CONTROL_DISABLE = &H0
Public Const DTR_CONTROL_ENABLE = &H1
Public Const DTR_CONTROL_HANDSHAKE = &H2
Public Const RTS_CONTROL_DISABLE = &H0
Public Const RTS_CONTROL_ENABLE = &H1
Public Const RTS_CONTROL_HANDSHAKE = &H2
Public Const RTS_CONTROL_TOGGLE = &H3
Public Type COMMTIMEOUTS
ReadIntervalTimeout As Long
ReadTotalTimeoutMultiplier As Long
ReadTotalTimeoutConstant As Long
WriteTotalTimeoutMultiplier As Long
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
Public Function CommOpen(ByVal strPort As String) As Long
CommOpen = CreateFile(strPort, GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
End Function
Public Function CommInput(ByVal hCom As Long, strBuffer As String, ByVal lngLen As Long) As Long
Dim lngRead As Long
Call ReadFile(hCom, ByVal strBuffer, lngLen, lngRead, 0)
CommInput = lngRead
End Function
Public Function CommOutput(ByVal hCom As Long, ByVal strBuffer As String, ByVal lngLen As Long) As Long
Dim lngWrite As Long
Call WriteFile(hCom, ByVal strBuffer, lngLen, lngWrite, 0)
CommOutput = lngWrite
End Function
Public Function CommClose(ByVal hCom As Long) As Boolean
CommClose = CloseHandle(hCom)
End Function
Public Function SetCommTimeout(ByVal hCom As Long, typTimeout As COMMTIMEOUTS) As Boolean
SetCommTimeout = SetCommTimeouts(hCom, typTimeout)
End Function