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

Arduino Discussion :

Communication arduino avec VB.net


Sujet :

Arduino

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Inscrit en
    Février 2013
    Messages
    6
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Février 2013
    Messages : 6
    Points : 8
    Points
    8
    Par défaut Communication arduino avec VB.net
    Bonjour

    je veux communiquer une carte Arduino avec VB.net
    dans mon programme j'ai plusieurs bouton poussoir, quand je clique sur l'un des BP j'envoie sur le port série une chaîne de caractères ver une interface VB

    coté arduino

    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
    //// déclaration de 5 boutons poussoirs
    const int APPUI=LOW;      // constante pour tester état BP
    const int BP10=2;
    const int BP1F=2;
    const int BP20=3;
    const int BP2F=3;
    const int BP30=4;
    const int BP3F=4;
    const int BP40=5;
    const int BP4F=5;
    const int BP50=6;
    const int BP5F=6;
    const int BP60=7;
    const int BP6F=7;
    const int BP70=8;
    const int BP7F=8;
    const int BP80=9;
    const int BP8F=9;
    const int BP90=10;
    const int BP9F=10;
    const int BP11=11;
    const int BP12=12;
    const int BP13=13;
     
    void setup() {
      Serial.begin(9600); // initialise la communication série
      // vérifier que le débit utiliser est le même dans le Terminal Série
     
      pinMode(BP10, INPUT);  // déclaration dee BPi comme entrée
      pinMode(BP1F,INPUT); 
      pinMode(BP20,INPUT);
      pinMode(BP2F,INPUT);
      pinMode(BP30,INPUT);
      pinMode(BP3F,INPUT);
      pinMode(BP40,INPUT);
      pinMode(BP4F,INPUT);
      pinMode(BP50,INPUT);
      pinMode(BP5F,INPUT);
      pinMode(BP60, INPUT);  
      pinMode(BP6F,INPUT);   
      pinMode(BP70, INPUT);
      pinMode(BP7F, INPUT);
      pinMode(BP80, INPUT);
      pinMode(BP8F, INPUT);
      pinMode(BP90, INPUT);
      pinMode(BP9F, INPUT);
      pinMode(BP11, INPUT);
      pinMode(BP12, INPUT);
      pinMode(BP13,INPUT);
     
     
     
      digitalWrite (BP10,HIGH);
      digitalWrite (BP1F,HIGH);
      digitalWrite (BP20,HIGH);
      digitalWrite (BP2F,HIGH);
      digitalWrite (BP30,HIGH);
      digitalWrite (BP3F,HIGH);
      digitalWrite (BP40,HIGH);
      digitalWrite (BP4F,HIGH);
      digitalWrite (BP50,HIGH);
      digitalWrite (BP5F,HIGH);
      digitalWrite (BP60,HIGH);
      digitalWrite (BP6F,HIGH);
      digitalWrite (BP70,HIGH);
      digitalWrite (BP7F,HIGH);
      digitalWrite (BP80,HIGH);
      digitalWrite (BP8F,HIGH);
      digitalWrite (BP90,HIGH);
      digitalWrite (BP9F,HIGH);
      digitalWrite (BP11,HIGH);
      digitalWrite (BP12,HIGH);
      digitalWrite (BP13,HIGH);
     
    }
     
    void loop() {
      if (digitalRead(BP10)==APPUI) {      // boutton pour déclencher l'arret du poste 1
      Serial.println(1); 
      }
     
       if (digitalRead(BP1F)==APPUI) {    // boutton pour déclencher la marche du poste 1
      Serial.println(2);
      }
     
      if (digitalRead(BP20)==APPUI) {     // boutton pour déclencher l'arret du poste 2
      Serial.println(3);
      }
       if (digitalRead(BP2F)==APPUI) {     // boutton pour déclencher la marche du poste 2
      Serial.println(4);
      }
      if (digitalRead(BP30)==APPUI) {     // boutton pour déclencher l'arret du 
      Serial.println(5);
      }
      if (digitalRead(BP3F)==APPUI) { 
       Serial.println(6);
      }
      if (digitalRead(BP40)==APPUI) { 
      Serial.println(7);
      }
     
       if (digitalRead(BP4F)==APPUI) { 
      Serial.println(8);
      }
       if  (digitalRead(BP50)==APPUI){ 
      Serial.println(9);
      }
      if  (digitalRead(BP5F)==APPUI){ 
      Serial.println(10);
      }
      if  (digitalRead(BP60)==APPUI){
      Serial.println(11);
      }
      if  (digitalRead(BP6F)==APPUI){ 
      Serial.println(12);
     
      }
       if  (digitalRead(BP70)==APPUI){ 
      Serial.println(13);
     
      }
       if  (digitalRead(BP7F)==APPUI){ 
      Serial.println(14);
     
      }
       if  (digitalRead(BP80)==APPUI){ 
      Serial.println(15);
     
      }
       if  (digitalRead(BP8F)==APPUI){ 
      Serial.println(16);
     
      }
       if  (digitalRead(BP90)==APPUI){ 
      Serial.println(17);
     
      }
       if  (digitalRead(BP9F)==APPUI){ 
      Serial.println(18);
     
      }
       if  (digitalRead(BP11)==APPUI){       // Nombre faisceau électrique
      Serial.println(19);
     
      }
     
       if  (digitalRead(BP12)==APPUI){      // Arret LAD
      Serial.println(20);
     
      }
     
       if  (digitalRead(BP13)==APPUI){       // marche LAD
      Serial.println(21);
     
      }
    coté

    mais coté VB.net.
    ex: si on reçoit l'un des valeur 10,20,30.... on va déclencher un compteur
    et si on reçoit 1F,2F,3F..... on va arrêter le comptage

    voici partie du code VB mais ça compile pas

    Code VB.net : 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
    Private Sub Form8_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            s.Close()
        End Sub
     
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
            s.Close()
            Try
                s.Open()
                value = CInt(s.ReadExisting)
                If value = 12 Then      ' start 
                    etat = 1
                ElseIf value =  Then  ' pause 
                    etat = 0
                ElseIf value = 14 Then  ' reset 
                    etat = 2
                End If
                s.Close()
            Catch ex As Exception
                Timer1.Stop()
                MsgBox("Erreur!..." & Chr(13) & ex.Message, CType(48, MsgBoxStyle), "Erreur")
                s.Close()
            End Try
     
     
            If etat = 1 Then
                answer = answer.Add(duration)
            ElseIf etat = 2 Then
                answer = New System.TimeSpan(0, 0, 0, 0)
            End If
            TextBox1.Text = answer.ToString + " S"
        End Sub
     
     
     Private Sub S_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
     
            Timer1.Enabled = True
            Timer2.Enabled = True
            Timer3.Enabled = True
            Timer4.Enabled = True
            Timer5.Enabled = True
            Timer6.Enabled = True
            Timer7.Enabled = True
            Timer8.Enabled = True
            Timer9.Enabled = True
            Timer10.Enabled = True
            Timer11.Enabled = True
            Timer12.Enabled = True
            Timer13.Enabled = True
            Timer14.Enabled = True
            Timer15.Enabled = True
     
        End Sub
     
     
     
     Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
            duration = New System.TimeSpan(0, 0, 0, 1)
            answer = New System.TimeSpan(0, 0, 0, 0)
            s.PortName = "COM1"
            s.BaudRate = 9600
            s.DataBits = 8
            s.Parity = Parity.None
            s.StopBits = StopBits.One
            s.Handshake = Handshake.None
            s.Encoding = System.Text.Encoding.Default
            Timer1.Start()
     
     
        End Sub

  2. #2
    Membre confirmé
    Avatar de deletme
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Indre et Loire (Centre)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2011
    Messages : 257
    Points : 519
    Points
    519
    Par défaut
    Bonjour,

    Peut-être pourrais tu commencer par donner l'erreur de compilation ?

    Cdlt, deletMe
    "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
    - Martin Golding
    Traduction obligatoire : "Toujours écrire du code en gardant en tête que le mec qui en assurera la maintenance est un psychopathe violent qui connait votre adresse"

Discussions similaires

  1. communication avec pointeuse avec VB.net
    Par expert.tun dans le forum VB.NET
    Réponses: 8
    Dernier message: 23/06/2010, 14h51
  2. communication Bluetooth simple avec VB.net
    Par Naklov dans le forum VB.NET
    Réponses: 2
    Dernier message: 04/01/2010, 20h54
  3. communication série via rs232 avec vb.net
    Par lemabs dans le forum Windows Forms
    Réponses: 1
    Dernier message: 16/11/2009, 16h35
  4. Comparaison de méthodes de communications AJAX avec ASP.NET
    Par Louis-Guillaume Morand dans le forum ASP.NET
    Réponses: 5
    Dernier message: 13/05/2009, 14h12

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