SerialPort

lucgabon Messages postés 3 Date d'inscription dimanche 21 janvier 2007 Statut Membre Dernière intervention 17 juin 2007 - 13 juin 2007 à 20:23
lucgabon Messages postés 3 Date d'inscription dimanche 21 janvier 2007 Statut Membre Dernière intervention 17 juin 2007 - 17 juin 2007 à 10:48
je viens de débuter en VB, je cherche simplement pour l'instant d'afficher les bytes qui vienent sur le port com3 dans n RichTextBox

j'envoie sur le port rs232 des série de 17 bytes donc le premier et $FF

Merci pour vos réponse

Public Class FormBoeBot

    Private Sub ButtonGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGo.Click
        If LedGo.BackColor = Color.SandyBrown Then
            LedGo.BackColor = Color.OrangeRed
        Else
            LedGo.BackColor = Color.SandyBrown
        End If
    End Sub

 
    Private Sub SerialPortBoeBot_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPortBoeBot.DataReceived
        While SerialPortBoeBot.BytesToRead > 0
            RichTextBoxRS232.Text &= SerialPortBoeBot.ReadChar()
        End While
    End Sub

    Private Sub FormBoeBot_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SerialPortBoeBot.Open()
        MsgBox("OK", MsgBoxStyle.Information)
    End Sub

    Private Sub FormBoeBot_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
        SerialPortBoeBot.Close()
    End Sub

End Class

4 réponses

jers19 Messages postés 9 Date d'inscription mardi 5 juin 2007 Statut Membre Dernière intervention 18 juin 2007
13 juin 2007 à 21:55
Salut

As-tu quelques part dans ton programme configurer ton port série (vitesse, nbre de bits, parité,bit d'arrêt, protocole) ?
0
lucgabon Messages postés 3 Date d'inscription dimanche 21 janvier 2007 Statut Membre Dernière intervention 17 juin 2007
13 juin 2007 à 22:03
oui dans les propriétées de SerialPortRS232

com3
8 bits
Pas de parité
1 bit stop
flow control none
0
jers19 Messages postés 9 Date d'inscription mardi 5 juin 2007 Statut Membre Dernière intervention 18 juin 2007
14 juin 2007 à 20:03
Mais explique un peu, qu'est ce qui se passe quand tu exécutes le code ?
0
lucgabon Messages postés 3 Date d'inscription dimanche 21 janvier 2007 Statut Membre Dernière intervention 17 juin 2007
17 juin 2007 à 10:48
voici mon nouveau code

Public Class FormBoeBot

    Private Sub ButtonGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGo.Click
        If LedGo.BackColor = Color.SandyBrown Then
            LedGo.BackColor = Color.OrangeRed
        Else
            LedGo.BackColor = Color.SandyBrown
        End If
    End Sub

 
    Private Sub SerialPortBoeBot_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPortBoeBot.DataReceived
        While SerialPortBoeBot.BytesToRead > 0
            RichTextBoxRS232.Text &= SerialPortBoeBot.ReadChar()
        End While
    End Sub

    Private Sub FormBoeBot_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'initialise Timer
        EchRS232.Interval = 1000
        EchRS232.Start()
        'initialise le port Com
        SerialPortBoeBot.BaudRate = 9600
        SerialPortBoeBot.PortName = "COM3"
        SerialPortBoeBot.DataBits = 8
        SerialPortBoeBot.StopBits = IO.Ports.StopBits.One
        SerialPortBoeBot.Parity = IO.Ports.Parity.None
        SerialPortBoeBot.Handshake = IO.Ports.Handshake.None
        SerialPortBoeBot.Open()
    End Sub

    Private Sub FormBoeBot_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
        SerialPortBoeBot.Close()
    End Sub

    Private Sub EchRS232_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EchRS232.Tick
        LedRx.BackColor = Color.Green
        RichTextBoxRS232.Text &= "Lecture " & SerialPortBoeBot.BytesToRead & Chr(13)
        While SerialPortBoeBot.BytesToRead > 0
            RichTextBoxRS232.Text &= Chr(SerialPortBoeBot.ReadChar())
        End While
        LedRx.BackColor = Color.PaleGreen
        EchRS232.Start()
    End Sub
End Class

et voici ce que j'obtien dans la fenetre RichTextBox

Lecture 22
?�13;?�12;?�13;?????M?A?@?@?A??Lecture 0
Lecture 0
Lecture 0
Lecture 0

a chaque fois que le programe ce lance, j'ai un serie de caractére qui s'affiche et apres plus rien, même si je n'émet plus sur le port série

Merci de vos message
0
Rejoignez-nous