1,2,3,com4. ou il est ce :-((( modem ?

Contenu du snippet

Ce projet donne les indications indispensables
pour détecter le port ou est connecté le modem.
En prime il indique la validité des ports du PC.

Sur une feuille, créer:
2 controles timer: Ti et Ti2
4 controles MsComm: MsComm1 à 4
1 controle Textbox : tt
1 controle Command: Command1

Source / Exemple :


Dim ti_ok, ti2_ok, cport 

Private Sub Command1_Click()
1 Dim cport As Integer
2 Dim i As Integer
'
3 ti2_ok = False
4 ti_ok = False
6 Cls

7 On Error GoTo erreur1
8 MousePointer = 11
9 Command1.Enabled = False

19 ti_ok = False: Ti.Enabled = False: Ti.Interval = 100 ' en millisecondes
20 ti2_ok = False: Ti2.Enabled = False: Ti2.Interval = 500 ' en millisecondes
' attente des données venant de la RS232
21 MousePointer = 11

cport = 1: tt.ForeColor = vbBlack: tt.FontBold = True:  tt.Print "COM1 : ";: buffer$ = ""
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
If MSComm1.InBufferCount Then a$ = MSComm1.Input ' vider le tampon

198 MSComm1.Output = "ATi0i1i2I3I4i6i7i8i9i10i11" & Chr$(13)
199 DoEvents
200 Ti2.Enabled = False: ti2_ok = False: Ti2.Enabled = True
205     Do
210     Ti.Enabled = False: ti_ok = False: Ti.Enabled = True
215     DoEvents
220        Do
225        DoEvents
230        Loop Until MSComm1.InBufferCount > 1 Or ti_ok
235            If ti_ok = False Then
240            Ti.Enabled = False
245            buffer$ = buffer$ & MSComm1.Input
250            DoEvents
255            End If
260     Loop Until ti2_ok = True
tt.ForeColor = vbBlue: tt.FontBold = False: tt.Print buffer$

cport = 2: tt.ForeColor = vbBlack: tt.FontBold = True:  tt.Print "COM2 : ";: buffer$ = ""
MSComm2.CommPort = 2
MSComm2.Settings = "9600,N,8,1"
MSComm2.PortOpen = True
MSComm2.InputLen = 0
MSComm2.InputMode = comInputModeText
If MSComm2.InBufferCount Then a$ = MSComm2.Input ' vider le tampon

298 MSComm2.Output = "ATi0i1i2I3I4i6i7i8i9i10i11" & Chr$(13)
299 DoEvents
300 Ti2.Enabled = False: ti2_ok = False: Ti2.Enabled = True
305     Do
310     Ti.Enabled = False: ti_ok = False: Ti.Enabled = True
315     DoEvents
320        Do
325        DoEvents
330        Loop Until MSComm2.InBufferCount > 1 Or ti_ok
335            If ti_ok = False Then
340            Ti.Enabled = False
345            buffer$ = buffer$ & MSComm2.Input
350            DoEvents
355            End If
360     Loop Until ti2_ok = True
tt.ForeColor = vbBlue: tt.FontBold = False: tt.Print buffer$

cport = 3: tt.ForeColor = vbBlack: tt.FontBold = True:  tt.Print "COM3 : ";: buffer$ = ""
MSComm3.CommPort = 3
MSComm3.Settings = "9600,N,8,1"
MSComm3.PortOpen = True
MSComm3.InputLen = 0
MSComm3.InputMode = comInputModeText
If MSComm3.InBufferCount Then a$ = MSComm3.Input ' vider le tampon

398 MSComm3.Output = "ATi0i1i2I3I4i6i7i8i9i10i11" & Chr$(13)
399 DoEvents
400 Ti2.Enabled = False: ti2_ok = False: Ti2.Enabled = True
405     Do
410     Ti.Enabled = False: ti_ok = False: Ti.Enabled = True
415     DoEvents
420        Do
425        DoEvents
430        Loop Until MSComm3.InBufferCount > 1 Or ti_ok
435            If ti_ok = False Then
440            Ti.Enabled = False
445            buffer$ = buffer$ & MSComm3.Input
450            DoEvents
455            End If
460     Loop Until ti2_ok = True
tt.ForeColor = vbBlue: tt.FontBold = False: tt.Print buffer$

cport = 4: tt.ForeColor = vbBlack: tt.FontBold = True: tt.Print "COM4 : ";: buffer$ = ""
MSComm4.CommPort = 4
MSComm4.Settings = "9600,N,8,1"
MSComm4.PortOpen = True
MSComm4.InputLen = 0
MSComm4.InputMode = comInputModeText
If MSComm4.InBufferCount Then a$ = MSComm4.Input ' vider le tampon

498 MSComm4.Output = "ATi0i1i2I3I4i6i7i8i9i10i11" & Chr$(13)
499 DoEvents
500 Ti2.Enabled = False: ti2_ok = False: Ti2.Enabled = True
505     Do
510     Ti.Enabled = False: ti_ok = False: Ti.Enabled = True
515     DoEvents
520        Do
525        DoEvents
530        Loop Until MSComm4.InBufferCount > 1 Or ti_ok
535            If ti_ok = False Then
540            Ti.Enabled = False
545            buffer$ = buffer$ & MSComm4.Input
550            DoEvents
555            End If
560     Loop Until ti2_ok = True
tt.ForeColor = vbBlue: tt.FontBold = False: tt.Print buffer$

37 MousePointer = 0
38 Command1.Enabled = True
39
40 DoEvents
46 Exit Sub

100 erreur1:
101 tt.ForeColor = vbRed
102 tt.FontBold = False
103 If Err = 8002 Then
104    tt.Print buffer$ & "Rien sur le Port COM" & cport
105 End If
106 If Err = 8005 Then
107    'buffer$ = buffer$ &  "Port COM" & cport & " déjà ouvert." & vbCrLf
108 End If
109 If Err = 8012 Then
110    'buffer$ = buffer$ &  "Port COM" & cport & " pas ouvert." & vbCrLf
111 End If
112 'Print "Erreur N°"; Err; " ligne "; Erl
113
114 DoEvents
115 Resume Next
End Sub

Private Sub Form_Load()
Top = 0: Left = 0
On Error GoTo erreur

cport = 1
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True
MSComm1.InputLen = 0
MSComm1.InputMode = comInputModeText
If MSComm1.InBufferCount Then a$ = MSComm1.Input ' vider le tampon

cport = 2
MSComm2.CommPort = 2
MSComm2.Settings = "9600,N,8,1"
MSComm2.PortOpen = True
MSComm2.InputLen = 0
MSComm2.InputMode = comInputModeText
If MSComm2.InBufferCount Then a$ = MSComm2.Input ' vider le tampon

cport = 3
MSComm3.CommPort = 3
MSComm3.Settings = "9600,N,8,1"
MSComm3.PortOpen = True
MSComm3.InputLen = 0
MSComm3.InputMode = comInputModeText
If MSComm3.InBufferCount Then a$ = MSComm3.Input ' vider le tampon

cport = 4
MSComm4.CommPort = 4
MSComm4.Settings = "9600,N,8,1"
MSComm4.PortOpen = True
MSComm4.InputLen = 0
MSComm4.InputMode = comInputModeText
If MSComm4.InBufferCount Then a$ = MSComm4.Input ' vider le tampon

' resultats affichés, en code alphanumeriques
' pour le modem, c'est ma seule source !
' Envoie la commande Echo désactivé, Echo local désactivé.
cport = 2
MSComm2.Output = "ATQ1V1E0F1" & Chr$(13)
If MSComm2.InBufferCount Then a$ = MSComm2.Input
DoEvents

ti_ok = False: Ti.Enabled = False: Ti.Interval = 100 ' en millisecondes
ti2_ok = False: Ti2.Enabled = False: Ti2.Interval = 500 ' en millisecondes
Exit Sub

100 erreur:
115 Resume Next
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
End
End Sub

Private Sub Ti_Timer()
ti_ok = True
End Sub

Private Sub Ti2_Timer()
ti2_ok = True
End Sub

Conclusion :


Les codes envoyés au modem sous tension,
retournent ses paramètres.
Vitesse maxi, Nom, Fabriquant, Marque etc...

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.