IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Application VB.net 2010


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2013
    Messages : 9
    Par défaut Application VB.net 2010
    slt
    svp on veut s'avoir comment faire une communication entre PC et Récepteur de Basse fréquence en utilisent SerialPort RS32 (VB 10 express )
    merci

  2. #2
    Modérateur
    Avatar de DotNetMatt
    Homme Profil pro
    CTO
    Inscrit en
    Février 2010
    Messages
    3 611
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : CTO
    Secteur : Finance

    Informations forums :
    Inscription : Février 2010
    Messages : 3 611
    Billets dans le blog
    3
    Par défaut
    Less Is More
    Pensez à utiliser les boutons , et les balises code
    Desole pour l'absence d'accents, clavier US oblige
    Celui qui pense qu'un professionnel coute cher n'a aucune idee de ce que peut lui couter un incompetent.

  3. #3
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2013
    Messages : 9
    Par défaut
    Slt
    j'ai arrivé de faire la réception entre pc et un récepteur avec càble RS32 mais à la réception les données ne sont pas clair ; ils sont écris en "?" ;voici le code SVP trouvez moi une solution

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Imports System
    Imports System.ComponentModel
    Imports System.Threading
    Imports System.IO.Ports
     
     
     
    Public Class Form1
        Dim myPort As Array  'COM Ports detected on the system will be stored here
        Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data
     
     
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'When our form loads, auto detect all serial ports in the system and populate the cmbPort Combo box.
            myPort = IO.Ports.SerialPort.GetPortNames() 'Get all com ports available
            ComboBox2.Items.Add(9600)     'Populate the cmbBaud Combo box to common baud rates used
            ComboBox2.Items.Add(19200)
            ComboBox2.Items.Add(38400)
            ComboBox2.Items.Add(57600)
            ComboBox2.Items.Add(115200)
     
            For i = 0 To UBound(myPort)
                ComboBox1.Items.Add(myPort(i))
            Next
            ComboBox1.Text = ComboBox1.Items.Item(0)    'Set cmbPort text to the first COM port detected
            ComboBox2.Text = ComboBox2.Items.Item(0)    'Set cmbBaud text to the first Baud rate on the list
     
            Button2.Enabled = False           'Initially Disconnect Button is Disabled
        End Sub
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            SerialPort1.PortName = ComboBox1.Text         'Set SerialPort1 to the selected COM port at startup
            SerialPort1.BaudRate = ComboBox2.Text         'Set Baud rate to the selected value on
     
            'Other Serial Port Property
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8            'Open our serial port
            SerialPort1.Open()
     
            Button1.Enabled = False          'Disable Connect button
            Button2.Enabled = True        'and Enable Disconnect button
        End Sub
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
     
            SerialPort1.Close()             'Close our Serial Port
     
            Button1.Enabled = True
            Button2.Enabled = False
        End Sub
     
     
     
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
     
            If SerialPort1.IsOpen = False Then
                SerialPort1.PortName = ComboBox1.Text         'pop a message box to user if he is changing ports
            Else                                                                               'without disconnecting first.
                MsgBox("Valid only if port is Closed", vbCritical)
            End If
        End Sub
     
        Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            ReceivedText(SerialPort1.ReadExisting())    'Automatically called every time a data is received at the serialPort
            'compares the ID of the creating Thread to the ID of the calling Thread
     
        End Sub
        Private Sub ReceivedText(ByVal [text] As String)
            If Me.RichTextBox1.InvokeRequired Then
                Dim x As New SetTextCallback(AddressOf ReceivedText)
                Me.Invoke(x, New Object() {(text)})
     
     
            Else
                Me.RichTextBox1.Text &= [text]
            End If
        End Sub
     
        Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
            If SerialPort1.IsOpen = False Then
                SerialPort1.BaudRate = ComboBox2.Text         'pop a message box to user if he is changing baud rate
            Else                                                                                'without disconnecting first.
                MsgBox("Valid only if port is Closed", vbCritical)
            End If
        End Sub
     
    End Class

  4. #4
    Membre émérite
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2012
    Messages
    337
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2012
    Messages : 337
    Par défaut
    J'adore la réponse de DotNetMatt

  5. #5
    Membre actif
    Homme Profil pro
    Technicien Help Desk
    Inscrit en
    Novembre 2006
    Messages
    129
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Technicien Help Desk
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Novembre 2006
    Messages : 129
    Par défaut
    Salut,

    Déjà, il faudrait que tu utilise les balise CODE (dièse dans la saisie) pour qu'on arrive à lire un truc faisable.

    Ensuite, l'event DataReceived est très rapide, je te conseille de mettre une Sleep avant la fonction pour être sur que toute la réponse soit arrivée avant de la traiter, ca économisera un peu les ressources du PC.

    Le stockage de la trame dans un TextBox est pour le retraitement derrière ? Est-ce que tu connais ton protocole et la structure de la trame de retour ?

  6. #6
    Membre habitué
    Homme Profil pro
    Étudiant
    Inscrit en
    Mars 2013
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Mars 2013
    Messages : 9
    Par défaut
    Slt
    non je ne connais pas la structure de trame mais je Crois que le protocole est celle de Null modem (MODBUS?!!!)
    Merci

Discussions similaires

  1. [Débutant] Application VB.net 2010
    Par taher025 dans le forum VB.NET
    Réponses: 2
    Dernier message: 17/05/2013, 14h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo