Solved

How to extract info form modem.

Posted on 1997-07-24
12
273 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
  • 6
  • 5
12 Comments
 
LVL 3

Expert Comment

by:ESI
Comment Utility
This is handled by the driver, no ?
0
 
LVL 2

Accepted Solution

by:
vorlon earned 10 total points
Comment Utility
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
Comment Utility
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
 
LVL 2

Expert Comment

by:vorlon
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:vorlon
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I'm using Windows 95 and Visual Basic 4.0 Pro.


Best reguards, Kim Morgan Ellis
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now