Solved

using AT commands with VB

Posted on 2007-12-03
38
679 Views
Last Modified: 2013-12-21
there is a list of api i found here
http://search.cpan.org/~johanvdb/GSM-SMS-0.162/lib/GSM/SMS/NBS.pm
http://www.symbian.com/developer/techlib/v70sdocs/doc_source/reference/cpp/Gsmu/index.html

and there is a AT commands here
http://www.developershome.com/sms/readSmsByAtCommands.asp


suppose i want to work with VB how can i use this AT commands in a wat that it will be sent to the mobile phone that will be connected to the computer
?
0
Comment
Question by:sasha85
  • 21
  • 17
38 Comments
 

Author Comment

by:sasha85
Comment Utility
for example this is the at command to read unread sms
AT+CMGL="REC UNREAD"
how i can write it inside the vb code, in a way that it will send this command to the mobile phone?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
How do you connect to the phone? If the connection is set up to be a Com port, you use the MSComm control to transmit AT commands.
0
 

Author Comment

by:sasha85
Comment Utility
i connect nokia gsm with usb cable and in the settings i can see it as a modem on com 4
when i used the hyperterminal i choose this com 4...
0
 

Author Comment

by:sasha85
Comment Utility
how to open socket or port?
how to send the at commends to this port?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I am trying to adapt the code in this Microsoft article for you. At the moment it simply reads the data from the line (No sending)

http://support.microsoft.com/?kbid=158008
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Hmm. It seems I no longer have a COM port available on my PC to test the code. I will try to set one up, but meanwhile here is a pointer to another question with some more relevant code that I wrote a while ago.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_20859694.html
0
 

Author Comment

by:sasha85
Comment Utility
thank you for your help:)

i a m tring to understand how to open the connection with the mobile and i tried to use the code in the thread but i realy don't understand how it works:(
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
Comment Utility
I have copied the code from the question into this one and changed the comm port to No. 4.
It is written to use a Hayes-compatible modem, and I can't be sure how far the protocol is the same as your mobile.
How far do you get?
Option Explicit
 

'flow control variables. Strings for now. Integers taking enumerated constants would be better

'eg.

'Const phSending = 0

'Const phReceiving = 1
 

Dim Phase As String

Dim Stage As String
 

Dim ReceiveBuffer As String

Const ReceivingInterval = 100
 

Private Sub Command1_Click()

    Dim b As String

    Dim i As Integer

   

    MSComm1.Settings = "56000,N,8,1"

    MSComm1.CommPort = 4

    MSComm1.InputLen = 0 'Default anyway

    MSComm1.RThreshold = 1 'Fire OnComm event with a single character in input buffer

    MSComm1.PortOpen = True

    Transact "ATE0", 500   'command to tell the modem not to echo the "AT" back

    Stage = "Initialising Modem"
 

End Sub
 

Sub Transact(SendText As String, TimeOut As Integer)

    ReportIt "Sending: " & SendText

    Timer1.Interval = TimeOut 'milliseconds

    ReceiveBuffer = ""

    MSComm1.Output = SendText & vbCr

    Timer1.Enabled = True

   

    Phase = "Sending"
 

End Sub
 

Private Sub Timer1_Timer()

    Dim b As String

    ReportIt "Timer: Interval: " & Timer1.Interval & " Stage: " & Stage & " Phase: " & Phase

    Select Case Phase

        Case "Sending"

            ReportIt "Nothing Received"

           

        Case "Receiving"

            b = TrimBoth(ReceiveBuffer)

            ReportIt "Received: " & b
 

            Select Case Stage

                Case "Initialising Modem"

                    If Right$(b, 2) = "OK" Then

                        Transact "ATDT 12345", 30000 ' Hard coded for now

                        Stage = "Dialling"

                        Phase = "Sending"

                    Else

                        ReportIt "Modem not responding"

                    End If

                Case "Dialling"

                    Select Case Left$(b, 7)

                        Case "CONNECT"

                            'this is where you start to control the device

                           Transact "Device Command", 30000

                           Stage = "Device1"

                           Phase = "Sending"

                        Case Else

                              'some sort of error

                    End Select

            End Select

    End Select

    Timer1.Enabled = False

End Sub
 

Function TrimRight(Intext As String) As String

    'strip blanks, tabs, line feeds etc from end of string

    Dim Text As String

   

    Text = Intext

    If Len(Intext) > 0 Then

        Do While Asc(Right$(Text, 1)) <= 32

            Text = Left$(Text, Len(Text) - 1)

        Loop

        TrimRight = Text

    End If

End Function
 
 

Private Sub MSComm1_OnComm()

