Imports System.
IO
Imports System.IO.Ports
Imports System.Data
Imports System.Data.SqlClient
Public Class FormMonitoring
Private Sub FormMonitoring_FormClosing(sender As Object, e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
FormLogin.Show()
End Sub
Private Sub FormMonitoring_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
ButtonDisconnect.Enabled = False
ButtonConnect.Enabled = False
ComboBoxBaudRate.SelectedIndex = 2
GroupBoxConnection.Hide()
Panel2.Hide()
End Sub
Private Sub ButtonScanPort_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
ComboBoxPort.Items.Clear()
Dim myPort As Array
Dim i As Integer
myPort = IO.Ports.SerialPort.GetPortNames()
ComboBoxPort.Items.AddRange(myPort)
i = ComboBoxPort.Items.Count
i = i - i
Try
ComboBoxPort.SelectedIndex = i
ButtonConnect.Enabled = True
Catch ex As Exception
MsgBox("Com port not detected", MsgBoxStyle.Critical, "Warning !!!")
ComboBoxPort.Text = ""
ComboBoxPort.Items.Clear()
ButtonConnect.Enabled = False
Return
End Try
ComboBoxPort.DroppedDown = True
End Sub
Private Sub ButtonConnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
SerialPort1.BaudRate = ComboBoxBaudRate.SelectedItem
SerialPort1.PortName = ComboBoxPort.SelectedItem
SerialPort1.Open()
Timer1.Start()
TimerDataLogRecord.Start()
ComboBoxPort.Enabled = False
'Label1.Enabled = False
ComboBoxBaudRate.Enabled = False
ButtonScanPort.Enabled = False
ButtonConnect.Enabled = False
ButtonDisconnect.Enabled = True
PictureBoxConnectionInd.Image = My.Resources.green
LabelStatus.Text = "Status : Connected"
End Sub
Private Sub ButtonDisconnect_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
PictureBoxConnectionInd.Image = My.Resources.red
PictureBoxConnectionInd.Visible = True
LabelStatus.Text = "Status : Disconnect"
ComboBoxPort.Enabled = True
'Label1.Enabled = True
ComboBoxBaudRate.Enabled = True
ButtonScanPort.Enabled = True
ButtonConnect.Enabled = True
ButtonDisconnect.Enabled = False
Timer1.Stop()
TimerDataLogRecord.Stop()
SerialPort1.Close()
End Sub
Public Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
End Sub
Private Sub ConnectionToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
GroupBoxConnection.Show()
End Sub
Private Sub MonitoringToolStripMenuItem_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Panel2.Show()
End Sub
End Class