RS232C シリアルポートの操作 その1

1.シリアルポートコントロールの使用
2.受信は別スレッドで受信待ち
3.送信は送信データにCR+LFをつけて送信

1.手順ポートの初期設定
Imports System.Windows.Forms
sysytem.IO.Ports.XXXXを利用

例 com5 9600 evex データ7ビット 偶数 ストップ2ビット ハードなし

SerialPort1.PortName = “COM5”
SerialPort1.BaudRate = 9600
SerialPort1.DataBits = 7
SerialPort1.Parity = IO.Ports.Parity.Even
SerialPort1.StopBits = IO.Ports.StopBits.Two
SerialPort1.Handshake = IO.Ports.Handshake.None

2.comオープン
SerialPort.Open()
try Catch ex As Exceptionを記載

3.comクローズ

If SerialPort.IsOpen = True Then
Call SerialPort.Close()
End If