ReportIt "OnComm: " & MSComm1.CommEvent

    Select Case MSComm1.CommEvent

        Case comEvSend '1 Send event.

        Case comEvReceive '2 Receive event.

            Phase = "Receiving"

            ReceiveBuffer = ReceiveBuffer & MSComm1.Input

            ReportIt "ReceiveBuffer: " & ReceiveBuffer

            Timer1.Enabled = False

            Timer1.Interval = ReceivingInterval

            Timer1.Enabled = True

        Case comEvCTS '3 Change in clear-to-send line.

        Case comEvDSR '4 Change in data-set ready line.

        Case comEvCD '5 Change in carrier detect line.

        Case comEvRing '6 Ring detect.

        Case comEvEOF '7 End of file.

        'errors

        Case comEventBreak '1001 A Break signal was received.

        Case comEventFrame '1004 Framing Error. The hardware detected a framing error.

        Case comEventOverrun '1006 Port Overrun. A character was not read from the hardware before the next character arrived and was lost.

        Case comEventRxOver '1008 Receive Buffer Overflow. There is no room in the receive buffer.

        Case comEventRxParity '1009 Parity Error. The hardware detected a parity error.

        Case comEventTxFull '1010 Transmit Buffer Full. The transmit buffer was full while trying to queue a character.

        Case comEventDCB '1011 Unexpected error retrieving Device Control Block (DCB) for the port.

   

    End Select

End Sub
 

Function TrimLeft(Intext As String) As String

    Dim Text As String

    If Len(Intext) > 0 Then

    Text = Intext

    Do While Asc(Text) <= 32

        Text = Mid$(Text, 2)

    Loop

    TrimLeft = Text

    End If

End Function
 

Function TrimBoth(Intext As String) As String

    TrimBoth = TrimLeft(TrimRight(Intext))

End Function
 

Sub ReportIt(Text As String)

    'This could be modified to write to a log file

    Dim b As String

    b = TrimBoth(Text)

    If Len(b) > 0 Then

        Debug.Print Now & " " & b

    End If

End Sub

Open in new window

0
 

Author Comment

by:sasha85
Comment Utility
i got motorola mobile and nokia mobile...how can i chack their protocol and to fit it to this string above?
the command as i see in this code writen in 'transact'?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
This shows the Hayes commands extended for Nokia phones. I expect that Motorola uses a similar set.

http://wiki.forum.nokia.com/index.php/AT_Commands
0
 

Author Comment

by:sasha85
Comment Utility
ok that suppose that is the commands...suppose i know the commands how i can connect with the phone...with the port in a way that i every command i will write inside the code it will run on the phone...
i tried every part of the code above but it somehow not work...when i look inside the settings 'phone and modems' i see the nokia and the motorola that i tried to connect on com 4
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I was only able to answer your initial question - how to senr AT to the phone - because that is the way that all modems work. I have never needed to use my mobile to dial out.

However, I will try it now.

I have an old Nokia (8310), but I can't remember how it connects to  the PC. Perhaps I have lost the cable. I also have a Sony Ericsson (K700i) which uses a bluetooth USB. Perhaps that will work.
0
 

Author Comment

by:sasha85
Comment Utility
i guess it need to be something like this http://images.google.com/images?q=nokia+8310+cable&svnum=10&um=1&hl=en&imgsz=small|medium|large|xlarge

i did not decided yet what model i will use but i think i need a phone that can store maximum sms...that means that if i will get 40 sms in one sec i need the pc to be able to read fast each sms and delete it and read the next one...if there will be 40 at a time i need the phone store maximum number of sms...
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Thanks for that. The cables don't look familiar, so perhaps I never connected my Nokia to my PC.
However, I have just managed to talk to my Sony Ericsson with Hyperterminal, so progress is being made.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I can get my phone to dial, but not (yet) to connect as a modem). I added a line in the code and commented out the original:

    Transact "ATE1", 500   'command to tell the modem to echo the "AT" back
    'Transact "ATE0", 500   'command to tell the modem not to echo the "AT" back


This is what was printed in the immediate window:

04/12/2007 21:18:51 Sending: ATE1
04/12/2007 21:18:51 OnComm: 2
04/12/2007 21:18:51 ReceiveBuffer: ATE1

OK
04/12/2007 21:18:51 Timer: Interval: 100 Stage: Initialising Modem Phase: Receiving
04/12/2007 21:18:51 Received: ATE1

OK
04/12/2007 21:18:51 Sending: ATDT 12345
04/12/2007 21:18:54 OnComm: 2
04/12/2007 21:18:54 ReceiveBuffer: ATDT 12345

NO CARRIER
04/12/2007 21:18:54 Timer: Interval: 100 Stage: Dialling Phase: Receiving
04/12/2007 21:18:54 Received: ATDT 12345

NO CARRIER
0
 

Author Comment

by:sasha85
Comment Utility
what is OnComm: 2 ?
on what stage it dailed?

do i need always to send ate1 3 times? and atdt with the numbers 3 time too?
0
 

Author Comment

by:sasha85
Comment Utility
what is the diffrences in coding  between serial rs232 cable and USB cable?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
Good morning.

I have used the Comm port before, but this is the first time that I have tried to program for a USB port. I think we must treat the USB as if it were a Comm port,  trusting that the USB driver will take care of the details.
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
So, as far as I know there are no differences in programming a real Comm port and one which is a USB and a driver.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I don't know exactly why the program sends three times, so I will analyse that next.
0
 

Author Comment

