Как програмно инициализировать(протестировать) модем. - VB
Формулировка задачи:
Подскажите пожалуйста, как програмно можно проверить подключен модем и если подключен, то протестировать его.
Решение задачи: «Как програмно инициализировать(протестировать) модем.»
textual
Листинг программы
Private Sub CheckModem()
On Error GoTo ErrHandler
Dim timeout As Single, portnum As Integer, buff As String
modempresent = 0
For portnum = 1 To 16
MSComm1.CommPort = portnum
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
MSComm1.PortOpen = 1
MSComm1.Output = "AT" & Chr(13)
timeout = Timer
buff = ""
Do
DoEvents
buff = buff & MSComm1.Input
If InStr(LCase(buff), "ok") Then Exit For
Loop Until InStr(LCase(buff), "ok") Or (Timer - timeout > 1)
MSComm1.PortOpen = 0
Next portnum
If MSComm1.PortOpen = 1 Then
MsgBox "Modem found on COM" & portnum
MSComm1.PortOpen = 0
Else
MsgBox "You have not modem :("
End If
Exit Sub
ErrHandler:
If Err.Number = comPortInvalid Then
MsgBox "You have no modem :("
Else
MsgBox "Some error occured while working with modem. Possibly it's busy..."
End If
End Sub