イメージ 1

SDR送信受信の制御プログラムをVB2008Expressで書いたのでリストを以下に載せます。
プログラムは単純に出力をONOFFするだけの制御ですのでとても簡単なものです。
以前はVB6のSDR受信プログラムで使用していた物を制御部分のみVBnet用に書き換えたものです。

Public Class Form1
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Finalize()
SerialPort1.DtrEnable = False
SerialPort1.RtsEnable = False
SerialPort1.Close()
End
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'Dim spflag As Boolean <--- module public
spflag = serialport1.IsOpen

Select Case spflag
Case False
SerialPort1.Open()
Button1.Text = "Now COM on"
Label1.Text = "ON"
'ボタンをイネーブル処理true
Button2.Enabled = True
Button3.Enabled = True
'ボタン名をリセット
Button2.Text = "DTR"
Button3.Text = "RTE"
' Stop
Case True
serialport1.Close()
Button1.Text = "Now COM off"
Label1.Text = "OFF"
'ボタンをイネーブル処理false
Button2.Enabled = False
Button3.Enabled = False
'ボタン名をリセット
Button2.Text = "DTR"
Button3.Text = "RTE"
'DTR、RTSをoff状態にしてCOM offとする。
SerialPort1.DtrEnable = False
TextBox1.Text = SerialPort1.DtrEnable
SerialPort1.RtsEnable = False
TextBox2.Text = SerialPort1.RtsEnable
Label8.Text = "RX"
Label11.Text = "OFF"
End Select
Dim kakunin As Boolean
kakunin = serialport1.IsOpen
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Dim serialport1 As New SerialPort <-- module public
'初期設定のみ シリアルポートは close状態
With serialport1
.PortName = "COM4"
.BaudRate = 4800
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.Two
.Handshake = IO.Ports.Handshake.None
' .DtrEnable = True
' .RtsEnable = True
End With
'RS232C INFO
TextBox4.Text = SerialPort1.BaudRate
TextBox5.Text = SerialPort1.Parity
TextBox6.Text = SerialPort1.DataBits
TextBox7.Text = SerialPort1.StopBits
TextBox8.Text = SerialPort1.Handshake
'制御状態初期表示
Label8.Text = "RX"
Label11.Text = "OFF"

SerialPort1.DtrEnable = False
SerialPort1.RtsEnable = False

TextBox1.Text = SerialPort1.DtrEnable
TextBox2.Text = SerialPort1.RtsEnable
TextBox3.Text = SerialPort1.PortName
'ボタンをイネーブル処理false
Button2.Enabled = False
Button3.Enabled = False

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If SerialPort1.DtrEnable = False Then
SerialPort1.DtrEnable = True
Button2.Text = "DTR on"
TextBox1.Text = SerialPort1.DtrEnable
Label8.Text = "TX"
Else
SerialPort1.DtrEnable = False
Button2.Text = "DTR off"
TextBox1.Text = SerialPort1.DtrEnable
Label8.Text = "RX"
End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If SerialPort1.RtsEnable = False Then
SerialPort1.RtsEnable = True
Button3.Text = "RTS on"
TextBox2.Text = SerialPort1.RtsEnable
Label11.Text = "ON"
Else
SerialPort1.RtsEnable = False
Button3.Text = "RTS off"
TextBox2.Text = SerialPort1.RtsEnable
Label11.Text = "OFF"
End If
End Sub
End Class

Module Module1
Public serialport1 As New SerialPort
Public spflag As Boolean
End Module

以上がプログラムです。文面の制限が5000文字なので使い方は次にアップします。