by:sasha85
Comment Utility
it is not a problem for me to use rs serial cable...
is it matter what kind of sms service provider i am using with the motorola/nokia device?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
OnComm 2
This reports the OnComm event where the value of CommEvent is 2. In the code that is a constant named comEvReceive, so it means that we have just received something
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I have been concentrating on getting dialling to work. I am an old person and don't use SMS very much. However, I'll try that next, because that is what you need.
0
 

Author Comment

by:sasha85
Comment Utility
half old or a half new?:)...i dailed my motorola from the hyperterminal with serial cable...but still cannot find a way to write VB to do this...

i am using now motorola with one mobile service provider. if i will chabge the sim...do you think  it effect the connections with the sms?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
No. The connection method will be the same.
Do you get any output in the immediate window when you run the program? If so, can you post it here?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I can't go any further with my equipment at the moment.

The Sony Ericsson returns the word ERROR when I try to issue SMS commands, and I have no means of connecting my Nokia to a PC.

For your information, most of the advice on SMS connection avoids using the mobile phone, but connects directly from the PC to the SMS service.
0
 

Author Comment

by:sasha85
Comment Utility
for example i got 10,000 sms at a time...my income limit is 200 sms
the program will need to read each sms than to procces it and delete it and read the new one...

speed is highly important...may be i will need a special GSM modem and not a regular mobile phone?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 total points
Comment Utility
You won't need to dial out, then.
I think the first SMS command that you need to send to the phone is to list the messages:

This timer routine has code for that. Remember that I can't test it.


Private Sub Timer1_Timer()

    Dim strTrimmedBuffer As String

    ReportIt "Timer: Interval: " & Timer1.Interval & " Stage: " & Stage & " Phase: " & Phase

    Select Case Phase

        Case "Sending"

            ReportIt "Nothing Received"

           

        Case "Receiving"

            strTrimmedBuffer = TrimBoth(ReceiveBuffer)

            ReportIt "Received: " & strTrimmedBuffer

 

            Select Case Stage

                Case "Initialising Modem"

                    If Right$(strTrimmedBuffer, 2) = "OK" Then

                        Transact "AT+CSMS", 30000 ' Hard coded for now

                        Stage = "Initialising Messaging"

                        Phase = "Sending"

                    Else

                        ReportIt "Modem not responding"

                    End If

                Case "Initialising Messaging"

                    If Right$(strTrimmedBuffer, 2) = "OK" Then

                        Transact "AT+CMGL", 30000 'List messages

                        Stage = "Listing messages"

                        Phase = "Sending"

                    Else

                        ReportIt "Modem not responding"

                    End If

                Case "Dialling"

                    Select Case Left$(strTrimmedBuffer, 7)

                        Case "CONNECT"

                            'this is where you start to control the device

                           Transact "Device Command", 30000

                           Stage = "Device1"

                           Phase = "Sending"

                        Case Else

                              'some sort of error

                    End Select

            End Select

    End Select

    Timer1.Enabled = False

End Sub

Open in new window

0
 

Author Comment

by:sasha85
Comment Utility
no i don't need to dail...
but do i need a gsm modem or a phone?
if i want(dream) it to get 10,000 sms in same time...
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
I expect that your phone will do the job. I'm not an expert in mobile phones, but as I understand it, just about all mobile phones have GSM modem functionality.

I will need to know exactly what happens when you run the program (paste the Immediate window results) if I am to help you any further.
0
 

Author Comment

by:sasha85
Comment Utility
i ment to write 1000...
i manage to get
Sierra Wireless AirCard 875U USB

i got it right here with me...it is staring at me right now...i want to say to him something but i don't know how to communicate with this...cause i don't know what AT command i have to use...i am sure it want to say something to me:)
some one knows where i can find the AT for sierra?
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
0
 

Author Comment

by:sasha85
Comment Utility
this is not a regular at command i think cause
+csms do not work...it got to be something like "at xxxx"
how to use those commands?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 total points
Comment Utility
The pdf that the URL in my last comment points to, indicates the Sierra supports commands such as +CMGL to list the messages and +CMGR to read a message.

Have you tried to use them?
0
 

Author Comment

by:sasha85
Comment Utility
i just write +cmgr
?
or i need at and to add something before that?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 total points
Comment Utility
This tutorial is about what to type into Hyperterminal for GSM modem connections:
http://www.developershome.com/sms/cmglCommand6.asp
If that works, then we need to put the sequence into the program.
0
 

Author Comment

by:sasha85
Comment Utility
ok...now i see the connection::)))

last question about this-
Sierra Wireless AirCard 875U USB
how can i check if it realy got better traffic than the regular nokia\moto mobile phone?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 500 total points
Comment Utility
I didn't reply to an earlier comment about commands. In the Hayes system, all commands are prefixed with AT, so the full string would be AT+CMGR

The only way to find out which is the faster would be to try them both. However I doubt if the speed of downloads from phone to PC will be a limiting factor. It will almost certainly be faster than the phone can receive.
0

Featured Post

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

Join & Write a Comment

Working settings for French ISP Orange "Prêt à Surfer" SIM cards for data connections only. Can't be found anywhere else !
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

11 Experts available now in Live!

Get 1:1 Help Now