Public Class Form1
Dim data As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Datatest1DataSet.datatest' table. You can move, or remove it, as needed.
Me.DatatestTableAdapter.Fill(Me.Datatest1DataSet.datatest)
ComboBox1.Items.Add("COM1")
ComboBox1.Items.Add("COM2")
ComboBox1.Items.Add("COM3")
ComboBox1.Items.Add("COM4")
ComboBox1.Items.Add("COM5")
ComboBox1.Items.Add("COM6")
ComboBox1.Items.Add("COM7")
ComboBox1.Items.Add("COM8")
ComboBox1.Items.Add("COM9")
ComboBox1.Items.Add("COM10")
Button1.Text = "Connect"
Timer1.Stop()
TextBox3.Focus()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
TextBox4.Text = TextBox4.Text + 1
If TextBox4.Text = 6 Then
TextBox1.Text = TextBox3.Text
Timer3.Start()
Timer2.Stop()
TextBox4.Text = 1
End If
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
If TextBox3.Text = "" Then
Else
Timer2.Start()
End If
End Sub
Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Me.Validate()
Me.DatatestBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Datatest1DataSet)
Me.DatatestBindingSource.AddNew()
Timer3.Stop()
TextBox2.Text = TextBox3.Text
Dim rpt As New CrystalReport1
rpt.SetParameterValue("d1", TextBox3.Text)
CrystalReportViewer1.ReportSource = rpt
CrystalReportViewer1.Refresh()
TextBox3.Clear()
TextBox3.Focus()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
data = SerialPort1.ReadExisting
TextBox3.AppendText(Data)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Connect" Then
With SerialPort1
.PortName = ComboBox1.Text
.BaudRate = 9600
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Parity = IO.Ports.Parity.None
End With
SerialPort1.Open()
Button1.Text = "Disconnect"
Timer1.Interval = 100
Timer1.Start()
TextBox3.Focus()
Else
SerialPort1.Close()
Timer1.Stop()
Button1.Text = "Connect"
TextBox1.Clear()
TextBox3.Clear()
End If
End Sub
End Class