Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Me.CenterToParent()
- BtnCon.Enabled = False
- BtnCon.BringToFront()
- BtnDiscon.Enabled = False
- BtnDiscon.SendToBack()
- CmbBaud.SelectedItem = "9600"
- End Sub
- Private Sub BtnScanPort_Click(sender As Object, e As EventArgs) Handles BtnScanPort.Click
- CmbPort.Items.Clear()
- Dim myPort As Array
- Dim i As Integer
- myPort = IO.Ports.SerialPort.GetPortNames()
- CmbPort.Items.AddRange(myPort)
- i = CmbPort.Items.Count
- i = i - i
- Try
- CmbPort.SelectedIndex = i
- Catch ex As Exception
- Dim result As DialogResult
- result = MessageBox.Show("com port not detected", "Warning !!!", MessageBoxButtons.OK)
- CmbPort.Text = ""
- CmbPort.Items.Clear()
- Call Form1_Load(Me, e)
- End Try
- BtnCon.Enabled = True
- BtnCon.BringToFront()
- CmbPort.DroppedDown = True
- End Sub
- Private Sub BtnCon_Click(sender As Object, e As EventArgs) Handles BtnCon.Click
- BtnCon.Enabled = False
- BtnCon.SendToBack()
- SerialPort1.BaudRate = CmbBaud.SelectedItem
- SerialPort1.PortName = CmbPort.SelectedItem
- SerialPort1.Open()
- Timer1.Start()
- BtnDiscon.Enabled = True
- BtnDiscon.BringToFront()
- End Sub
- Private Sub BtnDiscon_Click(sender As Object, e As EventArgs) Handles BtnDiscon.Click
- BtnDiscon.Enabled = False
- BtnDiscon.SendToBack()
- Timer1.Stop()
- SerialPort1.Close()
- BtnCon.Enabled = True
- BtnCon.BringToFront()
- End Sub
- Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
- Try
- Dim i As Integer
- Dim reach400 As Boolean
- Dim threshold As Integer
- i = 0
- reach400 = False
- threshold = 400
- Dim a As String = SerialPort1.ReadExisting()
- TextBox1.Text = a.ToString
- If a > threshold Then
- reach400 = True
- Else
- reach400 = False
- End If
- If Not reach400 & a > threshold Then
- reach400 = True
- i = i + 1
- TextBox3.Text = i.ToString
- End If
- If a < threshold Then
- reach400 = False
- End If
- Catch ex As Exception
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement