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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
| Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Public valeuraxe As String = 1500
Dim k As Double = 1
Private X As Integer = 0
Private Ytemp As Integer 'coordonnées Y pour le graph de température
Private seuilT As Integer 'seuil de température
Private Imagetemp As Bitmap = New Bitmap(600, 400)
Private Imagetemp1 As Bitmap = New Bitmap(609, 20) 'image pour le dessin de la temprérature
'image pour le dessin de la temprérature
Private valseuiltemp As String 'chaine qui contiendra le suil de température
Private tabtemp(540) As Point 'Déclaration du tableau de sauvegarde des températures
Dim cpt As Integer
Dim adipp As String
Public toto As String
Dim tutu As String
Dim bol As Boolean = False
Dim echel As Boolean = False
Dim echel1 As Boolean = False
Dim cptpoint As Integer
Private Shared mcastAddress As IPAddress
Private Shared mcastPort As Integer
Private Shared mcastSocket As Socket
Private Shared mcastOption As MulticastOption
Dim result As List(Of String)
Dim imm1 As Double
Dim imm2 As Double
Dim titi As Integer
Dim affich As Boolean
Dim Va As Double
Dim celip As String
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Dim path As String = Directory.GetCurrentDirectory() & "\myip.txt"
If bol = False Then
If File.Exists(path) = True Then
Using sr As StreamReader = File.OpenText(path)
Do While sr.Peek() >= 0
adipp = sr.ReadLine()
Loop
End Using
bol = True
Timer1.Enabled = True
End If
End If
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
AboutBox1.ShowDialog()
'MsgBox("Le logiciel toto+ est libre d'utilisation. Son code source reste la propriétée de son concepteur.")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Location = New Point(0, 0)
Dim path As String = Directory.GetCurrentDirectory() & "\myip.txt"
cptpoint = 0
affich = True
If File.Exists(path) = False Then
Timer1.Enabled = False
Form2.ShowDialog()
Else
Using sr As StreamReader = File.OpenText(path)
Do While sr.Peek() >= 0
adipp = sr.ReadLine()
Loop
End Using
Timer1.Enabled = True
'Timer2.Enabled = True
End If
cpt = 0
End Sub
Private Sub StartMulticast()
Try
mcastSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim localIPAddr As IPAddress = IPAddress.Parse(adipp)
'IPAddress localIP = IPAddress.Any;
Dim localEP As EndPoint = CType(New IPEndPoint(localIPAddr, mcastPort), EndPoint)
mcastSocket.Bind(localEP)
' Define a MulticastOption object specifying the multicast group
' address and the local IPAddress.
' The multicast group address is the same as the address used by the server.
mcastOption = New MulticastOption(mcastAddress, localIPAddr)
mcastSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mcastOption)
Catch e As Exception
'MsgBox(e.ToString())
End Try
End Sub 'StartMulticast
Public Sub ReceiveBroadcastMessages()
Dim done As Boolean = False
Dim bytes() As Byte = New [Byte](99) {}
Dim groupEP As New IPEndPoint(mcastAddress, mcastPort)
Dim remoteEP As EndPoint = CType(New IPEndPoint(IPAddress.Any, 0), EndPoint)
Try
mcastSocket.ReceiveTimeout = 1000
mcastSocket.ReceiveFrom(bytes, remoteEP)
toto = Encoding.ASCII.GetString(bytes, 0, bytes.Length)
TextBox1.Text = toto
result = decoup(";", TextBox1.Text)
Me.Text = "toto " & result(0)
Label1.Text = result(2)
Label2.Text = result(4)
Label3.Text = result(3) & "°"
calcul()
If affich = True Then
Label4.Text = CDbl(result(1)) + 14
Else
Label4.Text = Va
End If
If (CDbl(result(1)) + 14) > 15 And (CDbl(result(1)) + 14 < 16) Then
celip = "Derniére CEL à l'IP le : " & Now() & vbCrLf & "est de: " & result(2)
End If
Button2.Enabled = True
mcastSocket.Close()
Catch e As Exception
'Ne pas oublier le ".close" qui permet de pouvoir relançer l'acquisition
mcastSocket.Close()
Timer1.Enabled = False
Timergraphe.Enabled = False
Button2.Enabled = False
titi = 0
OvalShape1.BackColor = Color.Red
cptpoint = 0
MsgBox("Déconnecté")
Label1.Text = "-----"
Label2.Text = "-----"
Label3.Text = "-----"
Label4.Text = "-----"
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
mcastAddress = IPAddress.Parse("225.0.1.30")
mcastPort = 8000
' Start a multicast group.
StartMulticast()
' Receive broadcast messages.
ReceiveBroadcastMessages()
End Sub
Private Sub OvalShape1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OvalShape1.Click
If Timer1.Enabled = False Then
Timer1.Enabled = True
OvalShape1.BackColor = Color.Green
End If
End Sub
Private Function decoup(ByVal sepa As String, ByVal chaine As String)
Dim pars As New List(Of String) 'pars est du type list. Sa valeur commence par 0
Dim splichaine() As String = Split(chaine, sepa)
Dim LastNonEmpty As Integer = -1
For i As Integer = 0 To splichaine.Length - 1
If splichaine(i) <> "" Then
LastNonEmpty += 1
splichaine(LastNonEmpty) = splichaine(i)
pars.Add(splichaine(i))
End If
Next
ReDim Preserve splichaine(LastNonEmpty)
Return pars
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.ShowDialog()
End Sub
Private Function scribe(ByVal tps As String)
Dim sw As StreamWriter
Dim path As String = Directory.GetCurrentDirectory() & "\sauv.csv"
' This text is added only once to the file.
If File.Exists(path) = False Then
sw = File.CreateText(path)
sw.Close()
End If
sw = File.AppendText(path)
sw.WriteLine(tps)
sw.Close()
End Function
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
If affich = True Then
Label4.Text = Va
GroupBox4.Text = "Vitesse as."
affich = False
ElseIf affich = False Then
Label4.Text = CDbl(result(1)) + 14
GroupBox4.Text = "Immersion."
affich = True
End If
End Sub
Private Function calcul()
If titi = 0 Then
imm1 = CDbl(result(1))
ElseIf titi = 2 Then
imm2 = CDbl(result(1))
Va = (imm1 - imm2) / 2
Va = Math.Round(Va, 3)
titi = 0
Exit Function
End If
titi = titi + 1
End Function
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
MsgBox(celip)
End Sub
Private Sub Timergraphe_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timergraphe.Tick
Dim essai As String
Dim temp As Graphics = Graphics.FromImage(Imagetemp)
Dim temp2 As Graphics = Graphics.FromImage(Imagetemp1)
Dim police As Font
Dim policetitre As Font
police = New Font("arial", 10) 'police qui servt pour la legende
policetitre = New Font("arial", 15) 'police qui sert pour les titres de graph
'efface les pictureboxs pour eviter la supperposition de traits.
temp.Clear(Color.WhiteSmoke)
temp2.Clear(Color.WhiteSmoke)
'convertion d'echelle pour les valeurs
'température
essai = Mid(result(2), 6, 1)
essai = CInt(("0," & essai) * 8) / k
Ytemp = Mid(result(2), 1, 4) - valeuraxe '
Ytemp = 200 - Ytemp * 8 / k
'pression
If Ytemp >= 0 Then
Ytemp = Ytemp - essai
ElseIf Ytemp < 0 Then
Ytemp = Ytemp + essai
End If
tabtemp(X) = New Point(X, Ytemp) 'tableau qui contiendra les points de température
'decalage des tableaux pour donner l'impressioin de courbes temps reel
If X = 540 Then
For I As Integer = 0 To 539
tabtemp(I).Y = tabtemp(I + 1).Y
Next
X = X - 1 'annule la fyture incrémentation de X
End If
X = X + 1 'permet de tracer au prochain tou le point d'abscisse supérieur
'tracé des arrières plans
temp.DrawLine(Pens.Brown, New Point(60, 30), New Point(60, 370))
temp.DrawLine(Pens.Brown, New Point(120, 30), New Point(120, 370))
temp.DrawLine(Pens.Brown, New Point(180, 30), New Point(180, 370))
temp.DrawLine(Pens.Brown, New Point(240, 30), New Point(240, 370))
temp.DrawLine(Pens.Brown, New Point(300, 30), New Point(300, 370))
temp.DrawLine(Pens.Brown, New Point(360, 30), New Point(360, 370))
temp.DrawLine(Pens.Brown, New Point(0, 0), New Point(0, 370))
temp.DrawLine(Pens.Brown, New Point(420, 30), New Point(420, 370))
temp.DrawLine(Pens.Brown, New Point(480, 30), New Point(480, 370))
temp.DrawLine(Pens.Brown, New Point(540, 30), New Point(540, 370))
'temp.DrawString("9", police, Brushes.Black, 536, 390)
'graduations température
'temp.DrawLine(Pens.Green, New Point(0, 20), New Point(550, 20))
temp.DrawLine(Pens.Green, New Point(0, 160), New Point(550, 160))
temp.DrawLine(Pens.Green, New Point(0, 120), New Point(550, 120)) '1510
temp.DrawLine(Pens.Green, New Point(0, 80), New Point(550, 80))
temp.DrawLine(Pens.Green, New Point(0, 40), New Point(550, 40)) '1520
' temp.DrawLine(Pens.Green, New Point(0, 380), New Point(550, 380))
temp.DrawLine(Pens.Green, New Point(0, 360), New Point(550, 360))
temp.DrawLine(Pens.Green, New Point(0, 320), New Point(550, 320))
temp.DrawLine(Pens.Green, New Point(0, 280), New Point(550, 280))
temp.DrawLine(Pens.Green, New Point(0, 240), New Point(550, 240))
temp.DrawString(valeuraxe + 5 * k, police, Brushes.Black, 548, 152)
temp.DrawString(valeuraxe + 10 * k, police, Brushes.Black, 548, 112)
temp.DrawString(valeuraxe + 15 * k, police, Brushes.Black, 548, 72)
temp.DrawString(valeuraxe + 20 * k, police, Brushes.Black, 548, 32)
temp.DrawString(valeuraxe, police, Brushes.Black, 548, 192)
'temp.DrawString("1455", police, Brushes.Black, 548, 372)
temp.DrawString(valeuraxe - 20 * k, police, Brushes.Black, 548, 352)
temp.DrawString(valeuraxe - 15 * k, police, Brushes.Black, 548, 312)
temp.DrawString(valeuraxe - 10 * k, police, Brushes.Black, 548, 272)
temp.DrawString(valeuraxe - 5 * k, police, Brushes.Black, 548, 232)
'tracé des titres des graphs
temp.DrawString("CELERITE/TEMPS", policetitre, Brushes.DarkSlateGray, 110, 5)
'tracé des valeurs de seuil
'température
'valseuiltemp = "seuil : " & stationmeteo.Seuiltemp_indic.Text
' temp.DrawString(valseuiltemp, police, Brushes.DarkSeaGreen, 5, 7)
'pression
' valseuilpress = "seuil : " & stationmeteo.seuilpress_indic.Text
' press.DrawString(valseuilpress, police, Brushes.DarkSeaGreen, 5, 7)
'tracé des seuils
'temp.DrawLine(Pens.Red, New Point(0, seuilT), New Point(600, seuilT)) 'température
temp.DrawLine(Pens.Red, New Point(0, 200), New Point(600, 200)) 'température
'tracé des courbes
For I As Integer = 0 To 539
'courbe de température
If tabtemp(I + 1) <> New Point(0, 0) Then
temp.DrawLine(Pens.Blue, tabtemp(I), tabtemp(I + 1))
Select Case I
Case Is = 0
temp2.DrawString("0", police, Brushes.Black, 0, 5)
Case Is = 60
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("1", police, Brushes.Black, 0, 5)
temp2.DrawString("0", police, Brushes.Black, 56, 5)
Case Is = 120
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("2", police, Brushes.Black, 0, 5)
temp2.DrawString("1", police, Brushes.Black, 56, 5)
temp2.DrawString("0", police, Brushes.Black, 116, 5)
Case Is = 180
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("3", police, Brushes.Black, 0, 5)
temp2.DrawString("2", police, Brushes.Black, 56, 5)
temp2.DrawString("1", police, Brushes.Black, 116, 5)
temp2.DrawString("0", police, Brushes.Black, 176, 5)
Case Is = 240
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("4", police, Brushes.Black, 0, 5)
temp2.DrawString("3", police, Brushes.Black, 56, 5)
temp2.DrawString("2", police, Brushes.Black, 116, 5)
temp2.DrawString("1", police, Brushes.Black, 176, 5)
temp2.DrawString("0", police, Brushes.Black, 236, 5)
Case Is = 300
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("5", police, Brushes.Black, 0, 5)
temp2.DrawString("4", police, Brushes.Black, 56, 5)
temp2.DrawString("3", police, Brushes.Black, 116, 5)
temp2.DrawString("2", police, Brushes.Black, 176, 5)
temp2.DrawString("1", police, Brushes.Black, 236, 5)
temp2.DrawString("0", police, Brushes.Black, 296, 5)
Case Is = 360
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("6", police, Brushes.Black, 0, 5)
temp2.DrawString("5", police, Brushes.Black, 56, 5)
temp2.DrawString("4", police, Brushes.Black, 116, 5)
temp2.DrawString("3", police, Brushes.Black, 176, 5)
temp2.DrawString("2", police, Brushes.Black, 236, 5)
temp2.DrawString("1", police, Brushes.Black, 296, 5)
temp2.DrawString("0", police, Brushes.Black, 356, 5)
Case Is = 420
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("7", police, Brushes.Black, 0, 5)
temp2.DrawString("6", police, Brushes.Black, 56, 5)
temp2.DrawString("5", police, Brushes.Black, 116, 5)
temp2.DrawString("4", police, Brushes.Black, 176, 5)
temp2.DrawString("3", police, Brushes.Black, 236, 5)
temp2.DrawString("2", police, Brushes.Black, 296, 5)
temp2.DrawString("1", police, Brushes.Black, 356, 5)
temp2.DrawString("0", police, Brushes.Black, 416, 5)
Case Is = 480
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("8", police, Brushes.Black, 0, 5)
temp2.DrawString("7", police, Brushes.Black, 56, 5)
temp2.DrawString("6", police, Brushes.Black, 116, 5)
temp2.DrawString("5", police, Brushes.Black, 176, 5)
temp2.DrawString("4", police, Brushes.Black, 236, 5)
temp2.DrawString("3", police, Brushes.Black, 296, 5)
temp2.DrawString("2", police, Brushes.Black, 356, 5)
temp2.DrawString("1", police, Brushes.Black, 416, 5)
temp2.DrawString("0", police, Brushes.Black, 476, 5)
Case Is = 539
temp2.Clear(Color.WhiteSmoke)
temp2.DrawString("9", police, Brushes.Black, 0, 5)
temp2.DrawString("8", police, Brushes.Black, 56, 5)
temp2.DrawString("7", police, Brushes.Black, 116, 5)
temp2.DrawString("6", police, Brushes.Black, 176, 5)
temp2.DrawString("5", police, Brushes.Black, 236, 5)
temp2.DrawString("4", police, Brushes.Black, 296, 5)
temp2.DrawString("3", police, Brushes.Black, 356, 5)
temp2.DrawString("2", police, Brushes.Black, 416, 5)
temp2.DrawString("1", police, Brushes.Black, 476, 5)
temp2.DrawString("0", police, Brushes.Black, 536, 5)
End Select
End If
Next
'enregistrement des images
Graphtemp.Image = Imagetemp 'courbe température
PictureBox1.Image = Imagetemp1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Label6.Visible = True
Label7.Visible = True
Label8.Visible = True
Label9.Visible = True
Label10.Visible = True
Label11.Visible = True
Label12.Visible = True
If echel = False Then
Timergraphe.Enabled = True
seuilT = Str(result(2)) - valeuraxe
seuilT = 200 + seuilT * 8 / k
echel = True
Else
Timergraphe.Enabled = False
echel = False
End If
End Sub
Private Sub Graphtemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Graphtemp.Click
Dim xr As Integer
Dim yr As Integer
Dim cel As String
xr = MousePosition.X - 12
yr = MousePosition.Y - 292
' MsgBox(xr & " / " & yr)
cel = valeuraxe - ((yr - 221) / 8) * k
If echel1 = False Then
Label9.Text = xr
Label8.Text = FormatNumber(Convert.ToDecimal(cel), 1)
echel1 = True
Else
Label11.Text = xr
Label10.Text = FormatNumber(Convert.ToDecimal(cel), 1)
Label12.Text = "variation de " & FormatNumber(CDbl(Label10.Text) - CDbl(Label8.Text), 1) & " en " & CDbl(Label11.Text) - CDbl(Label9.Text) & " secondes"
echel1 = False
End If
End Sub
Private Sub Graphtemp_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Graphtemp.MouseMove
Dim xr As Integer
Dim yr As Integer
Dim cel As String
xr = MousePosition.X - 12
yr = MousePosition.Y - 292
' MsgBox(xr & " / " & yr)
cel = valeuraxe - ((yr - 221) / 8) * k
If echel1 = False Then
Label9.Text = xr
Label8.Text = FormatNumber(Convert.ToDecimal(cel), 1)
Else
Label11.Text = xr
Label10.Text = FormatNumber(Convert.ToDecimal(cel), 1)
End If
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
valeuraxe = ComboBox1.Text
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If k = 1 Then
k = 0.5
Button3.Text = "Revenir"
Else
k = 1
Button3.Text = "ZOOM x 2"
End If
End Sub
End Class |
Partager