Solved

How to extract info form modem.

Posted on 1997-07-24
12
277 Views
Last Modified: 2011-10-03
How can I extract info from the modem. Like OK, CARRIER DETECT, CARRIER LOST ............. and put them in a Text box..
0
Comment
Question by:troll
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
12 Comments
 
LVL 3

Expert Comment

by:ESI
ID: 1428788
This is handled by the driver, no ?
0
 
LVL 2

Accepted Solution

by:
vorlon earned 10 total points
ID: 1428789
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
 

Author Comment

by:troll
ID: 1428790
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:vorlon
ID: 1428791
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
 
LVL 2

Expert Comment

by:vorlon
ID: 1428792
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
 

Author Comment

by:troll
ID: 1428793
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
 
LVL 2

Expert Comment

by:vorlon
ID: 1428794
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
 

Author Comment

by:troll
ID: 1428795
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
 
LVL 2

Expert Comment

by:vorlon
ID: 1428796
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
 

Author Comment

by:troll
ID: 1428797
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
 
LVL 2

Expert Comment

by:vorlon
ID: 1428798
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
 

Author Comment

by:troll
ID: 1428799
I'm using Windows 95 and Visual Basic 4.0 Pro.


Best reguards, Kim Morgan Ellis
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 75
Error with a code discussed on this page 5 47
backup program with robocopy 6 87
VBA- How to change font, color and format in outlook e-mail sent from Access 2 157
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question