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

C# Discussion :

Problème exception C#


Sujet :

C#

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut Problème exception C#
    Bonjour,
    Je suis actuellement en réalisation de projet dans le cadre de mon BTS ( IRIS )
    Explication du projet : Gestion de capteurs d'une chaîne de production à l'aide d'une carte µChameleon.

    voici mon problème ( ne pas faire attention au message de l'antivirus ):



    Code source :
    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
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
     
    //********CSerie.cs*******//
     
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO.Ports;
    using System.Windows.Forms;
     
     
    namespace TestChameleon
    {
        class CSerie
        {
            SerialPort Com;
            int Vitesse;
            public CSerie(SerialPort Port, int Vitesse)
            {
     
                Com = Port;
                this.Vitesse = Vitesse;
                Com.BaudRate = Vitesse;
                Com.StopBits = StopBits.One;
                Com.DataBits = 8;
                Com.Parity = Parity.None;
                Com.Handshake = Handshake.None;
                Com.ReadTimeout = 1000;
     
     
            }
     
            public CSerie()
            {
     
                SerialPort Com = new SerialPort();
                // TODO: Complete member initialization
            }
            //-------------Ouverture du port série-------------//
            public bool Ouvrir()
            {
                bool EtatConnexion; 
                if (Com.IsOpen == false)
                {
                    Com.Open();
                    EtatConnexion = true;
                }
                else
                {
                    MessageBox.Show("Port utilisé", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    EtatConnexion = false;
                }
               return EtatConnexion;
            }
     
            //-------------Envoi d'un octet-------------//
            public void Envoi_Octet(byte[] Octet)
            {
                Com.Write(Octet, 0, 1);
            }
     
            //-------------Envoi d'une trame-------------//
            public void Envoi_Trame(byte[] Octet,int Taille)
            {
                Com.Write(Octet, 0, Taille);
            }
     
            //-------------Envoi d'une chaine-------------//
            public void Envoi_Trame(string Chaine)
            {
                Com.WriteLine(Chaine);
            }
     
            //----------Recevoir d'une chaine-------------//
            public string Recevoir_Trame()
            {
                return Com.ReadLine();
            }
            //-------------Réception d'une trame-------------//
            public byte[] Recevoir_DonneeByte()
            {
                byte[] BY = null;
                int Count = Com.BytesToRead;
                if (Count > 0)
                {
                    BY = new byte[Count];
                    for (int i = 0; i < Count; i++)
                    {
                        BY[i] = (byte)Com.ReadByte();
                    }
                }
                return BY;
            }
     
            //-------------Vidage du Buffer-------------//
            public void Vider_Buffer()
            {
                  Com.ReadExisting();          
            }
     
            public bool Fermer()
            {
                bool EtatConnexion;
                if (Com.IsOpen == true)
                {
                    Com.Close();
                    EtatConnexion = false;
                }
                else
                {
                    //MessageBox.Show("Port utilisé", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    EtatConnexion = true;
                }
                return EtatConnexion;
            }
     
        }
    }
     
    //*************CChameleon.cs*******************//
     
    using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace TestChameleon
    {
        class CChameleon
        {
            CSerie ComUSB;
            Pin[] Bornier = new Pin[100];
     
            struct Pin{
                public int Config;
                public int Valeur;
            };
     
            public enum ConfigPin {  
               Entree = 0, 
               Sortie = 1           
            }  
     
            public CChameleon()
            {
                ComUSB = null;
            }
     
            public CChameleon(CSerie Ref)
            {
                ComUSB = Ref;
                this.InitialisationDefaut();
            }
     
            /*************************************************************/
            /********Permet de configurer une pin ou un ensemble *********/
            /************** de pins consécutives en entrée ***************/
            /*************************************************************/
            public void ConfigurerEntreeTOR(int NumeroPin, int NombrePin)
            {
                string Trame;
                int Indice = NumeroPin;
     
                while (Indice < (NumeroPin + NombrePin))
                {
                    Trame = "pin " + Indice + " in";
                    ComUSB.Envoi_Trame(Trame);
                    Trame = "pin " + Indice + " pullup on";
                    ComUSB.Envoi_Trame(Trame);
                    this.Bornier[Indice -1].Config = (int)ConfigPin.Entree;
                    Indice++;
                }
     
            }
            /*************************************************************/
            /********Permet de configurer une pin ou un ensemble *********/
            /************** de pins consécutives en sortie ***************/
            /*************************************************************/
     
            public void ConfigurerSortieTOR(int NumeroPin, int NombrePin)
            {
                string Trame;
                int Indice = NumeroPin;
     
                while (Indice < (NumeroPin + NombrePin))
                {
                    Trame = "pin " + Indice + " out";
                    ComUSB.Envoi_Trame(Trame);
                    this.Bornier[Indice - 1].Config = (int)ConfigPin.Sortie;
                    Trame = "pin " + Indice + " lo";
                    ComUSB.Envoi_Trame(Trame);
                    this.Bornier[Indice - 1].Valeur = 0;
                    Indice++;
                }
            }
     
            /*************************************************************/
            /********Mettre au niveau haut ou bas une sotie **************/
            /*************************************************************/
     
            public void EcrireSortieTOR(int NumeroPin,int Valeur,int NombrePin)
            {
                string Trame;
                int Indice = NumeroPin;
     
     
                while (Indice < (NumeroPin + NombrePin)){
     
                    if (this.Bornier[Indice - 1].Config == 1){
     
                        if (Valeur != this.Bornier[Indice - 1].Valeur){
     
                            if (Valeur == 1)
                            {
                                Trame = "pin " + Indice + " hi";
                                this.Bornier[Indice - 1].Valeur = 1;
                            }
                            else
                            {
                                Trame = "pin " + Indice + " lo";
                                this.Bornier[Indice - 1].Valeur = 0;
                            }
                            ComUSB.Envoi_Trame(Trame);
                        }
                        Indice++;
                    }
                }
            }
            /*************************************************************/
            /******************* Ecrire sur une sortie *******************/
            /*************************************************************/
     
            public void EcrireSortieTOR(int NumeroPin,int Valeur) {
     
                EcrireSortieTOR(NumeroPin, Valeur, 1);
            }
     
            /*************************************************************/
            /******** Envoyer un octet sur 8 sorties consécutives ********/
            /*************************************************************/
     
            public void EcrireOctet(byte Octet, int NumPinD0 ){
                int Indice = 0;
                byte Masque = 0x01;
                byte ValeurEnvoyee = Octet;
     
                while (Indice < 8)
                {
                    if ((this.Bornier[NumPinD0 + Indice - 1].Valeur) != (ValeurEnvoyee & Masque))
                    {
                        if ((ValeurEnvoyee & Masque) == 1)
                        {
                            this.EcrireSortieTOR((NumPinD0 + Indice), 1);
                        }
                        else
                        {
                            this.EcrireSortieTOR((NumPinD0 + Indice), 0);
                        }
                    }
                    Indice++;
                    ValeurEnvoyee = (byte)(ValeurEnvoyee >> 1);
                }
            }
     
            /*************************************************************/
            /******************** Allumer la led *************************/
            /*************************************************************/
     
            public void AllumerLED() {
     
                ComUSB.Envoi_Trame("led on");
            }
     
            /*************************************************************/
            /*********************** Eteindre la LED *********************/
            /*************************************************************/
     
            public void EteindreLED()
            {
                ComUSB.Envoi_Trame("led off");
            }
     
            /*************************************************************/
            /********************** Initialiser tout en entree *************/
            /*************************************************************/
     
            public void InitialisationDefaut()
            {
                ConfigurerEntreeTOR(1,18);
            }
     
            /*************************************************************/
            /***************** Allumer toute les led *********************/
            /*************************************************************/
     
            public void AllumerTouteLesLed()
            {
                EcrireSortieTOR(5, 1);
                EcrireSortieTOR(6, 1);
                EcrireSortieTOR(7, 1);
                EcrireSortieTOR(8, 1);
                EcrireSortieTOR(9, 1);
                EcrireSortieTOR(18, 1);
     
            }
     
            /*************************************************************/
            /***************** Eteindre toute les led ********************/
            /*************************************************************/
     
            public void EteindreTouteLesLed()
            {
                EcrireSortieTOR(5, 0);
                EcrireSortieTOR(6, 0);
                EcrireSortieTOR(7, 0);
                EcrireSortieTOR(8, 0);
                EcrireSortieTOR(9, 0);
                EcrireSortieTOR(18, 0);
     
     
     
            }
     
            /*************************************************************/
            /********************** allumer le buzzer ********************/
            /*************************************************************/
     
            public void AllumerBuzzer(int tempsEnSeconde)
            {
                EcrireSortieTOR(12, 1);
                tempsEnSeconde = tempsEnSeconde * 1000;
                System.Threading.Thread.Sleep(tempsEnSeconde);
                EcrireSortieTOR(12, 0);
     
            }
     
            /*************************************************************/
            /***************** Lire l'état d'une entre TOR ***************/
            /*************************************************************/
     
            public int LireEntreeTOR(int NumeroPin)
            {
                string Trame;
                string TrameReponse;
                int Etat = -1;
     
                CSerie ComUSB = new CSerie();
     
                if (this.Bornier[NumeroPin - 1].Config == 0) /* Si configurer en entree */
                {  
                    Trame = "pin " + NumeroPin + " state";
                    ComUSB.Envoi_Trame(Trame);
                    TrameReponse = ComUSB.Recevoir_Trame();
                    Etat = this.DecoderEtatEntreeTOR(TrameReponse);
                    this.Bornier[NumeroPin - 1].Valeur = Etat;
                }
                return Etat;
             }
     
            private int  DecoderEtatEntreeTOR (string Reponse){
                string[] SousChaine ;
                SousChaine = Reponse.Split(' ');    // Cherche le caractére espace est divise la chaine dans le tableau
                return Convert.ToInt16(SousChaine[2].ToString());
     
            }
         }
    }
     
     
    //*************Form1.cs*****************//
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO.Ports;
    using System.Threading;
    using TestChameleon;
     
    namespace TestChameleon
    {
        public partial class Form1 : Form
        {
     
            private CSerie Serie;
            private bool EtatConnexion;
            private CChameleon CarteChameleon;
     
            public Form1()
            {
                InitializeComponent();
                CSerie Serie = new CSerie();
                CChameleon CarteChameleon = new CChameleon();
                Thread th = new Thread(Lire);
                th.Start();
            }
     
           public void Lire()
           {
                int i = 1;
                int retour;
                int GestionCapteurs = 1;
                CChameleon CarteChameleon = new CChameleon();
     
     
                retour = CarteChameleon.LireEntreeTOR(i);
     
                if (retour == 1)
                {
                    switch (GestionCapteurs)
                    {
                        case 1:
                            i++;
                            this.label9.Text = "OK";
                            break;
                        case 2:
                            i++;
                            this.label10.Text = "OK";
                            break;
                        case 3:
                            i++;
                            this.label11.Text = "OK";
                            break;
                        case 4:
                            i++;
                            this.label12.Text = "OK";
                            break;
                        case 5:
                            i++;
                            this.label13.Text = "OK";
                            break;
                        case 6:
                            i++;
                            this.label14.Text = "OK";
                            break;
                        case 7:
                            i++;
                            this.label15.Text = "OK";
                            break;
                        case 8:
                            i++;
                            this.label16.Text = "OK";
                            break;
     
                    }
                }
            } 
     
            private void Form1_Load(object sender, EventArgs e)
            {
                EtatConnexion = false;
                Serie = null;
     
                string[] ports = SerialPort.GetPortNames();
     
                foreach (string port in ports)
                {
                    this.comboBox1.Items.Add(port);
                }
                this.comboBox1.SelectedIndex = 0;
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
     
     
     
                if(this.EtatConnexion == false)
                {
                    this.serialPort1.PortName = this.comboBox1.SelectedItem.ToString();
                    if (Serie == null)
                    {
                        Serie = new CSerie(serialPort1, 9600);
                        try
                        {
                            EtatConnexion = Serie.Ouvrir();
                            this.CarteChameleon = new CChameleon(Serie);
                            this.button1.Text = "Deconnecter";
                            toolStripStatusLabel1.Text = "Etat : Connecté";
     
     
     
                            /*************************************************************/
                            /*************Configuration des pin de la carte***************/
                            /*************************************************************/
                            /*************************************************************/
     
     
                            CarteChameleon.ConfigurerSortieTOR(18, 1); // led de reponse carte
                            CarteChameleon.ConfigurerEntreeTOR(3, 2); //inter alarm
                            CarteChameleon.ConfigurerSortieTOR(5, 5); // led alarm + led chauffage + led volet
                            CarteChameleon.ConfigurerEntreeTOR(10, 1); //inter capteur lumiere
                            CarteChameleon.ConfigurerSortieTOR(12, 1); // buzzer alarm
     
                            /*************************************************************/
                            /*************initialisation des pins de la carte*************/
                            /*************************************************************/
                            /*************************************************************/
     
                            CarteChameleon.EcrireSortieTOR(18, 0);
                            CarteChameleon.EcrireSortieTOR(5, 0);
                            CarteChameleon.EcrireSortieTOR(6, 0);
                            CarteChameleon.EcrireSortieTOR(7, 0);
                            CarteChameleon.EcrireSortieTOR(8, 0);
                            CarteChameleon.EcrireSortieTOR(9, 0);
                            CarteChameleon.EcrireSortieTOR(12, 0);
     
     
     
     
                        }
                        catch
                        {
                             toolStripStatusLabel1.Text = "Etat : Erreur de connection";
                             MessageBox.Show("Port utilisé", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                             Serie = null;
                        }
     
                    }
                }
                else
                {
                    if(EtatConnexion == true)
                    {
                        EtatConnexion = Serie.Fermer();
                        Serie = null;
                        this.button1.Text = "Connecter";
                        toolStripStatusLabel1.Text = "Etat : Déconnecté";
                    }
     
                }
     
            }
     
            private void button2_Click(object sender, EventArgs e)
            {
     
                CarteChameleon.AllumerLED();
     
            }
     
            private void button3_Click(object sender, EventArgs e)
            {
     
                CarteChameleon.EteindreLED();
            }
     
        //**********************************GESTION CAPTEURS**********************************//
     
     
     
     
     
     
        }
    }

  2. #2
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Par défaut
    Bonjour

    Visiblement Com est à null.

  3. #3
    Membre confirmé
    Inscrit en
    Août 2002
    Messages
    25
    Détails du profil
    Informations forums :
    Inscription : Août 2002
    Messages : 25
    Par défaut
    Bonjour,

    Tu ne semble pas instancier ta classe Com.
    Cela vient du fait que tu n'utilises pas le constructeur CSerie(SerialPort Port, int Vitesse).

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Bonjour Bluedeep,

    Oui Com est à null mais je ne vois pas comment il puisse l'être :/

  5. #5
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Quand je l'instancie il me fait une autre erreur toujours sur la même ligne mais avec le message
    Le port est fermé.

  6. #6
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Par défaut
    Citation Envoyé par Amiral62 Voir le message
    Bonjour Bluedeep,

    Oui Com est à null mais je ne vois pas comment il puisse l'être :/
    Met un breakpoint quelque part et exécute pas à pas (F11) pour voir si tu passes ou pas par le constructeur de Com.

  7. #7
    Membre chevronné
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Septembre 2011
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2011
    Messages : 610
    Par défaut
    Le constructeur CSerie(SerialPort Port, int Vitesse) est instancié lors de l'appui sur Button1.
    Met un point d'arrêt pour voir si celui-ci s’exécute bien

  8. #8
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Oui visiblement je ne passe pas dedans.

  9. #9
    Membre chevronné
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Septembre 2011
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2011
    Messages : 610
    Par défaut
    Enlève déjà le this à ta ligne 471.
    Tu peut conclure que c'est une de tes 2 conditions qui bloquent (malgrès que leurs valeurs correspondent à celle que tu charges dans ta form)

  10. #10
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Merci pour ta reponse bugg.
    J'essaye ça en rentrant et je te dis quoi

  11. #11
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Re,
    J'ai supprimé le this de la ligne 471 et essayé de bidouiller les deux conditions mais rien ne fait... avec un point d’arrêt il ne passe pas par là, après avoir lancer le Thred il lance le run ==>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Application.Run(new Form1());
    et bloque sur le fameux Com. =(

  12. #12
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Voilà le Message d'erreur et le code actualisé :

    Message d'erreur :



    Code :

    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
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
     
     
    //********************CSerie.cs******************//
     
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO.Ports;
    using System.Windows.Forms;
     
     
    namespace TestChameleon
    {
        class CSerie
        {
            SerialPort Com = new SerialPort() ;
            int Vitesse;
            public CSerie(SerialPort Port, int Vitesse)
            {
     
                Com = Port;
                this.Vitesse = Vitesse;
                Com.BaudRate = Vitesse;
                Com.StopBits = StopBits.One;
                Com.DataBits = 8;
                Com.Parity = Parity.None;
                Com.Handshake = Handshake.None;
                Com.ReadTimeout = 1000;
     
     
            }
     
            public CSerie()
            {
     
     
                // TODO: Complete member initialization
            }
            //-------------Ouverture du port série-------------//
            public bool Ouvrir()
            {
                bool EtatConnexion; 
                if (Com.IsOpen == false)
                {
                    Com.Open();
                    EtatConnexion = true;
                }
                else
                {
                    MessageBox.Show("Port utilisé", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    EtatConnexion = false;
                }
               return EtatConnexion;
            }
     
            //-------------Envoi d'un octet-------------//
            public void Envoi_Octet(byte[] Octet)
            {
                Com.Write(Octet, 0, 1);
            }
     
            //-------------Envoi d'une trame-------------//
            public void Envoi_Trame(byte[] Octet,int Taille)
            {
                Com.Write(Octet, 0, Taille);
            }
     
            //-------------Envoi d'une chaine-------------//
            public void Envoi_Trame(string Chaine)
            {
                Com.WriteLine(Chaine);
            }
     
            //----------Recevoir d'une chaine-------------//
            public string Recevoir_Trame()
            {
                return Com.ReadLine();
            }
            //-------------Réception d'une trame-------------//
            public byte[] Recevoir_DonneeByte()
            {
                byte[] BY = null;
                int Count = Com.BytesToRead;
                if (Count > 0)
                {
                    BY = new byte[Count];
                    for (int i = 0; i < Count; i++)
                    {
                        BY[i] = (byte)Com.ReadByte();
                    }
                }
                return BY;
            }
     
            //-------------Vidage du Buffer-------------//
            public void Vider_Buffer()
            {
                  Com.ReadExisting();          
            }
     
            public bool Fermer()
            {
                bool EtatConnexion;
                if (Com.IsOpen == true)
                {
                    Com.Close();
                    EtatConnexion = false;
                }
                else
                {
                    //MessageBox.Show("Port utilisé", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    EtatConnexion = true;
                }
                return EtatConnexion;
            }
     
        }
    }
     
    //**************CChameleon.cs*******************//
     
    using System;
    using System.Collections.Generic;
    using System.Text;
     
    namespace TestChameleon
    {
        class CChameleon
        {
            CSerie ComUSB;
            Pin[] Bornier = new Pin[100];
     
            struct Pin{
                public int Config;
                public int Valeur;
            };
     
            public enum ConfigPin {  
               Entree = 0, 
               Sortie = 1           
            }  
     
            public CChameleon()
            {
                ComUSB = null;
            }
     
            public CChameleon(CSerie Ref)
            {
                ComUSB = Ref;
                this.InitialisationDefaut();
            }
     
            /*************************************************************/
            /********Permet de configurer une pin ou un ensemble *********/
            /************** de pins consécutives en entrée ***************/
            /*************************************************************/
            public void ConfigurerEntreeTOR(int NumeroPin, int NombrePin)
            {
                string Trame;
                int Indice = NumeroPin;
     
                while (Indice < (NumeroPin + NombrePin))
                {
                    Trame = "pin " + Indice + " in";
                    ComUSB.Envoi_Trame(Trame);
                    Trame = "pin " + Indice + " pullup on";
                    ComUSB.Envoi_Trame(Trame);
                    this.Bornier[Indice -1].Config = (int)ConfigPin.Entree;
                    Indice++;
                }
     
            }
            /*************************************************************/
            /********Permet de configurer une pin ou un ensemble *********/
            /************** de pins consécutives en sortie ***************/
            /*************************************************************/
     
            public void ConfigurerSortieTOR(int NumeroPin, int NombrePin)
            {
                string Trame;
                int Indice = NumeroPin;
     
                while (Indice < (NumeroPin + NombrePin))
                {
                    Trame = "pin " + Indice + " out";
                    ComUSB.Envoi_Trame(Trame);
                    this.Bornier[Indice - 1].Config = (int)ConfigPin.Sortie;
                    Trame = "pin " + Indice + " lo";
                    ComUSB.Envoi_Trame(Trame);
                    this.Bornier[Indice - 1].Valeur = 0;
                    Indice++;
                }
            }
     
            /*************************************************************/
            /********Mettre au niveau haut ou bas une sotie **************/
            /*************************************************************/
     
            public void EcrireSortieTOR(int NumeroPin,int Valeur,int NombrePin)
            {
                string Trame;
                int Indice = NumeroPin;
     
     
                while (Indice < (NumeroPin + NombrePin)){
     
                    if (this.Bornier[Indice - 1].Config == 1){
     
                        if (Valeur != this.Bornier[Indice - 1].Valeur){
     
                            if (Valeur == 1)
                            {
                                Trame = "pin " + Indice + " hi";
                                this.Bornier[Indice - 1].Valeur = 1;
                            }
                            else
                            {
                                Trame = "pin " + Indice + " lo";
                                this.Bornier[Indice - 1].Valeur = 0;
                            }
                            ComUSB.Envoi_Trame(Trame);
                        }
                        Indice++;
                    }
                }
            }
            /*************************************************************/
            /******************* Ecrire sur une sortie *******************/
            /*************************************************************/
     
            public void EcrireSortieTOR(int NumeroPin,int Valeur) {
     
                EcrireSortieTOR(NumeroPin, Valeur, 1);
            }
     
            /*************************************************************/
            /******** Envoyer un octet sur 8 sorties consécutives ********/
            /*************************************************************/
     
            public void EcrireOctet(byte Octet, int NumPinD0 ){
                int Indice = 0;
                byte Masque = 0x01;
                byte ValeurEnvoyee = Octet;
     
                while (Indice < 8)
                {
                    if ((this.Bornier[NumPinD0 + Indice - 1].Valeur) != (ValeurEnvoyee & Masque))
                    {
                        if ((ValeurEnvoyee & Masque) == 1)
                        {
                            this.EcrireSortieTOR((NumPinD0 + Indice), 1);
                        }
                        else
                        {
                            this.EcrireSortieTOR((NumPinD0 + Indice), 0);
                        }
                    }
                    Indice++;
                    ValeurEnvoyee = (byte)(ValeurEnvoyee >> 1);
                }
            }
     
            /*************************************************************/
            /******************** Allumer la led *************************/
            /*************************************************************/
     
            public void AllumerLED() {
     
                ComUSB.Envoi_Trame("led on");
            }
     
            /*************************************************************/
            /*********************** Eteindre la LED *********************/
            /*************************************************************/
     
            public void EteindreLED()
            {
                ComUSB.Envoi_Trame("led off");
            }
     
            /*************************************************************/
            /********************** Initialiser tout en entree *************/
            /*************************************************************/
     
            public void InitialisationDefaut()
            {
                ConfigurerEntreeTOR(1,18);
            }
     
            /*************************************************************/
            /***************** Allumer toute les led *********************/
            /*************************************************************/
     
            public void AllumerTouteLesLed()
            {
                EcrireSortieTOR(5, 1);
                EcrireSortieTOR(6, 1);
                EcrireSortieTOR(7, 1);
                EcrireSortieTOR(8, 1);
                EcrireSortieTOR(9, 1);
                EcrireSortieTOR(18, 1);
     
            }
     
            /*************************************************************/
            /***************** Eteindre toute les led ********************/
            /*************************************************************/
     
            public void EteindreTouteLesLed()
            {
                EcrireSortieTOR(5, 0);
                EcrireSortieTOR(6, 0);
                EcrireSortieTOR(7, 0);
                EcrireSortieTOR(8, 0);
                EcrireSortieTOR(9, 0);
                EcrireSortieTOR(18, 0);
     
     
     
            }
     
            /*************************************************************/
            /********************** allumer le buzzer ********************/
            /*************************************************************/
     
            public void AllumerBuzzer(int tempsEnSeconde)
            {
                EcrireSortieTOR(12, 1);
                tempsEnSeconde = tempsEnSeconde * 1000;
                System.Threading.Thread.Sleep(tempsEnSeconde);
                EcrireSortieTOR(12, 0);
     
            }
     
            /*************************************************************/
            /***************** Lire l'état d'une entre TOR ***************/
            /*************************************************************/
     
            public int LireEntreeTOR(int NumeroPin)
            {
                string Trame;
                string TrameReponse;
                int Etat = -1;
     
                CSerie ComUSB = new CSerie();
     
                if (this.Bornier[NumeroPin - 1].Config == 0) /* Si configurer en entree */
                {  
                    Trame = "pin " + NumeroPin + " state";
                    ComUSB.Envoi_Trame(Trame);
                    TrameReponse = ComUSB.Recevoir_Trame();
                    Etat = this.DecoderEtatEntreeTOR(TrameReponse);
                    this.Bornier[NumeroPin - 1].Valeur = Etat;
                }
                return Etat;
             }
     
            private int  DecoderEtatEntreeTOR (string Reponse){
                string[] SousChaine ;
                SousChaine = Reponse.Split(' ');    // Cherche le caractére espace est divise la chaine dans le tableau
                return Convert.ToInt16(SousChaine[2].ToString());
     
            }
         }
    }
     
     
    //*******************Form1.cs************************//
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO.Ports;
    using System.Threading;
    using TestChameleon;
     
    namespace TestChameleon
    {
        public partial class Form1 : Form
        {
     
            private CSerie Serie;
            private bool EtatConnexion;
            private CChameleon CarteChameleon;
     
            public Form1()
            {
                InitializeComponent();
                CSerie Serie = new CSerie();
                CChameleon CarteChameleon = new CChameleon();
                Thread th = new Thread(Lire);
                th.Start();
            }
     
           public void Lire()
           {
                int i = 1;
                int retour;
                int GestionCapteurs = 1;
                CChameleon CarteChameleon = new CChameleon();
     
     
                retour = CarteChameleon.LireEntreeTOR(i);
     
                if (retour == 1)
                {
                    switch (GestionCapteurs)
                    {
                        case 1:
                            i++;
                            this.label9.Text = "OK";
                            break;
                        case 2:
                            i++;
                            this.label10.Text = "OK";
                            break;
                        case 3:
                            i++;
                            this.label11.Text = "OK";
                            break;
                        case 4:
                            i++;
                            this.label12.Text = "OK";
                            break;
                        case 5:
                            i++;
                            this.label13.Text = "OK";
                            break;
                        case 6:
                            i++;
                            this.label14.Text = "OK";
                            break;
                        case 7:
                            i++;
                            this.label15.Text = "OK";
                            break;
                        case 8:
                            i++;
                            this.label16.Text = "OK";
                            break;
     
                    }
                }
            } 
     
            private void Form1_Load(object sender, EventArgs e)
            {
                EtatConnexion = false;
                Serie = null;
     
                string[] ports = SerialPort.GetPortNames();
     
                foreach (string port in ports)
                {
                    this.comboBox1.Items.Add(port);
                }
                this.comboBox1.SelectedIndex = 0;
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
     
     
     
                if(EtatConnexion == false)
                {
                    this.serialPort1.PortName = this.comboBox1.SelectedItem.ToString();
                    if (Serie == null)
                    {
                        Serie = new CSerie(serialPort1, 9600);
                        try
                        {
                            EtatConnexion = Serie.Ouvrir();
                            this.CarteChameleon = new CChameleon(Serie);
                            this.button1.Text = "Deconnecter";
                            toolStripStatusLabel1.Text = "Etat : Connecté";
     
     
     
                            /*************************************************************/
                            /*************Configuration des pin de la carte***************/
                            /*************************************************************/
                            /*************************************************************/
     
     
                            CarteChameleon.ConfigurerSortieTOR(18, 1); // led de reponse carte
                            CarteChameleon.ConfigurerEntreeTOR(3, 2); //inter alarm
                            CarteChameleon.ConfigurerSortieTOR(5, 5); // led alarm + led chauffage + led volet
                            CarteChameleon.ConfigurerEntreeTOR(10, 1); //inter capteur lumiere
                            CarteChameleon.ConfigurerSortieTOR(12, 1); // buzzer alarm
     
                            /*************************************************************/
                            /*************initialisation des pins de la carte*************/
                            /*************************************************************/
                            /*************************************************************/
     
                            CarteChameleon.EcrireSortieTOR(18, 0);
                            CarteChameleon.EcrireSortieTOR(5, 0);
                            CarteChameleon.EcrireSortieTOR(6, 0);
                            CarteChameleon.EcrireSortieTOR(7, 0);
                            CarteChameleon.EcrireSortieTOR(8, 0);
                            CarteChameleon.EcrireSortieTOR(9, 0);
                            CarteChameleon.EcrireSortieTOR(12, 0);
     
     
     
     
                        }
                        catch
                        {
                             toolStripStatusLabel1.Text = "Etat : Erreur de connection";
                             MessageBox.Show("Port utilisé", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                             Serie = null;
                        }
     
                    }
                }
                else
                {
                    if(this.EtatConnexion == true)
                    {
                        EtatConnexion = Serie.Fermer();
                        Serie = null;
                        this.button1.Text = "Connecter";
                        toolStripStatusLabel1.Text = "Etat : Déconnecté";
                    }
     
                }
     
            }
     
            private void button2_Click(object sender, EventArgs e)
            {
     
                CarteChameleon.AllumerLED();
     
            }
     
            private void button3_Click(object sender, EventArgs e)
            {
     
                CarteChameleon.EteindreLED();
            }
     
        //**********************************GESTION CAPTEURS**********************************//
     
     
     
     
     
     
        }
    }

  13. #13
    Membre chevronné
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Septembre 2011
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2011
    Messages : 610
    Par défaut
    Si je comprend quand tu test tu appui sur le Button1 et CSerie ne s’instancie pas!

    Ce n'est pas normal! Met le BreakPoint sur le Button1 et dis nous ce qu'il en est!
    S'il rentre dans la première condition??
    S'il rentre dans la seconde??
    Sinon instancie le chargement et test...

  14. #14
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Quand je met le BreakPoint sur le Button1 il me met directement à l'erreur... :/

  15. #15
    Membre chevronné
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Septembre 2011
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2011
    Messages : 610
    Par défaut
    Et il y a autre chose, ta classe Cserie ne peut pas connaitre le serialPort ni la vitesse puisque tu ne lui déclare pas que c'est pour une méthode
    A ta ligne 476 essai plutôt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Serie.CSerie(serialPort1, 9600);
    Cela devrait mieux marcher

  16. #16
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Exactement ! Comme quoi on ne peut faire confiance aux profs :s lol
    Par contre il me dit qu'il y a une référence manquante :


  17. #17
    Membre chevronné
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Septembre 2011
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Septembre 2011
    Messages : 610
    Par défaut
    Change le Nom de ta méthode, il y a confusion!

  18. #18
    Membre éprouvé
    Homme Profil pro
    Responsable de service informatique
    Inscrit en
    Octobre 2010
    Messages
    62
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Responsable de service informatique
    Secteur : Transports

    Informations forums :
    Inscription : Octobre 2010
    Messages : 62
    Par défaut
    Bonjour,

    Avant de corriger trop de choses à droite et à gauche pas forcement utile, il faudrait peut être commencer par démarrer le thread qui fait tourner 'Lire' après avoir appuyé sur le bouton et initialisé le port au lieu de le lancer lorsque la form est créée.

  19. #19
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Par défaut
    Citation Envoyé par bugg7111 Voir le message
    Et il y a autre chose, ta classe Cserie ne peut pas connaitre le serialPort ni la vitesse puisque tu ne lui déclare pas que c'est pour une méthode
    A ta ligne 476 essai plutôt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Serie.CSerie(serialPort1, 9600);
    Cela devrait mieux marcher


    Appeler un constructeur comme une méthode d'instance,non, ça ne marche pas !

  20. #20
    Membre confirmé
    Homme Profil pro
    Développeur UNIFACE, C, C++, C#, Java
    Inscrit en
    Janvier 2012
    Messages
    71
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur UNIFACE, C, C++, C#, Java
    Secteur : Santé

    Informations forums :
    Inscription : Janvier 2012
    Messages : 71
    Par défaut
    Bonsoir,
    J'ai changer le nom de ma méthode, ça passe mais toujours la même erreur;
    Ensuite j'ai lancer le thread après avoir appuyer sur le bouton mais quand tu dis " initialisé le port au lieu de le lancer lorsque la form est créée" tu parle de :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
      string[] ports = SerialPort.GetPortNames();
    ?
    En tout cas merci pour vos réponses

+ Répondre à la discussion
Cette discussion est résolue.
Page 1 sur 2 12 DernièreDernière

Discussions similaires

  1. Comment résoudre ce probléme : Exception d'E/S: Connection refused ?
    Par adil_vpb dans le forum Connexions aux bases de données
    Réponses: 17
    Dernier message: 19/11/2007, 16h19
  2. [System.IO.Ports] Problème Exception
    Par goddet dans le forum C#
    Réponses: 6
    Dernier message: 11/09/2007, 10h23
  3. [C#] Problème exception mscorlib.dll
    Par moulefrite dans le forum Windows Forms
    Réponses: 2
    Dernier message: 31/07/2007, 15h21
  4. problème exception java.io.IOException
    Par boulette85 dans le forum Langage
    Réponses: 4
    Dernier message: 01/05/2007, 11h30
  5. Problème Exception EOFException
    Par jason69 dans le forum Entrée/Sortie
    Réponses: 1
    Dernier message: 04/09/2006, 14h47

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