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 :

Interface port serial transférer et réception de fichier


Sujet :

VB.NET

  1. #1
    Membre confirmé
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2015
    Messages : 131
    Par défaut Interface port serial transférer et réception de fichier
    bonjour,

    je doit faire une interface qui fait établir une communication entre mon pc et MCS 32EX serad ce dernier est connecté à mon pc à travers un port serie rs232, pour le moment j'ai commencer a faire une interface graphique avec visual basic, j'ai réussi a établir l’ouverture du port ainsi que le téléchargement d'un fichier sur mon pc. mais pour l'envoyer j'arrive pas, sachant que avant de l’envoyer il faut attendre l'instruction appuyée sur F6 de MSC 32EX puis l'envoyer pour recevoir aussi c'est la même chose.

    code_delphi.txt

    voila le code que j'ai écris:

    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
    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
     
    Imports System.IO
    Imports System
    Imports System.Threading
    Imports System.IO.Ports
    Imports System.ComponentModel
     
    Public Class Form1
     
        'DECLARE a COMM PORT
        ' Dim WithEvents Myport As SerialPort = New  _
        ' System.IO.Ports.SerialPort("COM0", _
        ' 9600, _
        'Parity.None, _
        '8, _
        'StopBits.One)
     
     
        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 frmMain_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
            For i = 0 To UBound(myPort)
                PortBox.Items.Add(myPort(i))
            Next
     
            PortBox.Text = PortBox.Items.Item(0)    'Set cmbPort text to the first COM port detected
            DeconnecteButton.Enabled = False
            Me.KeyPreview = True
     
        End Sub
     
     
     
        'le button du port'
        Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PortBox.SelectedIndexChanged
     
            If SerialPort1.IsOpen = False Then
                SerialPort1.PortName = PortBox.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
     
        'button charger'
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles ChargeButton.Click
     
            ' OpenFileDialog1.Filter = "TextFile|*.prj"
            ' OpenFileDialog1.ShowDialog()
     
            'nouveau
     
            Dim dlg As OpenFileDialog = New OpenFileDialog() 'Charge un fichier sur le disque
            If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
     
            End If
     
            Dim sDatasTexte = System.IO.File.OpenText(dlg.FileName).ReadToEnd() 'Récup le contenu format texte
     
            ' Place le contenu dans un buffer d'octets (ASCII: 1 char = 1 octet) (UNICODE: 1 Char = 2 octets)
            Dim bBufferBytes() As Byte = System.Text.Encoding.ASCII.GetBytes(sDatasTexte)
     
            'TextBox.Text = sDatasTexte ' Affiche le bloc de texte
     
            ' Et affiche le bloc sour forme d'octets (Convertit les retour chariots pour l'affichage)
            For i = 0 To UBound(bBufferBytes)
                TextBox.Text = TextBox.Text & String.Format("{0:X2} ", bBufferBytes(i)) ' Ou Hex(bBufferBytes(i))
                If System.Text.Encoding.ASCII.GetString(bBufferBytes, i, 1)(0) = vbLf Then TextBox.Text = TextBox.Text & vbCrLf
            Next
     
            ' Ecrit le buffer complet sur le SerialPort
            SerialPort1.Write(bBufferBytes, 0, bBufferBytes.Length)
     
     
     
            Timer1.Start()
     
        End Sub
     
        'button connecter'
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles ConnecteButton.Click
     
     
            SerialPort1.PortName = PortBox.Text         'Set SerialPort1 to the selected COM port at startup
     
            'Other Serial Port Property
            SerialPort1.BaudRate = 9600
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8            'Open our serial port
            SerialPort1.Open()
            'ToolStripStatusLabel1.Text = "Connecter"
     
            ConnecteButton.Enabled = False          'Disable Connect button
            DeconnecteButton.Enabled = True        'and Enable Disconnect button
            RadioButton.BackColor = Color.Gray
            ChargeButton.Enabled = True
     
        End Sub
     
        'button envoyer'
     
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            If e.KeyCode = Keys.F6 Then
                MsgBox("œuvres")
     
            End If
        End Sub
     
        Private Sub Button3_Click(sender As Object, e As EventArgs) Handles EnvoyButton.Click
            ' SerialPort1.Write(ChargeButton.Text & vbCr) 'The text contained in the txtText will be sent to the serial port as ascii
            'plus the carriage return (Enter Key) the carriage return can be ommitted if the other end does not need it
     
            ToolStripStatusLabel1.Text = "Appuyez sur 'F6' de la commande numérique puis patientez..."
     
            If Me.KeyPreview = True Then
                SerialPort1.Write(ChargeButton.Text & vbCr)  ' envoyer le fichier
                'SerialPort1.Write(Chr(10))
     
            End If
     
        End Sub
     
     
        'button deconnecter'
        Private Sub Button4_Click(sender As Object, e As EventArgs) Handles DeconnecteButton.Click
     
            SerialPort1.Close()             'Close our Serial Port
     
            ConnecteButton.Enabled = True
            DeconnecteButton.Enabled = False
            RadioButton.BackColor = Color.Red
            ChargeButton.Enabled = False
     
        End Sub
     
     
     
        'button recevoir'
        Private Sub Button6_Click(sender As Object, e As EventArgs) Handles RecevButton.Click
     
            ToolStripStatusLabel1.Text = "Appuyez sur 'F6' de la commande numérique puis patientez..."
     
                If Me.KeyPreview = True Then
                SerialPort1.Read(ChargeButton.Text & vbCr)  ' recevoir le fichier
     
     
            Timer1.Start()
     
     
        End Sub
     
        'button sauvegarder'
        Private Sub Button7_Click(sender As Object, e As EventArgs) Handles SauvegardeButton.Click
     
        End Sub
     
     
     
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            ProgressBar1.Increment(1)
            If ProgressBar1.Value = 100 Then
                'Label2.Text = "Télechargement Réussi"
                ToolStripStatusLabel1.Text = "Télechargement Réussi"
            End If
            Label1.Text = ProgressBar1.Value & ("%")
        End Sub
     
     End Class

  2. #2
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 204
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 204
    Par défaut
    il doit y avoir un évènement datareceived sur le serialport
    je pense qu'il t'envoies une instruction quand il est pret à recevoir le fichier, qu'il faut envoyer à ce moment là donc

    sinon voir la doc de ton truc ...
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  3. #3
    Membre confirmé
    Femme Profil pro
    Étudiant
    Inscrit en
    Mars 2015
    Messages
    131
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 35
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2015
    Messages : 131
    Par défaut
    bonjour,
    j'ai rajoute l’événement data received mais ça fonctionne pas , je comprend pas.
    peut-on travailler avec des thread pour la transmission et réception des données (communication) avec port série.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Quel langage pour Windows CE et interfaces ports COMs ?
    Par Nicoteen dans le forum Mobiles
    Réponses: 10
    Dernier message: 24/08/2007, 12h53
  2. Réponses: 1
    Dernier message: 22/01/2007, 09h02
  3. Interfacer Port Parallèle
    Par mariogarcia dans le forum C
    Réponses: 12
    Dernier message: 22/05/2006, 12h17
  4. portée des variables globales dans un fichier js
    Par crakazoid dans le forum Général JavaScript
    Réponses: 19
    Dernier message: 14/04/2006, 16h49
  5. Port et protocole de transfert de fichier
    Par oligig dans le forum Protocoles
    Réponses: 3
    Dernier message: 08/12/2005, 12h33

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