0% found this document useful (0 votes)
26 views

Coding Form Monitor

This document contains code for a monitoring form application in Visual Basic. It includes code to: 1) Close the form and open a login form when closing. 2) Center and initialize the form on load. 3) Scan and populate available COM ports in a dropdown and enable connecting when a port is selected. 4) Connect to a selected COM port and baud rate, start timers, and disable/enable buttons accordingly. 5) Disconnect from the COM port, stop timers, and enable/disable buttons in the opposite manner of connecting.

Uploaded by

Harits Cool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Coding Form Monitor

This document contains code for a monitoring form application in Visual Basic. It includes code to: 1) Close the form and open a login form when closing. 2) Center and initialize the form on load. 3) Scan and populate available COM ports in a dropdown and enable connecting when a port is selected. 4) Connect to a selected COM port and baud rate, start timers, and disable/enable buttons accordingly. 5) Disconnect from the COM port, stop timers, and enable/disable buttons in the opposite manner of connecting.

Uploaded by

Harits Cool
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

You might also like