1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| Dim listeports As String
Dim police1 As New Font("arial", 10, FontStyle.Regular, GraphicsUnit.Pixel)
Dim longueur As Integer = 420
Dim hauteur As Integer = 200
'température
Dim X_T As Integer
Dim Y_T As Integer
Dim pas_T As Integer = 1
Dim zoom_T As Integer = 20
Dim orig_T As Integer = 20
Dim tableau_T(longueur, 1) As Integer
Dim Image_T As Bitmap = New Bitmap(longueur, hauteur)
Dim graphics_T As Graphics = Graphics.FromImage(Image_T)
'PH
Dim X_PH As Integer
Dim Y_PH As Integer
Dim pas_PH As Integer = 1
Dim zoom_PH As Integer = 60
Dim orig_PH As Integer = 4
Dim tableau_PH(longueur, 1) As Integer
Dim Image_PH As Bitmap = New Bitmap(longueur, hauteur)
Dim graphics_PH As Graphics = Graphics.FromImage(Image_PH)
Dim Y2 As Integer
Dim X As Integer = 0 'coordonnées X pour le graph
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call add_console("Demarrage...")
If Not (SerialPort1.IsOpen = True) Then
SerialPort1.Open()
Call add_console("Ouverture du port COM")
Else : Call add_console("Problème port COM deja ouvert")
End If
Timer.Enabled = True
For Each str As String In SerialPort.GetPortNames()
DirectCast(ComboPorts, ComboBox).Items.Add(str)
Next
End Sub
Private Sub add_console(ByVal Chaine As String)
Console.Items.Insert(0, System.DateTime.Now.ToString & " " & Chaine)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer.Tick
Y_T = valeur1box.Value
Y_PH = valeur2box.Value
draw_graph(Graph_T, graphics_T, Image_T, X_T, Y_T, tableau_T, zoom_T, orig_T, pas_T)
draw_graph(Graph_PH, graphics_PH, Image_PH, X_PH, Y_PH, tableau_PH, zoom_PH, orig_PH, pas_PH)
End Sub
Private Sub draw_graph(ByRef graph, ByVal graphics, ByVal image, ByRef X, ByVal Y, ByVal tableau, ByVal zoom, ByVal orig, ByVal pas)
graphics.Clear(Color.Black) 'efface les pictureboxs pour eviter la supperposition de traits
'recup des valeurs
tableau(X, 0) = Y 'on place la valeur brute dans le tableau
tableau(X, 1) = scal(Y, orig, zoom) 'mise à l'echelle dans le tableau
'trace ligne
Y2 = hauteur + orig * zoom
pas = pas * zoom 'on convertit 'pas' en valeur graphique
Do Until Y2 < 0
Y2 = Y2 - pas
graphics.DrawLine(Pens.Gray, longueur, Y2, 0, Y2) 'trace la ligne
graphics.DrawString(unscal(Y2, orig, zoom), police1, Brushes.Blue, 0, Y2 - 12)
Loop
For I As Integer = 0 To longueur - 1 'on trace les lignes formant la courbe
If tableau(I + 1, 0) <> 0 Then 'on ne trace pas si il n'y a pas de valeur
graphics.DrawLine(Pens.Blue, I, tableau(I, 1), I + 1, tableau(I + 1, 1))
End If
Next
If X = longueur Then 'la courbe arrive au bout du graph, alors decalage du tableau vers la gauche,
X = longueur
Array.Copy(tableau, 2, tableau, 0, tableau.Length - 2) 'on remonte les données, on decalle vers la gauche le graphe
Else 'on ne decalle pas le tableau
X = X + 1
End If
'enregistrement des images
graph.Image = image 'on mets l'image temp dans la picturebox
End Sub
Private Function scal(ByVal Y, ByVal orig, ByVal zoom)
Return hauteur + zoom * orig - Y * zoom
End Function
Private Function unscal(ByVal Y, ByVal orig, ByVal zoom)
Return (hauteur + zoom * orig - Y) / zoom
End Function
End Class |
Partager