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
| Option Strict On
Option Explicit On
Imports System.IO
Imports System
Public Class Form1
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Short
Dim nom_fichier As String = "c:\temperature\temperature.txt"
Private Sub btn_depart_Click(sender As Object, e As EventArgs) Handles btn_depart.Click
btn_depart.Visible = False
Lab_sortie.Visible = True
Call ReceptionDonnesSerie()
End
End Sub
Private Sub btn_stop_Click(sender As Object, e As EventArgs)
btn_depart.Visible = True
Lab_sortie.Visible = False
End
End Sub
Sub ReceptionDonnesSerie()
' Receive strings from a serial port.
Dim reponse As MsgBoxResult
Dim com As IO.Ports.SerialPort = Nothing
Dim Incoming As String = com.ReadLine()
Dim lecture As String = ""
Try
com = My.Computer.Ports.OpenSerialPort("COM6")
com.ReadTimeout = 61000
Do
Lab_temp.Text = Incoming
Lab_date.Text = Date.Now.ToString("HH:mm")
Refresh()
Call sauvegarde()
Loop
Catch ex As TimeoutException
lecture = "Error: Serial Port read timed out."
Finally
If com IsNot Nothing Then com.Close()
End Try
If (GetAsyncKeyState(27) <> 0) Then
reponse = MsgBox("Arrêt programme ?", MsgBoxStyle.YesNo, "CONTROLE")
If reponse = vbYes Then
BackgroundWorker1.CancelAsync()
End If
End If
End Sub
Sub sauvegarde()
My.Computer.FileSystem.WriteAllText(nom_fichier, Lab_date.Text & ";" & Lab_temp.Text & Convert.ToChar(13) & Convert.ToChar(10), True) 'création fichier si necessaire et écriture
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
End Sub
End Class |
Partager