Public Sub RS232_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles RS232.DataReceived 'Me.Invoke(New Affiche_reception(AddressOf Affiche_reception), donnee) Me.Invoke(New EventHandler(AddressOf Affiche_reception)) End Sub 'Public Sub Affiche_reception(ByVal donnee As String) Public Sub Affiche_reception() Dim donnee As String = RS232.ReadExisting msgrecu.Text &= donnee End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionCes deux SUB me permettent de lire et d'afficher sur le port RS232.
Mon problème est qu'il faudrait que ces deux SUB fonctionnent pendant que un autre SUB est exécuté
Imports System Imports System.Threading Imports System.ComponentModel Imports System.IO.Ports Imports System.IO Imports System.IO.File Public Class Form1 Public Sub pause(ByVal seconde As Integer) Thread.Sleep(seconde) End Sub Private Delegate Sub _Affiche_reception() Dim type_mesure As String = "" Dim val_mesure As String = "" Dim testbon As Byte = 0 Dim nbrtest As Byte = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button2.Enabled = True Button1.Enabled = False RS232.Open() RS232.Write("REM" + Chr(10)) pause(500) RS232.Write("SRQ" + Chr(10)) pause(500) RS232.Write("*IDN?" + Chr(10)) Affiche_reception() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If cmdtxt.Text "" Or numserie.Text "" Then MsgBox("Entrez un nom de fichier et un numéro de série") Exit Sub ElseIf Exists("C:\Users\valentin\Desktop\stage\Fichier_commande" + cmdtxt.Text + ".Txt") Then Else MsgBox("Le fichier n'existe pas, veuillez saisir un nom de fichier existant") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Button1.Enabled = True Button2.Enabled = False RS232.Write("GTL" + Chr(10)) RS232.Close() Me.Close() End Sub 'Bouton démarré Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If RS232.IsOpen Then Dim nbr_ligne As Integer = 0 Dim ligne As String Dim sr As New StreamReader("C:\Users\valentin\Desktop\stage\Fichier_commande" + cmdtxt.Text + ".Txt") Dim path As String = "C:\Users\valentin\Desktop\stage\Fichier_commande" + cmdtxt.Text + "Résultat.Txt" Dim sw As StreamWriter Try If File.Exists(path) = False Then sw = File.CreateText(path) sw.Flush() sw.Close() End If Catch ex As Exception End Try sw = File.AppendText(path) sw.WriteLine(numserie.Text) While sr.Peek <> -1 nbr_ligne += 1 ligne = sr.ReadLine() Select Case nbr_ligne Case 1 RS232.Write("CONF:FILT " & ligne + Chr(10)) pause(500) RS232.Write("*ESR?" + Chr(10)) Affiche_reception() If msgrecu.Text "#H10" Or msgrecu.Text "#H90" Then MsgBox("Erreur de dialogue de type 2") Exit Sub ElseIf msgrecu.Text "#H20" Or msgrecu.Text "#HA0" Then MsgBox("Erreur de dialogue de type 1") Exit Sub End If pause(500) RS232.Write("QUIT" + Chr(10)) pause(500) Case Else nbrtest += 1 If ligne "MEG" Or ligne "RIG" Then If ligne = "MEG" Then nbr_ligne += 1 ligne = sr.ReadLine() RS232.Write("MEG" + Chr(10)) pause(500) Dim MEGstring As String = ligne Dim MEGarray() As String = Split(MEGstring, "/") RS232.Write("MEG:Par 1:" + MEGarray(0) + ":CBHLIM " + MEGarray(1) + ":LLIM " + MEGarray(2) + ":HTIM " + MEGarray(3) + ":RTIM " + MEGarray(4) + ":FTIM " + MEGarray(5) + Chr(10)) pause(500) type_mesure += "/MEG" ElseIf ligne = "RIG" Then nbr_ligne += 1 ligne = sr.ReadLine() RS232.Write("HIP" + Chr(10)) pause(500) Dim HIPstring As String = ligne Dim HIParray() As String = Split(HIPstring, "/") RS232.Write("HIP:Par 1:" + HIParray(0) + ":HTIM " + HIParray(1) + ":RTIM " + HIParray(2) + ":FTIM " + HIParray(3) + ":CBHLIM " + HIParray(4) + ":LLIM " + HIParray(5) + ":DET " + HIParray(6) + ":IDE " + HIParray(7) + ":RDET " + HIParray(8) + ":IMRA " + HIParray(9) + ":IDERA " + HIParray(10) + Chr(10)) pause(500) type_mesure += "/RIG" End If RS232.Write("*ESR?" + Chr(10)) Affiche_reception() If msgrecu.Text "H10" Or msgrecu.Text "H90" Then MsgBox("Erreur de dialogue de type 2") Exit Sub ElseIf msgrecu.Text "H20" Or msgrecu.Text "HA0" Then MsgBox("Erreur de dialogue de type 1") Exit Sub End If pause(500) RS232.Write("*LRN?" + Chr(10)) Affiche_reception() pause(500) RS232.Write("MEAS" + Chr(10)) Affiche_reception() pause(500) RS232.Write("STOP" + Chr(10)) pause(500) RS232.Write("*STB?" + Chr(10)) Affiche_reception() pause(500) If msgrecu.Text = "H3" Then MsgBox("Boucle de sécurité ouverte") Exit Sub ElseIf msgrecu.Text = "H2" Then MsgBox("Erreur, tension incorrecte") Exit Sub ElseIf msgrecu.Text = "H1" Then MsgBox("Test mauvais") Exit Sub Else msgrecu.Text = "H9" Then RS232.Write("MEAS?" + Chr(10)) Affiche_reception() testbon += 1 val_mesure += "/" + msgrecu.Text RS232.Write("STOP" + Chr(10)) pause(500) RS232.Write("QUIT" + Chr(10)) pause(500) RS232.Write("*CLS" + Chr(10)) pause(500) End If Else MsgBox("Erreur d'écriture") End If End Select End While If nbrtest = testbon Then sw.WriteLine("Résultat : test bon") Voyant.BackColor = Color.LightSeaGreen Else sw.WriteLine("Résultat : test mauvais") Voyant.BackColor = Color.Red End If sw.WriteLine(type_mesure) sw.WriteLine(val_mesure) sw.Flush() sw.Close() sr.Close() type_mesure = "" val_mesure = "" MsgBox("Fin du fichier") Else MsgBox("Cliquez sur le bouton connecter") Exit Sub End If nbrtest testbon 0 Demande.Show() Me.Visible = False End Sub Public Sub RS232_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles RS232.DataReceived Me.Invoke(New EventHandler(AddressOf Affiche_reception)) End Sub Public Sub Affiche_reception() Dim donnee As String = RS232.ReadExisting msgrecu.Text &= donnee End Sub
'Tu mets donnee en tant que variable publique et: donnee &= RS232.ReadExisting msgrecu.Text &= donnee If donnee.Contains(Chr(13)) Then Dim Str As String = donnee.ToCharArray(0, (InStr(donnee, Chr(13), CompareMethod.Text) - 1)) donnee.Remove(0, (InStr(donnee, Chr(13), CompareMethod.Text))) ListBox1.Items.Add(Str) End If
RS232.Write("*ESR?" + Chr(10)) Affiche_reception(
RS232.Write("*ESR?" + Chr(10)) Affiche_reception()
RS232.Write("*LRN?" + Chr(10)) Affiche_reception()
RS232.Write("*STB?" + Chr(10)) Affiche_reception()
RS232.Write("*ESR?" & Chr(10) & "*STB?" & Chr(10))
imports system.io
Dim dir As New DirectoryInfo("C:\chemin") ComboBox1.DataSource = dir.GetFiles("*.*")
Dim dir As New DirectoryInfo("C:\chemin") ComboBox1.DataSource = dir.GetFiles("*.txt")
Public Sub RS232_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Me.Invoke(New EventHandler(AddressOf Affiche_reception)) End Sub 'Public Sub Affiche_reception(ByVal donnee As String) Public Sub Affiche_reception() donnee &= RS232.ReadExisting if donnee.contains (ChrSpécial) then end if End Sub
Public Sub Affiche_reception()
Public Class Form1 Dim ZorroEstArrive As Boolean
Public Sub Affiche_reception() donnee = RS232.ReadExisting if donnee.contains (ChrSpécial) then ZorroEstArrive = true else ZorroEstArrive = false end if 'Après tu sais si ton programme doit continuer ou pas Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click if ZorroEstArrive = false then exit sub 'Blablabla end sub