Bonjour,

Je dois faire une application qui récupère et stocke dans un fichier csv des données GPS et des données récupérées par un combiné sepura(norme TETRA).
J'utilise donc 2 ports 1 pour le GPS et 1 pour le combiné TETRA.
J'arrive à récupérer et traiter les données GPS car le gps (un garmin) envoie les données toutes les secondes (si je ne m'abuse).
Par contre mon problème viens du coté du combiné car en effet pour récupérer les données dont j'ai besoin je dois d'abord envoyer une commande de type AT.
J'ai effectué plusieurs test dans un premier temps d'envoyer la commande uniquement quand je fais démarrer le programme en général au premier coup il ne détecte rien et quand je le relance j'ai bien la donnée qu'il me fallais.
Puis j'ai aussi testé avec l'évènement comEvSend le souci que j'ai est que quand je le lance le programme plante alors quand je le test pas à pas il fonctionne correctement.

Voici les parties du code qui nous intéresse, je met aussi la partie traitement coté GPS pour comparer ca peut aider.

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
Private Sub BoutonStart_Click()
 
Dim i As Integer
Dim Index As Integer
Dim crlf As String
 
 
BoutonStop.Enabled = True
BoutonStart.Enabled = False
 
Ouverture_Port_COM (1)
Ouverture_Port_COM (2)
 
 
'If Option1.Enabled = True Then
'    CommandeTETRA = "at+cci?" & vbCr
'    Comm(2).Output = CommandeTETRA & vbCr
'    Label26.Caption = CommandeTETRA
''    Call Envoi_Port_COM(CommandeTETRA, 2)
'
'ElseIf Option2.Enabled = True Then
'    CommandeTETRA = "at+cci?"
'    Comm(2).Output = CommandeTETRA & vbCr
'    Label26.Caption = CommandeTETRA
''    Call Envoi_Port_COM(CommandeTETRA, 2)
'End If
 
Call Comm_OnComm(Index)
'Call TraitementTETRA(TmpChaineTETRA, CommandeTETRA)
 
End Sub
 
Private Sub TraitementGPS(TmpChaineGPS)
 
Dim i As Integer
Dim j As Integer
Dim tmp As String
Dim degres As String
Dim minutes As String
 
i = InStr(TmpChaineGPS, "GPRMC")
 
On Error Resume Next
Comm(1).InputLen = 0
TmpChaineGPS = TmpChaineGPS & Comm(1).Input
Text1.Text = Text1.Text & TmpChaineGPS
 
 
    If Split(TmpChaineGPS, ",")(2) = "A" Then
        Latitude = Split(TmpChaineGPS, ",")(4) & " " & Split(Split(TmpChaineGPS, ",")(3), ".")(0) & "'" & Split(Split(TmpChaineGPS, ",")(3), ".")(1)
        tmp = Split(Split(TmpChaineGPS, ",")(3), ".")(0)
        Longitude = Split(TmpChaineGPS, ",")(6) & " " & Split(Split(TmpChaineGPS, ",")(5), ".")(0) & "'" & Split(Split(TmpChaineGPS, ",")(5), ".")(1)
        Heure = Mid(Split(TmpChaineGPS, ",")(1), i - 1, 2) & ":" & Mid(Split(TmpChaineGPS, ",")(1), i + 1, 2) & ":" & Mid(Split(TmpChaineGPS, ",")(1), i + 3, 2)
 
        Label24.ForeColor = VERT
        Label25.ForeColor = VERT
        Label21.ForeColor = VERT
        Label24.Caption = Latitude
        Label21.Caption = Longitude
        Label25.Caption = Heure
 '       NumPortTETRA = Port(0).Text
        Label29.Caption = NumPortTETRA
 
    ElseIf Split(TmpChaineGPS, ",")(2) = "V" Then
        Heure = Mid(Split(TmpChaineGPS, ",")(1), i - 1, 2) & ":" & Mid(Split(TmpChaineGPS, ",")(1), i + 1, 2) & ":" & Mid(Split(TmpChaineGPS, ",")(1), i + 3, 2)
        'Latitude = Split(TmpChaineGPS, ",")(4) & " " & Split(Split(TmpChaineGPS, ",")(3), ".")(0) & "'" & Split(Split(TmpChaineGPS, ",")(3), ".")(1)
        tmp = Split(Split(TmpChaineGPS, ",")(3), ".")(0)
        minutes = Right(tmp, 2)
        degres = Left(tmp, 2)
        Latitude = Math.Round(degres + minutes / 60, 6)
        'Longitude = Split(TmpChaineGPS, ",")(6) & " " & Split(Split(TmpChaineGPS, ",")(5), ".")(0) & "'" & Split(Split(TmpChaineGPS, ",")(5), ".")(1)
        tmp = Split(Split(TmpChaineGPS, ",")(5), ".")(0)
        minutes = Right(tmp, 2)
        degres = Left(tmp, 3)
        Longitude = Math.Round(degres + minutes / 60, 7)
 
        Label24.ForeColor = ROUGE
        Label21.ForeColor = ROUGE
        Label25.ForeColor = ROUGE
        Label25.Caption = Heure
        Label24.Caption = Latitude
        Label21.Caption = Longitude
  '      NumPortTETRA = Port(0).Text
        Label28.Caption = NumPortGPS
        Print #1, Heure & "; " & Longitude & "; " & Latitude
    End If
 
