How to extract info form modem.

How can I extract info from the modem. Like OK, CARRIER DETECT, CARRIER LOST ............. and put them in a Text box..
trollAsked:
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.

ESICommented:
This is handled by the driver, no ?
0
vorlonCommented:
troll,
Currently I only have access to Visual Basic 3 for reference. However, here's a routine program using the Communications control that might help you.

Create a new form. Place a command button on the form, along with a communications control and a label.

In the form_load event place this code:
Sub Form_Load()
   'use com1
   Comm1.CommPort = 1
   
   '9600 baud, no parity, 8 data, and 1 stop bit
   Comm1.Settings = "9600,N,8,1"

   'tell the control to read entire buffer when Input is used
   Comm1.InputLen = 0

   'Open the port
   Comm1.PortOpen = True
End Sub

In the form_unload event place this code:
Sub Form_Unload (Cancel as integer)
   'close the port
   'Comm1.PortOpen = false
End Sub

In the command1_click event place this code:
Sub Command1_Click()
   Dim inputStr as string, outputStr as string
   Dim Dummy as integer

   'output to send to comm port
   outputStr = "AT" + Chr$(13)

   'initialize the label
   Label1.caption = "Sending " & outputStr

   'send the output string to the port
   Comm1.Output = outputStr

   'loop until response is received
   Do
      dummy = DoEvents()
   Loop Until Comm1.InBufferCount > 0

   inputStr = Comm1.Input

   label1.caption = Right$(inputStr, Len(inputStr) - Len(outputStr))
End Sub


Run the application. Click on the command button and you'll see that the response (reprinted on label1) was "OK" if you're modem is in the correct port and turned on.

If you're using a version of Visual Basic higher than versin 3, then you'll have to play with it. I'm assuming those higher versions still come with communications controls.

Hope this helps.
0

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
trollAuthor Commented:
Ok. Thanks, but there is only one problem... When the modem reports back to the label. I can't do this :

Dim ISOK AS Boolean

If label1.caption = "OK" Then
      ISOK = True
End If

Why?. When I look at the label, it looks like the report "OK" dropps down one line. Is there a way I can use the reports that the modem gives to turn on a switch or something simular, because I need to know when the modem reports OK, so I can send the next command...

Best reguards, Kim Morgan Ellis
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

vorlonCommented:
troll,
In the function I gave you, you have the following line of code:
label1.caption = Right$(inputStr, Len(inputStr) - Len(outputStr))

All you have to do is place code in the label1.change event and test for the OK. Like this:

Sub Label1_Change ()
    If label1.Caption = "OK" Then
       ISOK = True
    else
       ISOK = False
    End If
End Sub

or with 1 line of code like this:

Sub Label1_Change ()
    ISOK = (label1.Caption = "OK")    
End Sub

Hope this helps.
0
vorlonCommented:
troll,
(I should have included this with my last comment)

Sometimes there are extra null characters or carriage return with the return string from the modem. To ignore these and check for the presence of OK in the messy string you can do this:

Sub Label1_Change()
   ISOK = (InStr(label1.caption,"OK"))  
End Sub

This simply searches the entire string for a presence of an OK.

Hope this helps.
0
trollAuthor Commented:
Hmmm.. I can't get it to work.

In label1.Change I put inn the Code you gave me..
it reportet 0, and not OK.

Sub label1_Change()
    text2.text = (label1.caption = "OK")
    text2.text =(InStr(label1.caption,"OK"))
End Sub

In the textbox it reportet "O"

?

Best reguards, Kim Morgan Ellis


0
vorlonCommented:
troll,
Can you paste the function of your code? The same function I gave you --- Sub Command1_Click(). I want to see exactly what is happening. It's possible you made a typo, or I made a typo, or something. The code I sent you works on my system...

vorlon
0
trollAuthor Commented:
Here is the timer that checks the status on the modem :

Private Sub tmratx0_Timer()
Dim InputStr As String, OutputStr As String
Dim Dummy As Integer

Do
Dummy = DoEvents()
Loop Until Com2.InBufferCount >= 2
    InputStr = Com2.Input
    Lblstatus.Caption = Right$(InputStr, Len(InputStr) - Len(OutputStr))
End Sub

Here is the Timer that Checks if the repsone is "OK"
Private Sub Timer1_Timer()
If Lblstatus.Caption = "OK" Then
    ISOK = True
 Else
    ISOK = False
 End If
End Sub

Here is my Sub to extract just OK from the string.

Private Sub Lblstatus_Change()

Lblstatus.Caption = (InStr(Label1.Caption, "OK"))

End Sub

When I use these codes, in the label, it looks like "OK" dropps down one line," AT" just blinks one line above (It seems when it blinks that its inn the right place)..

0
vorlonCommented:
troll,
Looked at your code and found some problems. Here they are:

1) you can merge the code from Timer1_timer with that of Lblstatus_Change.

2) The Lblstatus_Change code is wrong. The Instr does not return "OK". It returns the position of "OK" in the string. Therefore the line:

Lblstatus.Caption = (InStr(Label1.Caption, "OK"))

will place a number in the caption of the label, not OK.

BUT, like I had said earlier, you can merge these functions like this:

Private Sub Lblstatus_Change()
   ISOK = (InStr(Label1.Caption, "OK")>0)
End Sub

What we're doing here is comparing the result of the InStr (which is the position of the OK in the string), to see if it's higher than 0 meaning that OK is found in the string. If this is the case the entire call "InStr(Label1.captin,"OK")>0, because it's surrrounded by parenthesis "()", will return back true or false. This in turn will get assigned to ISOK. There's no need to use a timer because this code gets called automatically as soon as some data gets assigned to the caption routine which you are already doing in the other timer routine.

If you need additional information, let me know.
Hope this helps.
0
trollAuthor Commented:
Hmm.. when I put the code in lblstatus.caption_Change.

It allways report 0, is this correct, or is it supposed to report a higher value?.

One other thing. How can I get the program to wait, so when I dial my account number, the modem waits until the dialing is done, before starting to dial the code?. I've tryed to make a timer, but I don't seem to get it to work. I need something that makes the program wait 2-3 seconds...

Best reguards, Kim Morgan Ellis
0
vorlonCommented:
troll,
What environment are you using? Win95/Win 3.xx, VB4/VB3?

I tried this under Win 3.1 using VB3. I'll check it again using VB4 under Win95.

As far as dialing, you can let the modem dial yourself by using the DT command. Like this:

ATDT12013448952

Here:
AT means attention
DT means Dial Tone
Phone: 1-201-3448952.

Of course the string has to have a carriage return (CHR$(13)) at the end.

I'll let you know what I find under Win95.
vorlon
0
trollAuthor Commented:
I'm using Windows 95 and Visual Basic 4.0 Pro.


Best reguards, Kim Morgan Ellis
0
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.