Imports System
Imports System.IO
Public Class Form2
Dim buffer As Double
Dim contador As Integer
Dim contador2 As Integer
Dim recibe As Boolean
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Textmas.Text = My.Settings.pesomas
Textmenos.Text = My.Settings.pesomenos
Texttimer2.Text = My.Settings.tinicio
Texttimer3.Text = My.Settings.tfin
Textpesominimo.Text = My.Settings.minimo
Textpesomaximo.Text = My.Settings.maximo
'
Label11.Visible = False
Label3.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label5.Visible = False
Label4.Visible = False
pesoultimo.Visible = False
Texttimer2.Visible = False
Texttimer3.Visible = False
Textmas.Visible = False
Textmenos.Visible = False
Button3.Visible = False
''
Form1.Visible = False
Textpeso.Text = "WAIT"
SerialPort1.Close()
SerialPort1.Open()
CheckForIllegalCrossThreadCalls = False
contador = 0
contador2 = 0
recibe = False
Timer1.Enabled = True
Timer2.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.Close()
End Sub
Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Try
Dim az As String = SerialPort1.ReadLine
If az > 1 Then
Textpeso.Text = (Val(az) + Val(Textmenos.Text) - Val(Textmas.Text))
pesoultimo.Text = Val(Textpeso.Text)
If Val(pesoultimo.Text) > 10 Then
If Val(pesoultimo.Text) < 100 Then
Timer3.Enabled = True
Else
Textpeso.Text = 0
End If
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Textpeso_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Textpeso.TextChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub Button2_Click_t1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SerialPort1.Write("a")
Textpeso.Text = "WAIT"
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Textpeso.Text = 0
Timer1.Enabled = False
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Texttimer2.Text = Timer3.Interval
Texttimer3.Text = Timer4.Interval
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
SerialPort1.Write("c")
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
SerialPort1.Write("B")
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If Val(pesoultimo.Text) > 10 Then
If Val(pesoultimo.Text) < 100 Then
SerialPort1.Write("c")
Timer3.Enabled = True
End If
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Timer2.Enabled = False
If contador2 >= 2 Then
' Exit loop code.
SerialPort1.Write("c")
Timer4.Enabled = True
Timer3.Enabled = False
contador2 = 0
Else
' Run your procedure here.
' Increment counter.
contador2 = contador2 + 1
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
If contador >= 2 Then
' Exit loop code.
SerialPort1.Write("B")
recibe = False
Timer4.Enabled = True
Timer3.Enabled = False
contador = 0
pesoultimo.Text = 0
Else
' Run your procedure here.
' Increment counter.
contador = contador + 1
End If
End Sub
Private Sub Bajustes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bajustes.Click
If Bajustes.Text = "AJUSTES" Then
Bajustes.Text = "SALIR DE AJUSTES"
Label11.Visible = True
Label3.Visible = True
Label8.Visible = True
Label9.Visible = True
Label10.Visible = True
Label5.Visible = True
Label4.Visible = True
pesoultimo.Visible = True
Texttimer2.Visible = True
Texttimer3.Visible = True
Textmas.Visible = True
Textmenos.Visible = True
Button3.Visible = True
ElseIf Bajustes.Text = "SALIR DE AJUSTES" Then
Bajustes.Text = "AJUSTES"
Label11.Visible = False
Label3.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label5.Visible = False
Label4.Visible = False
pesoultimo.Visible = False
Texttimer2.Visible = False
Texttimer3.Visible = False
Textmas.Visible = False
Textmenos.Visible = False
Button3.Visible = False
End If
End Sub
Private Sub Button4_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
My.Settings.pesomas = Textmas.Text
My.Settings.pesomenos = Textmenos.Text
My.Settings.tinicio = Texttimer2.Text
My.Settings.tfin = Texttimer3.Text
My.Settings.minimo = Textpesominimo.Text
My.Settings.maximo = Textpesomaximo.Text
My.Settings.Save()
MsgBox("GUARDAR DATOS?", MsgBoxStyle.OkOnly, "Save...")
Catch ex As Exception
MsgBox("There was a problem saving your settings.", MsgBoxStyle.Critical, "Save Error...")
End Try
End Sub
End Class