Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Collections.Generic
- Imports System.ComponentModel
- Imports System.Data
- Imports System.Drawing
- Imports System.Linq
- Imports System.Text
- Imports System.Threading.Tasks
- Imports System.Windows.Forms
- Imports System.IO.Ports
- Imports System.Threading
- Namespace arduino
- Public Partial Class Form1
- Inherits Form
- Private X As Thread
- Public Sub New()
- InitializeComponent()
- ComboPorta.DataSource = SerialPort.GetPortNames()
- X = New Thread(New ThreadStart(AddressOf Serial))
- End Sub
- Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
- If SP.IsOpen Then
- SP.Close()
- X.Abort()
- timerx.Enabled = False
- Else
- SP.PortName = ComboPorta.Text
- SP.BaudRate = Convert.ToInt32(ComboBaud.Text)
- SP.Open()
- timerx.Enabled = True
- End If
- End Sub
- Private Sub Serial()
- While True
- SP.Write("a")
- textBox1.Text += SP.ReadLine()
- textBox1.Text += vbCrLf
- End While
- End Sub
- Private Sub timerx_Tick(ByVal sender As Object, ByVal e As EventArgs)
- SP.Write("a")
- End Sub
- Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
- SP.Close()
- X.Abort()
- timerx.Enabled = False
- End Sub
- Private Sub SP_DataReceived(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
- Me.Invoke(New EventHandler(AddressOf transfere))
- End Sub
- Private Sub transfere(ByVal sender As Object, ByVal e As EventArgs)
- Dim dado As String = SP.ReadLine()
- Dim dados As String() = dado.Split(","c)
- textBox1.Text += dados(0)
- textBox1.Text += "%" & vbCrLf
- textBox1.[Select](textBox1.Text.Length, 0)
- textBox1.ScrollToCaret()
- textBox2.Text += dados(1)
- textBox2.Text += "°C" & vbCrLf
- textBox2.[Select](textBox2.Text.Length, 0)
- textBox2.ScrollToCaret()
- chart1.Series(0).Points.Add(Convert.ToDouble(dados(0)))
- chart1.Series(1).Points.Add(Convert.ToDouble(dados(1)))
- Dim x As Integer = chart1.Series(0).Points.Count
- If x > 100 Then chart1.ChartAreas(0).AxisX.ScaleView.Zoom(x - 100, x)
- End Sub
- End Class
- End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement