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 :

Programme VB en général


Sujet :

VB.NET

  1. #1
    Membre confirmé
    Homme Profil pro
    Responsable de projet fonctionnel
    Inscrit en
    Mars 2005
    Messages
    82
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Responsable de projet fonctionnel

    Informations forums :
    Inscription : Mars 2005
    Messages : 82
    Par défaut Programme VB en général
    Bonjour à tous

    N'ayant rien trouvé ou mal cherché je vous poste mon problème.
    J'ai mon soft en vb.net ou j'ai
    mes private Sub (appuis bouton, affichage texte ect)
    mes évènement
    dont un évènement : SerailPort.DataReceived
    tout fonctionne correctement (même la réception des messages)
    Ce que je voudrais faire c'est losque je n'ai pas rien à faire (pas d'appui de touche ou d'évènement ) je voudrais analyser ma trame reçue (pour ne pas avoir à le faire dans mon SerailPort.DataReceived)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    classe
    Private sub action 1
    end
    Private sub action 2
    end
    Mon événement SerailPort.DataReceived
    end
    'c'est ici que je voudrais faire mon analyse
    si caractererecu = "A"
    ect
     
    fin de clase
    merci de votre aide

  2. #2
    Membre émérite Avatar de methylene
    Profil pro
    Inscrit en
    Février 2010
    Messages
    659
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2010
    Messages : 659
    Par défaut
    Je ne comprend pas vraiment ce dont tu as besoin :O

  3. #3
    Membre très actif Avatar de oussi
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    192
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 192
    Par défaut
    Il faut utiliser un timer et l'événement Tick du timer. comme suit

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Private Sub timer1_Tick(blablabla...)
     
    'ton code d'analyse de la trame reçu
     
    End Sub
    Ensuite tu dois configurer ton timer pour qu'il s'execute à un Interval donné, on utilisant la propriété Interval je crois et tu lui donne une valeur en millisecondes.

    Et tous ce qu'il reste à faire c'est d'ajouter l'instruction timer1.Start() pour déclencher le timer.

    Et n'oublie pas d'ajouter l'instruction Application.DoEvents() au début de l'évènement Tick du timer pour que tu puisse faire d'autres choses dans ton appli en parallèle avec la verification.

    @++

  4. #4
    Membre confirmé
    Homme Profil pro
    Responsable de projet fonctionnel
    Inscrit en
    Mars 2005
    Messages
    82
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Responsable de projet fonctionnel

    Informations forums :
    Inscription : Mars 2005
    Messages : 82
    Par défaut
    Mon 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
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    Imports System.Drawing
    Imports System.Drawing.Drawing2D
    Imports System.Drawing.Imaging
    Imports System.Drawing.Brush
     
    Public Class Form1
        Dim ValeurReelT1 As Int16
        Dim ValeurReelT2 As Int16
        Dim ValeurReelT3 As Int16
        Dim ValeurReelT4 As Int16
     
        Dim re As Integer
        Dim img As New Bitmap(410, 410)
        Dim Trace As Graphics = Graphics.FromImage(img)
        Dim CadreRec As New Pen(Color.White)
        Dim pinceauX1 As New Pen(Color.Orange)
        Dim pinceauX2 As New Pen(Color.Green)
        Dim pinceauX3 As New Pen(Color.Yellow)
        Dim pinceauX4 As New Pen(Color.Pink)
        Dim pinceauX5 As New Pen(Color.Black)
        Dim pinceauX6 As New Pen(Color.Gray)
        Dim pinceauX7 As New Pen(New SolidBrush(Color.Cyan))
        Dim pinceauX8 As New Pen(New SolidBrush(Color.Red))
        Dim TraitFleche As New Pen(Color.Black)
     
        Dim fontFamily As New FontFamily("Times New Roman")
        Dim fonts As New Font(fontFamily, 12, FontStyle.Regular, GraphicsUnit.Pixel)
        Dim pointF As New PointF(30, 10)
        Dim solidBrush As New SolidBrush(Color.Black)
        Dim ValeurDureeMaxnuit As Integer
        Dim ValeurDureeMinnuit As Integer
        Dim LimiteMilieunuit As Integer
        Dim PointD1_1_X As Integer
        Dim PointD1_1_Y As Integer
        Dim PointD1_2_X As Integer
        Dim PointD1_2_Y As Integer
        Dim PointD2_1_X As Integer
        Dim PointD2_1_Y As Integer
        Dim PointD2_2_X As Integer
        Dim PointD2_2_Y As Integer
        Dim PointD3_1_X As Integer
        Dim PointD3_1_Y As Integer
        Dim PointD3_2_X As Integer
        Dim PointD3_2_Y As Integer
        Dim PointD4_1_X As Integer
        Dim PointD4_1_Y As Integer
        Dim PointD4_2_X As Integer
        Dim PointD4_2_Y As Integer
     
        Dim trameReception As String
        Dim trameReceptionVal As Char
        Dim trameReceptionVal1 As Integer
        Dim Place1 As Integer
        Dim Place2 As String
        Dim Place3 As Integer
        Dim ChaineDebutReceptionTrameConfiguration As String = Chr(170) + Chr(7) + Chr(24)
        Dim TableauCarRecu(100) As String
        Dim CptCaractereRecu As Integer = 0
        Dim longueurTrame As Integer
        Dim CsRecu As Integer
     
        Function RechercheDansChaine(ByVal Chaine As String, ByVal ChaineRecherche1 As String, ByVal ChaineRecherche2 As String)
            Dim Chaine1 As String
            Dim Chaine2 As String
            Dim val1 As Integer
            Dim Val2 As Integer
            val1 = Strings.InStr(Chaine, ChaineRecherche1)
            Chaine1 = Strings.Mid(Chaine, (val1 + Len(ChaineRecherche1)))
            Val2 = Strings.InStr(Chaine1, ChaineRecherche2)
            Chaine2 = Strings.Left(Chaine1, Val2 - Len(ChaineRecherche2))
            Return (CStr(Convert.ToInt16(Chaine2)))
     
        End Function
     
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            CadreRec.Width = 5
            pinceauX1.Width = 2
            pinceauX2.Width = 2
            pinceauX3.Width = 2
            pinceauX4.Width = 2
            pinceauX5.Width = 2
            pinceauX6.Width = 1
            pinceauX7.DashStyle = DashStyle.Dash
            pinceauX8.DashStyle = DashStyle.Dash
            TraitFleche.Width = 1
            TraitFleche.StartCap = LineCap.ArrowAnchor
            TraitFleche.EndCap = LineCap.ArrowAnchor
            'TraitFleche.EndCap = LineCap.RoundAnchor
            ValeurX1.Text = "X1=" & CStr(CursorX1.Value) & "%"
            ValeurReelT1 = CursorT1.Value * 15
            ValeurT1.Text = "T1= - " & CStr(Int(ValeurReelT1 / 60)) & " h : " & CStr(ValeurReelT1 - (Int(ValeurReelT1 / 60) * 60)) & " mm"
     
            ValeurX2.Text = "X2=" & CStr(CursorX2.Value) & "%"
            ValeurReelT2 = CursorT2.Value * 15
            ValeurT2.Text = "T2= - " & CStr(Int(ValeurReelT2 / 60)) & " h : " & CStr(ValeurReelT2 - (Int(ValeurReelT2 / 60) * 60)) & " mm"
     
            ValeurX3.Text = "X3=" & CStr(CursorX3.Value) & "%"
            ValeurReelT3 = CursorT3.Value * 15
            ValeurT3.Text = "T3= " & CStr(Int(ValeurReelT3 / 60)) & " h : " & CStr(ValeurReelT3 - (Int(ValeurReelT3 / 60) * 60)) & " mm"
     
            ValeurX4.Text = "X4=" & CStr(CursorX4.Value) & "%"
            ValeurReelT4 = CursorT4.Value * 15
            ValeurT4.Text = "T4= " & CStr(Int(ValeurReelT4 / 60)) & " h : " & CStr(ValeurReelT4 - (Int(ValeurReelT4 / 60) * 60)) & " mm"
            AfficheCourbe()
     
            BP_envConfig.Visible = False
            Label15.Visible = False
            Label16.Visible = False
            Resultat_Dimming.Visible = False
            Resultat_Tolerance.Visible = False
            ' For Each sp As String In My.Computer.Ports.SerialPortNames
            'ComboBox1.Items.Add(sp)
            '  Next
        End Sub
     
        Private Sub BPSortie_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BPSortie.Click
            SerialPort1.Close()
            Close()
        End Sub
     
        Private Sub BP_Ouvrir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BP_Ouvrir.Click
            Dim text As String
            Dim Chaine1 As String
     
            ' Ouverture du fichier
            OpenFileDialog1.ShowDialog()
            text = System.IO.File.ReadAllText(OpenFileDialog1.FileName)
     
            'Recherche de la valeur de X1
            Chaine1 = RechercheDansChaine(text, "X1=", ";")
            CursorX1.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de T1
            Chaine1 = RechercheDansChaine(text, "T1=", ";")
            CursorT1.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de X2
            Chaine1 = RechercheDansChaine(text, "X2=", ";")
            CursorX2.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de T2
            Chaine1 = RechercheDansChaine(text, "T2=", ";")
            CursorT2.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de X3
            Chaine1 = RechercheDansChaine(text, "X3=", ";")
            CursorX3.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de T3
            Chaine1 = RechercheDansChaine(text, "T3=", ";")
            CursorT3.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de X4
            Chaine1 = RechercheDansChaine(text, "X4=", ";")
            CursorX4.Value = Convert.ToInt16(Chaine1)
            'Recherche de la valeur de T4
            Chaine1 = RechercheDansChaine(text, "T4=", ";")
            CursorT4.Value = Convert.ToInt16(Chaine1)
     
            'Recherche de la valeur de la durée maximum d'une nuit
            Tb_DureeMaxNuit.Text = RechercheDansChaine(text, "MaxNuit=", ";")
     
            'Recherche de la valeur de la durée min d'une nuit
            Tb_DureeMinNuit.Text = RechercheDansChaine(text, "MinNuit=", ";")
     
            'Recherche de la valeur de la limite Milieu Nuit
            Tb_LimiteMilieuNuit.Text = RechercheDansChaine(text, "LimiteMilieuNuit=", ";")
     
            Tb_NomFichier.Text = OpenFileDialog1.FileName
            AfficheCourbe()
        End Sub
     
        Private Sub BP_Enregistrer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BP_Enregistrer.Click
            Dim ChaineSauvegarde As String
            Dim NomFichier As String
     
            ChaineSauvegarde = "X1=" & Convert.ToString(CursorX1.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "T1=" & Convert.ToString(CursorT1.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "X2=" & Convert.ToString(CursorX2.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "T2=" & Convert.ToString(CursorT2.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "X3=" & Convert.ToString(CursorX3.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "T3=" & Convert.ToString(CursorT3.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "X4=" & Convert.ToString(CursorX4.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "T4=" & Convert.ToString(CursorT4.Value) & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "MaxNuit=" & Tb_DureeMaxNuit.Text & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "MinNuit=" & Tb_DureeMinNuit.Text & ";" & Chr(13) & Chr(10)
            ChaineSauvegarde = ChaineSauvegarde & "LimiteMilieuNuit=" & Tb_LimiteMilieuNuit.Text & ";" & Chr(13) & Chr(10)
     
            SaveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            NomFichier = (SaveFileDialog1.ShowDialog())
            NomFichier = SaveFileDialog1.FileName
            System.IO.File.WriteAllText(NomFichier, ChaineSauvegarde)
            Tb_NomFichier.Text = NomFichier
        End Sub
     
        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
     
     
            SerialPort1.PortName = ComboBox1.Text
            SerialPort1.BaudRate = 9600
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.DataBits = 8
            SerialPort1.Encoding = System.Text.Encoding.Default
            SerialPort1.Open()
            BP_envConfig.Enabled = True
            BP_LectureConfiguration.Enabled = True
     
        End Sub
     
        Private Sub BP_envConfig_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BP_envConfig.Click
     
            Dim TabTrameValeureAberrante As Byte() = New Byte(8) {0, 0, 0, 0, 0, 0, 0, 0, 0}
            Dim TrameValeureAberrante As String
            Dim cheksum As Integer = 0
            Dim CptBoucle As Integer
            Dim TabTrameDimmiming As Byte() = New Byte(12) {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
            Dim cheksumDimmiming As Integer = 0
            Dim TrameDimming As String
     
            ' Constitution de la Trame des valeurs abérrantes
            TabTrameValeureAberrante(0) = 170
            TabTrameValeureAberrante(1) = 85
            TabTrameValeureAberrante(2) = 5
            TabTrameValeureAberrante(3) = ValeurDureeMinnuit - ((ValeurDureeMinnuit >> 8) * 256)
            TabTrameValeureAberrante(4) = ValeurDureeMinnuit >> 8
            TabTrameValeureAberrante(5) = ValeurDureeMaxnuit - ((ValeurDureeMaxnuit >> 8) * 256)
            TabTrameValeureAberrante(6) = ValeurDureeMaxnuit >> 8
            TabTrameValeureAberrante(7) = LimiteMilieunuit / 15
     
            'Calcul Cheksum valeurs abérrantes
            For CptBoucle = 0 To 8
                cheksum = cheksum + TabTrameValeureAberrante(CptBoucle)
            Next
            cheksum = 297
            cheksum = ((Not cheksum) + 1) 'D7 215dec
     
            TrameValeureAberrante = Chr(TabTrameValeureAberrante(0)) & Chr(TabTrameValeureAberrante(1)) & Chr(TabTrameValeureAberrante(2)) & Chr(TabTrameValeureAberrante(3)) & Chr(TabTrameValeureAberrante(4)) & Chr(TabTrameValeureAberrante(5)) & Chr(TabTrameValeureAberrante(6)) & Chr(TabTrameValeureAberrante(7)) & Chr(Val("&h" & Mid(cheksum.ToString("X"), 7)))
     
            ' Constitution de la Trame programmation dimming
            TabTrameDimmiming(0) = 170
            TabTrameDimmiming(1) = 10
            TabTrameDimmiming(2) = 9
            TabTrameDimmiming(3) = 0
            TabTrameDimmiming(4) = System.Math.Abs(CursorT1.Value)
            TabTrameDimmiming(5) = System.Math.Abs(CursorT2.Value)
            TabTrameDimmiming(6) = System.Math.Abs(CursorT3.Value)
            TabTrameDimmiming(7) = System.Math.Abs(CursorT4.Value)
            TabTrameDimmiming(8) = CursorX1.Value
            TabTrameDimmiming(9) = CursorX2.Value
            TabTrameDimmiming(10) = CursorX3.Value
            TabTrameDimmiming(11) = CursorX4.Value
     
            'Calcul Cheksum valeurs abérrantes
            For CptBoucle = 0 To 12
                cheksumDimmiming = cheksumDimmiming + TabTrameDimmiming(CptBoucle)
            Next
            cheksumDimmiming = ((Not cheksumDimmiming) + 1)
     
            TrameDimming = Chr(TabTrameDimmiming(0)) & Chr(TabTrameDimmiming(1)) & Chr(TabTrameDimmiming(2)) & Chr(TabTrameDimmiming(3)) & Chr(TabTrameDimmiming(4)) & Chr(TabTrameDimmiming(5)) & Chr(TabTrameDimmiming(6)) & Chr(TabTrameDimmiming(7)) & Chr(TabTrameDimmiming(8)) & Chr(TabTrameDimmiming(9)) & Chr(TabTrameDimmiming(10)) & Chr(TabTrameDimmiming(11)) & Chr(Val("&h" & Mid(cheksumDimmiming.ToString("X"), 7)))
     
            'Envoi des 2 trames
            ' SerialPort1.Open()
            SerialPort1.Write(TrameValeureAberrante)
            SerialPort1.Write(TrameDimming)
            'SerialPort1.Close()
        End Sub
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim ChekSum As String
            Dim TabMaj As Byte() = New Byte(7) {0, 0, 0, 0, 0, 0, 0, 0}
            Dim TabMajEnv As String() = New String(7) {"0", "0", "0", "0", "0", "0", "0", "0"}
     
            Dim somme As Integer = 0
            Dim TrameMaj As String
            Dim Cpt As Integer = 0
     
            TabMaj(0) = 170 '0xAA
            TabMaj(1) = 85 'Type de trame 0X55
            TabMaj(2) = 5 'Nombre d'octet à envoyer 0x05
            TabMaj(3) = 1 'LSB val min
            TabMaj(4) = 1 'MSB val min
            TabMaj(5) = 2 'LSB val max
            TabMaj(6) = 3 'MSB val max
            TabMaj(7) = 4 'Tolérence milieu de nuit
     
     
            While (Cpt < TabMajEnv.Length)
                TabMajEnv(Cpt) = Hex(TabMaj(Cpt))
                If Len(TabMajEnv(Cpt)) = 1 Then
                    TabMajEnv(Cpt) = "0" & TabMajEnv(Cpt)
                End If
                Cpt = Cpt + 1
            End While
     
            ' Calcul du Cheksum de la trame Dimming
            For Each b As Byte In TabMaj
                somme += b
            Next
            Dim sommeNot As Integer = (Not somme) + 1
            ChekSum = Hex(sommeNot)
            ChekSum = Strings.Right(ChekSum, 2)
     
            ' Construstion de la trame d'envoi
            TrameMaj = TabMajEnv(0) & TabMajEnv(1) & TabMajEnv(2) & TabMajEnv(3) & TabMajEnv(4) & TabMajEnv(5) & TabMajEnv(6) & TabMajEnv(7) & ChekSum
            SerialPort1.Open()
            SerialPort1.Write(TrameMaj)
            SerialPort1.Close()
        End Sub
     
        Private Sub BP_LectureConfiguration_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BP_LectureConfiguration.Click
            Dim TrameLectureConfiguration As String = Chr(170) & Chr(112) & Chr(1) & Chr(165) & Chr(64)
     
            SerialPort1.ReadTimeout = 1000
            CptCaractereRecu = 1
            SerialPort1.ReadExisting() 'vidage buffer réception
            SerialPort1.Write(TrameLectureConfiguration)
            Timer1.Start()
            'If SerialPort1 Then
            ' NbCarrecu = SerialPort1.BytesToRead
            'trameReception = SerialPort1.ReadExisting
     
     
     
        End Sub
     
        Private Sub AfficheCourbe()
     
            Trace.Clear(Color.DimGray)
            CalculPoints()
            ValeurReelT4 = CursorT4.Value * 15
            ValeurT4.Text = "T4= " & CStr(Int(ValeurReelT4 / 60)) & " h : " & CStr(ValeurReelT4 - (Int(ValeurReelT4 / 60) * 60)) & " mm"
            ValeurReelT3 = CursorT3.Value * 15
            ValeurT3.Text = "T3= " & CStr(Int(ValeurReelT3 / 60)) & " h : " & CStr(ValeurReelT3 - (Int(ValeurReelT3 / 60) * 60)) & " mm"
            ValeurReelT2 = CursorT2.Value * -15
            ValeurT2.Text = "T2= - " & CStr(Int(ValeurReelT2 / 60)) & " h : " & CStr(ValeurReelT2 - (Int(ValeurReelT2 / 60) * 60)) & " mm"
            ValeurReelT1 = CursorT1.Value * -15
            ValeurT1.Text = "T1= - " & CStr(Int(ValeurReelT1 / 60)) & " h : " & CStr(ValeurReelT1 - (Int(ValeurReelT1 / 60) * 60)) & " mm"
            ValeurX1.Text = "X1= " & CStr(CursorX1.Value) & " %"
            ValeurX2.Text = "X2= " & CStr(CursorX2.Value) & " %"
            ValeurX3.Text = "X3= " & CStr(CursorX3.Value) & " %"
            ValeurX4.Text = "X4= " & CStr(CursorX4.Value) & " %"
     
            Trace.DrawLine(pinceauX8, 205, 5, 205, 405)
            Trace.DrawLine(pinceauX7, 189, 5, 189, 405)
            Trace.DrawLine(pinceauX7, 173, 5, 173, 405)
            Trace.DrawLine(pinceauX7, 157, 5, 157, 405)
            Trace.DrawLine(pinceauX7, 141, 5, 141, 405)
            Trace.DrawLine(pinceauX7, 125, 5, 125, 405)
            Trace.DrawLine(pinceauX7, 109, 5, 109, 405)
            Trace.DrawLine(pinceauX7, 93, 5, 93, 405)
            Trace.DrawLine(pinceauX7, 77, 5, 77, 405)
            Trace.DrawLine(pinceauX7, 61, 5, 61, 405)
            Trace.DrawLine(pinceauX7, 45, 5, 45, 405)
            Trace.DrawLine(pinceauX7, 29, 5, 29, 405)
            Trace.DrawLine(pinceauX7, 13, 5, 13, 405)
     
            Trace.DrawLine(pinceauX7, 221, 5, 221, 405)
            Trace.DrawLine(pinceauX7, 237, 5, 237, 405)
            Trace.DrawLine(pinceauX7, 253, 5, 253, 405)
            Trace.DrawLine(pinceauX7, 269, 5, 269, 405)
            Trace.DrawLine(pinceauX7, 285, 5, 285, 405)
            Trace.DrawLine(pinceauX7, 301, 5, 301, 405)
            Trace.DrawLine(pinceauX7, 317, 5, 317, 405)
            Trace.DrawLine(pinceauX7, 333, 5, 333, 405)
            Trace.DrawLine(pinceauX7, 349, 5, 349, 405)
            Trace.DrawLine(pinceauX7, 365, 5, 365, 405)
            Trace.DrawLine(pinceauX7, 381, 5, 381, 405)
            Trace.DrawLine(pinceauX7, 397, 5, 397, 405)
     
            Trace.DrawLine(pinceauX8, 12, 205, 398, 205)
            Trace.DrawLine(pinceauX7, 12, 165, 398, 165)
            Trace.DrawLine(pinceauX7, 12, 125, 398, 125)
            Trace.DrawLine(pinceauX7, 12, 85, 398, 85)
            Trace.DrawLine(pinceauX7, 12, 45, 398, 45)
            Trace.DrawLine(pinceauX7, 12, 5, 398, 5)
     
            Trace.DrawLine(pinceauX7, 12, 245, 398, 245)
            Trace.DrawLine(pinceauX7, 12, 285, 398, 285)
            Trace.DrawLine(pinceauX7, 12, 325, 398, 325)
            Trace.DrawLine(pinceauX7, 12, 365, 398, 365)
            Trace.DrawLine(pinceauX7, 12, 405, 398, 405)
     
            Trace.DrawLine(pinceauX1, PointD1_1_X, PointD1_1_Y, PointD1_2_X, PointD1_2_Y)
            Trace.DrawLine(pinceauX2, PointD2_1_X, PointD2_1_Y, PointD2_2_X, PointD2_2_Y)
            Trace.DrawLine(pinceauX3, PointD3_1_X, PointD3_1_Y, PointD3_2_X, PointD3_2_Y)
            Trace.DrawLine(pinceauX4, PointD4_1_X, PointD4_1_Y, PointD4_2_X, PointD4_2_Y)
     
            Trace.DrawLine(pinceauX2, PointD1_2_X, PointD1_2_Y, PointD2_1_X, PointD2_1_Y)
            Trace.DrawLine(pinceauX1, PointD1_1_X, 5, PointD1_1_X, PointD1_1_Y)
            Trace.DrawLine(pinceauX5, PointD2_2_X, PointD2_2_Y, PointD3_1_X, PointD3_1_Y)
            Trace.DrawLine(pinceauX3, PointD3_2_X, PointD3_2_Y, PointD4_1_X, PointD4_1_Y)
            Trace.DrawLine(pinceauX4, PointD4_2_X, PointD4_2_Y, PointD4_2_X, 5)
            If CursorX1.Value < 97 Then
                Trace.DrawLine(TraitFleche, PointD1_1_X, PointD1_1_Y - 15, 205, PointD1_1_Y - 15)
                Trace.DrawString("T1", fonts, solidBrush, 210, PointD1_1_Y - 20)
            Else
                Trace.DrawLine(TraitFleche, PointD1_1_X, PointD1_1_Y + 15, 205, PointD1_1_Y + 15)
                Trace.DrawString("T1", fonts, solidBrush, 210, PointD1_1_Y + 7)
            End If
     
            If CursorX2.Value < 97 Then
                Trace.DrawLine(TraitFleche, PointD2_1_X, PointD2_1_Y - 15, 205, PointD2_1_Y - 15)
                Trace.DrawString("T2", fonts, solidBrush, 210, PointD2_1_Y - 20)
            Else
                Trace.DrawLine(TraitFleche, PointD2_1_X, PointD2_1_Y + 15, 205, PointD2_1_Y + 15)
                Trace.DrawString("T2", fonts, solidBrush, 210, PointD2_1_Y + 7)
            End If
     
            If CursorX3.Value < 97 Then
                Trace.DrawLine(TraitFleche, 205, PointD3_1_Y - 15, PointD3_2_X, PointD3_2_Y - 15)
                Trace.DrawString("T3", fonts, solidBrush, PointD3_2_X + 10, PointD3_1_Y - 20)
            Else
                Trace.DrawLine(TraitFleche, 205, PointD3_1_Y + 15, PointD3_2_X, PointD3_2_Y + 15)
                Trace.DrawString("T3", fonts, solidBrush, PointD3_2_X + 10, PointD3_1_Y + 7)
            End If
     
            If CursorX4.Value < 97 Then
                Trace.DrawLine(TraitFleche, 205, PointD4_1_Y - 15, PointD4_2_X, PointD4_2_Y - 15)
                Trace.DrawString("T4", fonts, solidBrush, PointD4_2_X - 20, PointD4_1_Y - 30)
            Else
                Trace.DrawLine(TraitFleche, 205, PointD4_1_Y + 15, PointD4_2_X, PointD4_2_Y + 15)
                Trace.DrawString("T4", fonts, solidBrush, PointD4_2_X - 20, PointD4_1_Y + 15)
     
            End If
     
     
            PictureBox1.Image = img
        End Sub
     
        Private Sub CalculPoints()
            'doite T1
            'PointD1_1_X = 205 + ((CursorT2.Value * 4) + (CursorT1.Value * 4))
            PointD1_1_X = 205 + (CursorT1.Value * 4)
            PointD1_1_Y = 405 - CursorX1.Value * 4
            PointD1_2_X = 205 + (CursorT2.Value * 4)
            PointD1_2_Y = 405 - CursorX1.Value * 4
            'doite T2
            PointD2_1_X = 205 + (CursorT2.Value * 4)
            PointD2_1_Y = 405 - CursorX2.Value * 4
            PointD2_2_X = 205 'Après ce sera P3
            PointD2_2_Y = 405 - CursorX2.Value * 4
            'droite T3
            PointD3_1_X = 205
            PointD3_1_Y = 405 - CursorX3.Value * 4
            PointD3_2_X = 205 + (CursorT3.Value * 4)
            PointD3_2_Y = 405 - CursorX3.Value * 4
            'droite T3
            PointD4_1_X = 205 + (CursorT3.Value * 4)
            PointD4_1_Y = 405 - CursorX4.Value * 4
            'PointD4_2_X = 205 + ((CursorT3.Value * 4) + (CursorT4.Value * 4))
            PointD4_2_X = 205 + (CursorT4.Value * 4)
     
            PointD4_2_Y = 405 - CursorX4.Value * 4
        End Sub
     
        Private Sub CursorT4_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorT4.Scroll
            If (CursorT4.Value <= CursorT3.Value) Then
                If (CursorT3.Value = 0) Then
                    CursorT3.Value = CursorT4.Value
                Else
                    CursorT3.Value = CursorT4.Value - 1
                End If
            End If
            AfficheCourbe()
        End Sub
     
        Private Sub CursorT3_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorT3.Scroll
            If (CursorT3.Value >= CursorT4.Value) Then
                If (CursorT4.Value = 48) Then
                    CursorT4.Value = CursorT3.Value
                Else
                    CursorT4.Value = CursorT3.Value + 1
                End If
            End If
            ValeurReelT3 = CursorT3.Value * 15
            ValeurT3.Text = "T3= " & CStr(Int(ValeurReelT3 / 60)) & " h : " & CStr(ValeurReelT3 - (Int(ValeurReelT3 / 60) * 60)) & " mm"
            AfficheCourbe()
     
        End Sub
     
        Private Sub CursorT1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorT1.Scroll
            If (CursorT1.Value >= CursorT2.Value) Then
                If (CursorT2.Value = 0) Then
                    CursorT2.Value = CursorT1.Value
                Else
                    CursorT2.Value = CursorT1.Value + 1
                End If
            End If
            AfficheCourbe()
        End Sub
     
        Private Sub CursorT2_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorT2.Scroll
            If (CursorT2.Value <= CursorT1.Value) Then
                If (CursorT1.Value = -48) Then
                    CursorT1.Value = CursorT2.Value
                Else
                    CursorT1.Value = CursorT2.Value - 1
                End If
            End If
            AfficheCourbe()
        End Sub
     
        Private Sub CursorX1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorX1.Scroll
            ' ValeurX1.Text = "X1= " & CStr(CursorX1.Value) & " %"
            AfficheCourbe()
        End Sub
     
        Private Sub CursorX2_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorX2.Scroll
            'ValeurX2.Text = "X2= " & CStr(CursorX2.Value) & " %"
            AfficheCourbe()
        End Sub
     
        Private Sub CursorX3_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorX3.Scroll
            'ValeurX3.Text = "X3= " & CStr(CursorX3.Value) & " %"
            AfficheCourbe()
        End Sub
     
        Private Sub CursorX4_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles CursorX4.Scroll
            'ValeurX4.Text = "X4= " & CStr(CursorX4.Value) & " %"
            AfficheCourbe()
        End Sub
     
        Private Sub Tb_DureeMaxNuit_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Tb_DureeMaxNuit.KeyPress, Tb_DureeMinNuit.KeyPress
            If Not Char.IsControl(e.KeyChar) And Not Char.IsDigit(e.KeyChar) Then
                e.Handled = True
                MessageBox.Show("Erreur vous devez saisir une valeur numérique")
            End If
        End Sub
     
        Private Sub Tb_DureeMaxNuit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tb_DureeMaxNuit.TextChanged
            If (Convert.ToInt16(Tb_DureeMaxNuit.Text) < 0) Or (Convert.ToInt16(Tb_DureeMaxNuit.Text) > 1440) Then
                MessageBox.Show("Erreur vous devez saisir une valeur comprise entre 0 et 1440 ")
            Else
                ValeurDureeMaxnuit = Convert.ToInt16(Tb_DureeMaxNuit.Text)
            End If
        End Sub
     
        Private Sub Tb_DureeMinNuit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tb_DureeMinNuit.TextChanged
            If (Convert.ToInt16(Tb_DureeMinNuit.Text) < 0) Or (Convert.ToInt16(Tb_DureeMinNuit.Text) > 1440) Then
                MessageBox.Show("Erreur vous devez saisir une valeur comprise entre 0 et 1440 ")
            Else
                ValeurDureeMinnuit = Convert.ToInt16(Tb_DureeMinNuit.Text)
            End If
        End Sub
     
        Private Sub Tb_LimiteMilieuNuit_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tb_LimiteMilieuNuit.TextChanged
            If (Convert.ToInt16(Tb_LimiteMilieuNuit.Text) < 0) Or (Convert.ToInt16(Tb_LimiteMilieuNuit.Text) > 360) Then
                MessageBox.Show("Erreur vous devez saisir une valeur comprise entre 0 et 360 ")
            Else
                LimiteMilieunuit = Convert.ToInt16(Tb_LimiteMilieuNuit.Text)
            End If
        End Sub
     
        Private Sub ComboBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
     
            ComboBox1.Items.Clear()
            For Each sp As String In My.Computer.Ports.SerialPortNames
                ComboBox1.Items.Add(sp)
            Next
            BP_envConfig.Visible = True
            BP_LectureConfiguration.Visible = True
            Label15.Visible = True
            Label16.Visible = True
            Resultat_Dimming.Visible = True
            Resultat_Tolerance.Visible = True
        End Sub
     
        Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
     
            trameReception = SerialPort1.ReadExisting
            For Me.CptCaractereRecu = CptCaractereRecu To trameReception.Length
                TableauCarRecu(CptCaractereRecu - 1) = Mid(trameReception, CptCaractereRecu, 1)
            Next CptCaractereRecu
                End Sub
     
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Timer1.Stop()
        End Sub
     
     
    End Class
    Juste avant End Class je voudrais ajouter du code qui tournerai que lorsque qu'il n'a rien d'autre à faire du genre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if TableauCarRecu(0) = Chr(170) then
     
    end if

  5. #5
    Membre très actif Avatar de oussi
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    192
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 192
    Par défaut
    Salut,
    C'est le code qui doit tourner en arrière plan que tu dois mettre dans l'événement Tick du timer.

    Timer1.Stop() va stopper le timer donc déactiver l'événement Tick du timer.

    Pas très clair?

    @++

  6. #6
    Membre confirmé
    Homme Profil pro
    Responsable de projet fonctionnel
    Inscrit en
    Mars 2005
    Messages
    82
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Responsable de projet fonctionnel

    Informations forums :
    Inscription : Mars 2005
    Messages : 82
    Par défaut
    Salut

    Ok je vais faire l'essai et je t'informe du résultat.

    merci

  7. #7
    Membre confirmé
    Homme Profil pro
    Responsable de projet fonctionnel
    Inscrit en
    Mars 2005
    Messages
    82
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Maine et Loire (Pays de la Loire)

    Informations professionnelles :
    Activité : Responsable de projet fonctionnel

    Informations forums :
    Inscription : Mars 2005
    Messages : 82
    Par défaut
    Salut oussi
    Le timer tick fonctionne merci

    par contre suite à cela j'ai ouvert une nouvelle discution
    Timer et DataReceived ne font pas bon ménage

    regarde si tu peux

  8. #8
    Membre très actif Avatar de oussi
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    192
    Détails du profil
    Informations personnelles :
    Âge : 35
    Localisation : Maroc

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 192
    Par défaut
    Salut,
    Merci de me donner le lien vers la discussion ainsi que les raisons pourquoi il ne font pas "bon ménage"

    @++

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

Discussions similaires

  1. Besoin d'information sur les métiers de programmation en général
    Par Amnael dans le forum Forum général Solutions d'entreprise
    Réponses: 1
    Dernier message: 30/09/2013, 20h07
  2. [Kylix] Probleme d'execution de programmes...
    Par yopziggy dans le forum EDI
    Réponses: 19
    Dernier message: 03/05/2002, 15h50
  3. [Kylix] icone associée à un programme
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 10h43

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