0% found this document useful (0 votes)
23 views4 pages

' Abrir Puerto Mientras Se Ejecute La Aplicación

This document contains the code for a VB.NET class called Panel that is used to display readings from a serial port on a graphical interface. The class initializes the serial port, draws graphics on the form such as an image and lines, and contains methods to get readings from the serial port and update the display periodically based on timer intervals. Buttons and radio buttons are used to control settings like the units and time intervals.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

' Abrir Puerto Mientras Se Ejecute La Aplicación

This document contains the code for a VB.NET class called Panel that is used to display readings from a serial port on a graphical interface. The class initializes the serial port, draws graphics on the form such as an image and lines, and contains methods to get readings from the serial port and update the display periodically based on timer intervals. Buttons and radio buttons are used to control settings like the units and time intervals.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

D:\Visual Studio 2010\Projects\Polimetro\Polimetro\Panel.

vb martes, 15 de octubre de 2013 11:57

Public Class Panel


Dim MiGrafico As Graphics
Dim relleno As New SolidBrush(Color.Black)
Dim image As New Bitmap("D:\Visual Studio
2010\Projects\Polimetro\Polimetro\Dibujos\voltimetro2.bmp")
Dim n = 10
Dim punto As Integer
Dim basura, datoS As String
Public Sub New()
InitializeComponent()
' Abrir puerto mientras se ejecute la aplicación
If Not SerialPort1.IsOpen Then
Try
SerialPort1.Open()
Catch ex As System.Exception
MessageBox.Show(ex.ToString())
End Try
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
MiGrafico = Me.CreateGraphics
End Sub

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As


System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dibujar(0, 150, 152)
MiGrafico.DrawRectangle(Pens.Black, 10, 196, 275, 210)
End Sub
Private Sub Dibujar(ByVal angulo As Integer, ByVal x1 As Integer, ByVal y1 As Integer)
MiGrafico.DrawImage(image, x1 - 140, y1 - 142)
Dim x2, y2 As Single
Dim radio, grueso, angulo1, angulo2 As Single
radio = 90
grueso = 3
angulo = angulo / 1024 * 180
angulo1 = angulo - 90
angulo2 = angulo + 90
x2 = x1 - (radio * Math.Cos(angulo * 0.01745329))
y2 = y1 - (radio * Math.Sin(angulo * 0.01745329))
Dim point1 As New Point(x2, y2)
Dim point2 As New Point(x1 - (grueso * Math.Cos(angulo2 * 0.01745329)), y1 - (grueso
* Math.Sin(angulo2 * 0.01745329)))
Dim point3 As New Point(x1 - (grueso * Math.Cos(angulo1 * 0.01745329)), y1 - (grueso
* Math.Sin(angulo1 * 0.01745329)))
Dim curvePoints As Point() = {point1, point2, point3}
MiGrafico.DrawPolygon(Pens.Black, curvePoints)
MiGrafico.FillPolygon(relleno, curvePoints)
Label1.Text = Convert.ToInt16(datoS) * 0.0048875
End Sub
Private Sub OptenerDato()
SerialPort1.Write(Chr(10))
datoS = SerialPort1.ReadLine
datoS = datoS.Substring(0, datoS.Length - 1)
Dibujar(Convert.ToInt16(datoS), 150, 152)
basura = SerialPort1.ReadExisting
End Sub

-1-
D:\Visual Studio 2010\Projects\Polimetro\Polimetro\Panel.vb martes, 15 de octubre de 2013 11:57

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
If Label4.Text = "V" Then Label2.Text = "V"
If Label4.Text = "A" Then Label2.Text = "A"
If Label4.Text = "Hz" Then Label2.Text = "Hz"
If Label4.Text = "Ω" Then Label2.Text = "Ω"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
If Label4.Text = "V" Then Label2.Text = "mV"
If Label4.Text = "A" Then Label2.Text = "mA"
If Label4.Text = "Hz" Then Label2.Text = "mHz"
If Label4.Text = "Ω" Then Label2.Text = "mΩ"
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button9.Click
If Me.Button9.BackColor = Color.Gainsboro Then
Me.Button9.BackColor = Color.LightSkyBlue
Timer1.Enabled = True
Else
Me.Button9.BackColor = Color.Gainsboro
Timer1.Enabled = False
End If
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button7.Click
Label3.Text = "CA"
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button8.Click
Label3.Text = "CC"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button3.Click
Label4.Text = "V"
Label2.Text = "V"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button4.Click
Label4.Text = "A"
Label2.Text = "A"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button5.Click
Label4.Text = "Hz"
Label2.Text = "Hz"
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button6.Click

-2-
D:\Visual Studio 2010\Projects\Polimetro\Polimetro\Panel.vb martes, 15 de octubre de 2013 11:57

Label4.Text = "Ω"
Label2.Text = "Ω"
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Timer1.Tick
ListBox1.Items.Add(Convert.ToInt16(datoS))
If n > 280 Then
n = 10
MiGrafico.Clear(Color.Gainsboro)
MiGrafico.DrawRectangle(Pens.Black, 10, 196, 275, 210)
Dibujar(Convert.ToInt16(datoS), 150, 152)
End If
n = n + 1
TextBox2.Text = n
OptenerDato()
punto = Fix(Convert.ToInt16(datoS) * 0.195)
MiGrafico.DrawLine(Pens.Blue, n, 400 - punto, n, 399 - punto)
End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton1.CheckedChanged
Timer1.Interval = 100
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton2.CheckedChanged
Timer1.Interval = 60000
End Sub

Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton4.CheckedChanged
Timer1.Interval = 36000000
End Sub

Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton3.CheckedChanged
Timer1.Interval = 1000
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button11.Click
ListBox1.SelectedIndex = 1
TextBox2.Text = ListBox1.Text
End Sub

Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton8.CheckedChanged
Timer1.Interval = 500
End Sub

Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton6.CheckedChanged
Timer1.Interval = 5000
End Sub

Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As

-3-
D:\Visual Studio 2010\Projects\Polimetro\Polimetro\Panel.vb martes, 15 de octubre de 2013 11:57

System.EventArgs) Handles RadioButton7.CheckedChanged


Timer1.Interval = 300000
End Sub

Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RadioButton5.CheckedChanged
Timer1.Interval = 72000000
End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Timer2.Tick
OptenerDato()
End Sub
End Class

-4-

You might also like