How to check modem availability

Hi,

there is a Modem raid in our company and from time to time a modem becomes unavailable. I am supposed to write a WatchDog, which will run on a background as a service (no problem with that) and will do connect to all serial ports and checks modems there.

Any idea? I suppose I will use some ocx or dll which handles serial ports and send ATI commands. If no answer, then modem hanged up and send email.

Just want to ask whether there are some ready made snippets for this among EE users? Any thing I should be aware of?

Have a good weekend!

PN
Pedro KesonIT specialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

codeconquerorCommented:
You can try this.

Add the Microsoft Comm Control 6.0 component to your project, add a form and then insert the following code into the form:

<CODE SNIPPET>
Option Explicit
Option Compare Text

Dim mbGotData As Boolean
Dim mbGotOKMsg As Boolean

Private Sub Form_Load()
Dim iCommPorts As Integer
For iCommPorts = 1 To 20 '**** Cycle through ports 1 through 20, change this to suite your needs or change them to variables storing the current range
    If Not CheckModemOnPort(iCommPorts) Then
        MsgBox "The modem on comm port " & iCommPorts & " is not responding.", vbOKOnly + vbExclamation, " Modem Not Responding"
    End If
Next
End Sub

Private Function CheckModemOnPort(ByVal iCommPort As Integer) As Boolean
Dim dtStartTime As Date
mbGotOKMsg = False
mbGotData = False
With MSComm1
    '**** Set the comm port communication settings
    .CommPort = iCommPort
    .InBufferCount = 0
    .RThreshold = 1
    .SThreshold = 1
    .Settings = "9600,n,8,1" '**** 9600 baud, no parity, 8 data, 1 stop
    .PortOpen = True
    If .PortOpen Then
        .Output = "AT" '**** See if we can get an OK returned from the modem
        dtStartTime = Now
        Do While Not mbGotData
            DoEvents
            If Abs(DateDiff("s", Now, dtStartTime)) >= 10 Then '**** Wait up to 10 seconds for the OK message
                Exit Do
            End If
        Loop
    End If
End With
CheckModemOnPort = mbGotOKMsg
End Function

Private Sub MSComm1_OnComm()
Dim sData As String
sData = MSComm1.Input '**** Get the data from the receive buffer
mbGotData = True '**** Set the flag so we know that something was received
'**** Now check if it's what we wanted
mbGotOKMsg = (InStr(1, sData, "OK", vbTextCompare) > 0) '**** If we got an OK then this will return True, otherwise False
End Sub
</CODE SNIPPET>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pedro KesonIT specialistAuthor Commented:
Thanks!

Excelent! No coments needed. Just a perfect answer.
Thanks
codeconquerorCommented:
Glad to hear it.  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.