Hello,
I have a ZedGraph on Form1 along with a button and a label. I'm reading serialinput data(data format:startbit data stopbit checksum checksum)Serial Input data is the values of pressure sensor.I want to plot Pressure(in cmH2o) on X axis and time on y axis(in milliseconds). i read serial input data in a thread and display it in label as well as plot it on graph.. i can display data in label but cant plot the graph.
Imports ZedGraph
Imports System.IO.Ports
Imports System.Threading
Public Class Form1
Public data As Double
Public count As Integer
Public data_buffer(4) As Integer
Public data_available As Integer = 0
Public p As Double
Private Sub cmd_open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_open.Click
Try
If SerialPort1.IsOpen = False Then
SerialPort1.Open()
Console.WriteLine("PORT OPEN SUCCEEDED.")
End If
data_available = 1
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
Do
Try
data = SerialPort1.ReadByte
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Loop While (data <> 64)
data_buffer(0) = data
data = SerialPort1.ReadByte
data_buffer(1) = data
data = SerialPort1.ReadByte
data_buffer(2) = data
Me.Invoke(New EventHandler(AddressOf UpdateControls_label))
Me.Invoke(New EventHandler(AddressOf UpdateControls_graph))
data = SerialPort1.ReadByte
data_buffer(3) = data
data = SerialPort1.ReadByte
data_buffer(4) = data
For i = 0 To 4
Console.WriteLine(data_buffer(i))
Next
End Sub
Public Sub UpdateControls_label(ByVal sender As Object, ByVal e As EventArgs)
Me.Label1.Text = data_buffer(1)
End Sub
Private Sub UpdateControls_graph(ByVal sender As Object, ByVal e As EventArgs)
Dim zgc = New ZedGraphControl
Dim myPane As GraphPane = zgc.GraphPane
Dim list = New PointPairList()
Dim x As Double, y As Double
For x = 0 To 36
y = data_buffer(1)
list.Add(x, y)
Next x
Dim myCurve As LineItem = myPane.AddCurve("My Curve", list, Color.Blue, SymbolType.Circle)
myCurve.Line.Fill = New Fill(Color.White, Color.Red, 45.0F)
myCurve.Symbol.Fill = New Fill(Color.White)
myPane.Chart.Fill = New Fill(Color.White, Color.LightGoldenrodYellow, 45.0F)
myPane.Fill = New Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0F)
zgc.AxisChange()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
End Sub
End Class
Your help will be much appreciated.
Thanks and Regards,
Kadhambari K