End Sub
Private Sub TraitementTETRA(TmpChaineTETRA, CommandeTETRA)
 
Dim j As Integer
Dim ChaineTETRA As String
 
j = InStr(TmpChaineTETRA, "CCI")
'ChaineTETRA = TmpChaineTETRA & Comm(2).Input
 
On Error Resume Next
Comm(2).InputLen = 0
TmpChaineTETRA = Comm(2).Input
Text2.Text = Text2.Text & TmpChaineTETRA
Label26.Caption = CommandeTETRA
 
MNI = Split(TmpChaineTETRA, ",")(0)
MNI = Right(MNI, 7)
Label32 = MNI
 
RSSI = Split(TmpChaineTETRA, ",")(1)
Label30 = RSSI
'If TmpChaineTETRA.Contains("CCI") Then
'    CCI = Split(TmpChaineTETRA, ",")
'    MNI = TmpChaineTETRA
'    Label42.Caption = MNI
'    RSSI = Split(TmpChaineTETRA, ",")(1)
'    Label31.Caption = RSSI
'    Serveur = Split(TmpChaineTETRA, ",")(2)
'    Label32.Caption = MNI
'    MNI = Split(TmpChaineTETRA, ",")(3)
'    Label33.Caption = MNI
'    LA = Split(TmpChaineTETRA, ",")(4)
'    Label34.Caption = LA
'    MNI = Split(TmpChaineTETRA, ",")(5)
'    Label35.Caption = MNI
'    C1 = Split(TmpChaineTETRA, ",")(6)
'    Label36.Caption = C1
'End If
 
End Sub
 
 
Private Sub BoutonStop_Click()
BoutonStop.Enabled = False
BoutonStart.Enabled = True
 
Call Fermeture_Port_COM(1)
Call Fermeture_Port_COM(2)
 
End Sub
 
Private Sub Comm_OnComm(Index As Integer)
 
Dim InBuff As String
 
Comm(2).OutBufferCount = 0
Comm(2).Output = CommandeTETRA & vbCr
 
Select Case Comm(1).CommEvent
Case comEvReceive
    TmpChaineGPS = Comm(1).Input
    Call TraitementGPS(TmpChaineGPS) 'traitement données
End Select
 
Select Case Comm(2).CommEvent
    Case comEvSend
         Comm(2).Output = CommandeTETRA
         CommandeTETRA = "at+cci?" & vbCr
 
    Case comEvReceive
        TmpChaineTETRA = Comm(2).Input
        Call TraitementTETRA(TmpChaineTETRA, CommandeTETRA)
End Select
End Sub
Je mets aussi la partie ouverture des ports au cas ou:
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
Public Function Ouverture_Port_COM(Index As Integer) As Boolean
 
Dim PretAOuvrir As Boolean
Dim NumPortTETRA As Integer
Dim NumPortGPS As Integer
Dim CommandeTETRA
 
Ouverture_Port_COM = False
PretAOuvrir = False
 
If Form1.Comm(Index).PortOpen = False Then
    Form1.Comm(1).Settings = "4800,N,8,1"
    Form1.Comm(2).Settings = "38400,N,8,1"
    Form1.Comm(Index).InputLen = 1
    PretAOuvrir = True
End If
 
If PretAOuvrir = True Then
    On Error Resume Next
    Form1.Comm(2).CommPort = NumPortTETRA
    Form1.Comm(1).CommPort = NumPortGPS
    Form1.Comm(Index).PortOpen = True
 
End If
 
CommandeTETRA = "ate0" & vbCr
Form1.Comm(2).Output = CommandeTETRA & vbCr
 
If Not Form1.Comm(Index).PortOpen Then
  Select Case Err.Number
    Case 8002
      MsgBox "Erreur " & Err.Number & " : Port COM " & Index & _
      " n'existe pas!", vbCritical, " Erreur Port COM " & Index
      Form1.StatusBar1.Panels(Index).Text = "COM " & Index & ": Fermé"
 
    Case 8005
      MsgBox "Erreur " & Err.Number & " : Port COM " & Index & _
      " déja ouvert!", vbCritical, " Erreur Port COM " & Index
      Form1.StatusBar1.Panels(Index).Text = "COM " & Index & ": Ouvert"
 
    Case Else
       MsgBox "Erreur " & Err.Number & " : Port COM " & Index & _
      " ", vbCritical, " Erreur Port COM " & Index
      Form1.StatusBar1.Panels(Index).Text = "COM " & Index & ": Fermé"
  End Select
 
Else
    If Index = 1 Then
        Form1.StatusBar1.Panels(1).Text = "COM " & "GPS" & ": Ouvert"
    ElseIf Index = 2 Then
        Form1.StatusBar1.Panels(2).Text = "COM " & "TETRA" & ": Ouvert"
    End If
End If
End Function
Voili voilou j'espère avoir été clair n'hésitez pas à me dire si ce n'est pas assez clair ou ca manque de précision.

Merci d'avance pour l'aide et à bientot

PS: certaines lignes de codes mises en commentaires sont des test que j'ai effectué et qui m'aide à me rappeler ce qui fonctionne et voir ce que j'ai déjà testé.