943,074 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 634
  • VB.NET RSS
Feb 1st, 2010
0

How can i hold the graph data upto 10 minutes in vb.net

Expand Post »
I have written a simple program which receive data from serial port i.e (temperature) and display on a line graph. but i require accumlate the graph data upto 10 minutes on screen. after that it again accumlate next 10 minutes data.

**The Code of VB.Net program is below *

VB.NET Syntax (Toggle Plain Text)
  1. Imports System.Drawing.Image
  2. Imports System.IO.Ports
  3.  
  4. Public Class frmGraph
  5.  
  6. Dim WithEvents port2 As SerialPort = _
  7. New SerialPort("COM2", 19200, Parity.Even, 7, StopBits.One)
  8.  
  9.  
  10. ' Variables to store the changing values to be charted (previous and current)
  11. Private OldValue As Single = 0
  12. Private NewValue As Single = 0
  13.  
  14. Dim XMove As Integer = 4
  15. Dim Chunks As Integer = 10
  16.  
  17. Private Sub frmGraph_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  18. SwitchMT500()
  19. ReadLineAddress()
  20.  
  21.  
  22. txtMin.Text = 620
  23. txtMax.Text = 630
  24. ' Paint Guidelines on picGraph
  25. picGraph.Image = DisplayGuidelines(picGraph, Chunks)
  26. ' Paint Guidelines and Numbers on picValues
  27. picValues.Image = Me.DisplayVerticalValues(picValues, Chunks, CInt(txtMin.Text), CInt(txtMax.Text))
  28. ReadTemperature()
  29.  
  30. End Sub
  31.  
  32. Private Function DisplayGuidelines(ByVal PicBox As PictureBox, ByVal chunks As Integer) As Bitmap
  33. ' Step 1
  34. ' Create a bitmap to draw on and grab its Graphics Object
  35. Dim bm As New Bitmap(PicBox.Width, PicBox.Height)
  36. Dim gr As Graphics = Graphics.FromImage(bm)
  37.  
  38. ' Step 2
  39. ' Draw guidelines on main chart.
  40. ' Get the total height available and split it into chunks
  41. Dim total As Integer = PicBox.Height
  42. Dim chunk As Single = total / chunks
  43.  
  44. ' Step 3
  45. For i As Single = chunk To total Step chunk
  46. gr.DrawLine(Pens.WhiteSmoke, 0, i, PicBox.Width, i)
  47. Next i
  48.  
  49. ' Step 4
  50. ' return the results.
  51. Return bm
  52.  
  53. ' Step 5
  54. gr.Dispose()
  55. End Function
  56.  
  57. Private Function DisplayVerticalValues(ByVal PB As PictureBox, ByVal HowManyChunks As Single, _
  58. ByVal MinValue As Single, ByVal MaxValue As Single) As Bitmap
  59.  
  60. ' Step 1
  61. Dim bmp As New Bitmap(PB.Width, PB.Height)
  62. Dim gv As Graphics = Graphics.FromImage(bmp)
  63.  
  64. ' Step 2
  65. ' Draw guidelines on values strip
  66. ' Get the total height available and split it into chunks
  67. ' This value represents a number of pixels
  68. Dim TotalPixels As Integer = PB.Height
  69. Dim SingleChunk As Single = TotalPixels / HowManyChunks
  70.  
  71. For i As Single = SingleChunk To TotalPixels Step SingleChunk
  72. gv.DrawLine(Pens.WhiteSmoke, 0, i, PB.Width, i)
  73. Next i
  74.  
  75. ' Step 3
  76. ' Draw Numbers as Text, correctly spaced vertically
  77. ' Begin with the highest value allowed
  78. Dim NextMarker As Integer = MaxValue
  79. ' Calculate the plottable range
  80. Dim ValueRange As Integer = MaxValue - MinValue
  81.  
  82. ' Draw the numbers, decrementing values proportionately each time through the loop
  83. For i As Single = 0 To TotalPixels Step SingleChunk
  84. gv.DrawString(CStr(NextMarker), New Font("Verdana", 8, FontStyle.Regular), Brushes.Black, 1, i)
  85. NextMarker -= (ValueRange / HowManyChunks)
  86. Next
  87.  
  88. ' Step 4
  89. Return bmp
  90.  
  91. ' Step 5
  92. gv.Dispose()
  93.  
  94. End Function
  95.  
  96. Private Function DisplayGuidelinesAndChart(ByVal PicBox As PictureBox, ByVal chunks As Integer, _
  97. ByVal XMove As Integer, ByVal NewValue As Single, ByVal Min As Single, ByVal Max As Single) As Bitmap
  98.  
  99.  
  100. ' Step 1
  101. ' Grab the current image (the latest version of the chart)
  102. Dim bm As New Bitmap(PicBox.Width, PicBox.Height)
  103. Dim gr As Graphics = Graphics.FromImage(bm)
  104.  
  105. ' Step 2
  106. ' Get the total height available and split it into chunks
  107. Dim total As Integer = PicBox.Height
  108. Dim chunk As Single = total / chunks
  109. ' Tack missing guidelines to right hand side on the Graphics object.
  110. For i As Single = chunk To total Step chunk
  111. gr.DrawLine(Pens.WhiteSmoke, PicBox.Width - XMove, i, PicBox.Width, i)
  112. Next i
  113.  
  114. ' Step 3
  115. ' Draw this grabbed image, placing it XMove pixels to the left
  116.  
  117. If Not IsNothing(PicBox.Image) Then
  118. gr.DrawImage(PicBox.Image, -XMove, 0)
  119. End If
  120.  
  121. ' Step 4
  122. ' Plot the new value.
  123. ' Calculate the scaling required to make full use of the height of
  124. ' the PictureBox
  125. Dim ValueRange As Single = Max - Min
  126. Dim vScale As Single = PicBox.Height / ValueRange
  127. ' Apply the scale to the current value
  128. NewValue *= vScale
  129. ' Step 5
  130. ' Shift start point from top left to bottom left.
  131. gr.TranslateTransform(0, PicBox.Height)
  132.  
  133. ' Step 6
  134. ' Draw the next line segment on the Graphics object.
  135.  
  136. ' If Min is > 0 then you need to shift the drawing down once again,
  137. ' this time to put the Min value on the horizontal axis
  138. If Min > 0 Then gr.TranslateTransform(0, Min * vScale)
  139.  
  140. Dim p As Pen = New Pen(Color.Navy, 1)
  141.  
  142. gr.DrawLine(p, _
  143. PicBox.Width - 1 - XMove, -OldValue, _
  144. PicBox.Width - 1, -NewValue)
  145. OldValue = NewValue
  146.  
  147. ' Step 7
  148. ' Return the Bitmap .
  149. Return bm
  150.  
  151.  
  152. ' Calculate length of baseline drawn by the code above
  153. BaseLineLength = PicBox.Width
  154. ' Calculate the width of each line segment
  155. LineWidth = (BaseLineLength / Sales.ToArray.Length)
  156. ' Step 8
  157. ' All done
  158. gr.Dispose()
  159.  
  160. End Function
  161.  
  162. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  163. picValues.Image = Me.DisplayVerticalValues(picValues, Chunks, CInt(txtMin.Text), CInt(txtMax.Text))
  164. ReadTemperature()
  165.  
  166. End Sub
  167.  
  168.  
  169. Private Function ReadTemperature()
  170. Dim strValue as string
  171. strValue = port2.ReadExisting
  172. 'picGraph.Image = DisplayGuidelinesAndChart(picGraph, Chunks, XMove, strvalue, CInt(txtMin.Text), CInt(txtMax.Text))
  173. picGraph.Image = DisplayGuidelinesAndChart(picGraph, Chunks, XMove, strvalue, CInt(txtMin.Text), CInt(txtMax.Text))
  174.  
  175. lblValue.Text = strvalue
  176. End Function
  177.  
  178. End Class

Kindly provide code or functions so that i accumulate reading data from serial port on graph upto 10 minutes.
Last edited by adatapost; Feb 1st, 2010 at 2:06 am. Reason: Added [code] tags. Encase your code in: [code] and [/code] tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
san.kothari is offline Offline
1 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: how to retrive data from hyperterminal?
Next Thread in VB.NET Forum Timeline: out of memory exception in XP but not 7





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC