473,394 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem with AT send with GSM modem

2
I have a GSM modem, Wavecom.
When I connect to it using HyperTerminal, i can send SMS with the standard AT comands, like this:

AT+CMGS="+351nnnnnnnnn" <CR>
> text to send in the message <Control-Z>

and the SMS goes on.

Note: <CR> means ENTER
Note: <CR> is ASCII 13, and Control-Z is ASCII 26.

When I use VisualBasic, the SAME AT sequence does not work.
And I get an ERROR (twice).

The manual says to do the following:

MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnnnnn" & chr(34) & chr(13)

MsComm.Output = "text to send in the message" & chr(26).

Note: chr(34) is the character for the commas(").

What is wrong?

Many thanks for any help.
Jan 29 '07 #1
17 12428
willakawill
1,646 1GB
Hi. You could try this
Expand|Select|Wrap|Line Numbers
  1. Const quote As String = """"
  2. MsComm.Output = "AT+CMGS=" & quote & "+351nnnnnnnnn" & quote & vbCr
Jan 30 '07 #2
Killer42
8,435 Expert 8TB
I have a GSM modem, Wavecom.
When I connect to it using HyperTerminal, i can send SMS with the standard AT comands, like this:
AT+CMGS="+351nnnnnnnnn" <CR>
> text to send in the message <Control-Z>
and the SMS goes on.
When I use VisualBasic, the SAME AT sequence does not work.
And I get an ERROR (twice).
The manual says to do the following:
MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnnnnn" & chr(34) & chr(13)
MsComm.Output = "text to send in the message" & chr(26).
A couple of questions...
  • Are you certain that it's only a CR which is sent after the AT command?
  • What error are you getting?
  • What does the ">" represent on the second line? (I ask mainly because it is not present in the VB version.)
  • Are you sure you're in command mode? I seem to recall (from more than 10 years ago, I think) that you have to pause for at least a second, then send "+++" then another pause, to go into command mode. But this probably only applies if you are online at the time, right?
  • Is this code copied/pasted, or typed in here? Because
    MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnnnnn" & chr(34) & chr(13)
    seems to have quotes in the wrong places. It probably should have been
    MSComm.Output = "AT+CMGS=" & chr(34) & "+351nnnnnnnnn" & chr(34) & chr(13)
You can also make the code much more compact and readable by using CONST values as willakawill suggested. (Oops! Didn't realise you'd also fixed the mixed-up quotes, Will.)
Jan 30 '07 #3
willakawill
1,646 1GB
Yeah. Get with it down there. You're supposed to be 13 hours ahead of me :)
Jan 30 '07 #4
iburyak
1,017 Expert 512MB
It looks like your error is here:


[PHP]"+ "+351nnnnnnnnn" [/PHP]

You have "+ twice.
Jan 30 '07 #5
iburyak
1,017 Expert 512MB
Try this:

MSComm.Output = "AT+CMGS=""+351nnnnnnnnn""" & chr(13)

MsComm.Output = "text to send in the message" & chr(26).
Jan 30 '07 #6
willakawill
1,646 1GB
Try this:

MSComm.Output = "AT+CMGS=""+351nnnnnnnnn""" & chr(13)

MsComm.Output = "text to send in the message" & chr(26).
You are posting the same answer that has already been posted by 2 others
Jan 30 '07 #7
Killer42
8,435 Expert 8TB
Yeah. Get with it down there. You're supposed to be 13 hours ahead of me :)
Yeah, well it's hard to forecast accurately what someone is going to say in 13 hours. ;)
Jan 30 '07 #8
I have a GSM modem, Wavecom.
When I connect to it using HyperTerminal, i can send SMS with the standard AT comands, like this:

AT+CMGS="+351nnnnnnnnn" <CR>
> text to send in the message <Control-Z>

and the SMS goes on.

Note: <CR> means ENTER
Note: <CR> is ASCII 13, and Control-Z is ASCII 26.

When I use VisualBasic, the SAME AT sequence does not work.
And I get an ERROR (twice).

The manual says to do the following:

MSComm.Output = "AT+CMGS=" & chr(34) & "+ "+351nnnnnnnnn" & chr(34) & chr(13)

MsComm.Output = "text to send in the message" & chr(26).

Note: chr(34) is the character for the commas(").

What is wrong?

Many thanks for any help.

Hi friend,

I've been in that kind of situation before and I used VB6 too, I developed a computer program that will keep all the SMS to my database and reply back with some information.

Ok here is the answer, before i tried that using chr(13) because this is the equivalent for the new line but unfortunately i dont know why this chr(13) is not working in MSCOM, but the only thing left is the constant value of VBCRLF you can use this as a substitute in chr(13)

Inshort

chr(13) = VBCRLF

and dont forget to send +++ it means that you will set the GSM in Command mode. Some1 already post this one, you better be careful in sending AT Command always keep in mind that before sending another batch of command you need to wait just for a second or 2, just use Sleep function in VB6.

Actually, after I solved that problem reagrading GSM and MSCOMM I realized that ANSI C is the much better language to use beacuse it is very easy to communicate with Devices like GSM. I am just telling you this because I experienced that before, but it will work fine in VB6 with MSCOMM


Norman
Jan 31 '07 #9
Hi friend,

I've been in that kind of situation before and I used VB6 too, I developed a computer program that will keep all the SMS to my database and reply back with some information.

Ok here is the answer, before i tried that using chr(13) because this is the equivalent for the new line but unfortunately i dont know why this chr(13) is not working in MSCOM, but the only thing left is the constant value of VBCRLF you can use this as a substitute in chr(13)

Inshort

chr(13) = VBCRLF

and dont forget to send +++ it means that you will set the GSM in Command mode. Some1 already post this one, you better be careful in sending AT Command always keep in mind that before sending another batch of command you need to wait just for a second or 2, just use Sleep function in VB6.

Actually, after I solved that problem reagrading GSM and MSCOMM I realized that ANSI C is the much better language to use beacuse it is very easy to communicate with Devices like GSM. I am just telling you this because I experienced that before, but it will work fine in VB6 with MSCOMM


Norman

EXAMPLE:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  3.  
  4.  
  5. Private Sub Command1_Click()
  6. Dim strSMS As String
  7. 'set contact number
  8. 'buffer you message here
  9. strSMS = "Hello World!"
  10. 'Before sending command
  11. MSComm1.Output = "+++" & vbCrLf
  12. 'wait a second
  13. Sleep 1
  14. 'send at commands
  15. MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnnnnn" & Chr(34) & vbCrLf
  16.  
  17. 'There are some GSM modems that after sending "AT+CMGS"
  18. 'it will response before buffering the message
  19.  
  20. 'Ex.
  21. ' step 1: MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnnnnn" & Chr(34) & vbCrLf
  22. ' step 2: MSComm1.Input is equal to OK/ERROR
  23. ' step 3: then > insert your message
  24.  
  25. 'In this case the GSM is allowing you to check first if the AT command is valid or not
  26. 'before buffering the message to GSM
  27.  
  28. 'I dont know if this is your case but you can check.
  29.  
  30. While 1
  31.     'wait for 1 second or 2
  32.  
  33.     Sleep 1  'this is depend on how fast your GSM communicate with MSCOMM
  34.  
  35.     'Always wait this > sign to come out, because this the signal that the GSM is ready
  36.     'to get the Message
  37.  
  38.     'if MSComm1.Input = ">" send your Message to GSM
  39.  
  40.     'note: make it sure that no other chr(s) in MSComm1.Input except ">"
  41.     'The last thing to remember is do not ever try to use the DOEVENTS
  42.  
  43.     If StrComp(Left(MSComm1.Input, 1), ">", vbBinaryCompare) = 0 Then
  44.         MSComm1.Output = strSMS & Chr(26)
  45.         Sleep 2
  46.         'Before you do this pls remove the chr(26)
  47.         If StrComp(Replace(MSComm1.Input, Chr(26), ""), "OK", vbBinaryCompare) = 0 Then
  48.             'place your flag
  49.             GoTo ExitWhile
  50.         ElseIf StrComp(Replace(MSComm1.Input, Chr(26), ""), "ERROR", vbBinaryCompare) = 0 Then
  51.             'place your flag
  52.             GoTo ExitWhile
  53.         Else
  54.     End If
  55. Wend
  56.  
  57. ExitWhile:
  58.     'do your valdations here etc
  59.     'Check your falg here if error is true or false
  60.     Sleep 2
  61.  
  62.  
  63. End Sub
Jan 31 '07 #10
EXAMPLE:

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)


Private Sub Command1_Click()
Dim strSMS As String
'set contact number
'buffer you message here
strSMS = "Hello World!"
'Before sending command
MSComm1.Output = "+++" & vbCrLf
'wait a second
Sleep 1
'send at commands
MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnnnnn" & Chr(34) & vbCrLf

'There are some GSM modems that after sending "AT+CMGS"
'it will response before buffering the message

'Ex.
' step 1: MSComm1.Output = "AT+CMGS=" & Chr(34) & "+351nnnnnnnnn" & Chr(34) & vbCrLf
' step 2: MSComm1.Input is equal to OK/ERROR
' step 3: then > insert your message

'In this case the GSM is allowing you to check first if the AT command is valid or not
'before buffering the message to GSM

'I dont know if this is your case but you can check.

While 1
'wait for 1 second or 2

Sleep 1 'this is depend on how fast your GSM communicate with MSCOMM

'Always wait this > sign to come out, because this the signal that the GSM is ready
'to get the Message

'if MSComm1.Input = ">" send your Message to GSM

'note: make it sure that no other chr(s) in MSComm1.Input except ">"
'The last thing to remember is do not ever try to use the DOEVENTS

If StrComp(Left(MSComm1.Input, 1), ">", vbBinaryCompare) = 0 Then
MSComm1.Output = strSMS & Chr(26)
Sleep 2
'Before you do this pls remove the chr(26)
If StrComp(Replace(MSComm1.Input, Chr(26), ""), "OK", vbBinaryCompare) = 0 Then
'place your flag
GoTo ExitWhile
ElseIf StrComp(Replace(MSComm1.Input, Chr(26), ""), "ERROR", vbBinaryCompare) = 0 Then
'place your flag
GoTo ExitWhile
Else
End If
Wend

ExitWhile:
'do your valdations here etc
'Check your falg here if error is true or false
Sleep 2


End Sub

In addition, please always use PDU mode in reading and sending TEXT SMS Messages.

MSComm1.Output = "AT+CMGS=0"

AT+CMGF: Message Format:
Command Possible response(s) +CMGF=[<mode>] +CMGF?+CMGF: <mode> +CMGF=?+CMGF: (list of supported <mode>s)
<mode>: 0: PDU mode;
<mode>: 1: TEXT mode;


check out about PDU encryption/Decryption methods
http://www.activexperts.com/activsms/sms/pdu/
Jan 31 '07 #11
Killer42
8,435 Expert 8TB
[quote=sirsnorklingtayo]
Expand|Select|Wrap|Line Numbers
  1. ...
  2.     'wait for 1 second or 2
  3.     Sleep 1
  4. ...
Is this a routine of your own? I don't think VB6 has a Sleep statement. Mine doesn't, anyway.
Jan 31 '07 #12
[quote=Killer42]
Expand|Select|Wrap|Line Numbers
  1. ...
  2.     'wait for 1 second or 2
  3.     Sleep 1
  4. ...
Is this a routine of your own? I don't think VB6 has a Sleep statement. Mine doesn't, anyway.
Nop, SLEEP is an WIN32 API function it acts like a delay() function in ANSI C

Here is the declaration:
Expand|Select|Wrap|Line Numbers
  1. 'You can place this in Form, Module Class etc but indicate the declration scope
  2. 'like Global,Public,Private
  3.  
  4. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
  5.  
  6. 'to use this
  7.  
  8. Private Sub StopForAWhile(byval milliseconds as Integer)
  9.  
  10.   Sleep 1000 ' stop for 1 second
  11.  
  12. end sub
and I admit that I made a mistake instead of Sleep 1 it should be Sleep 1000

Sleep 1 = 1/1000 second stop
Sleep 1000 = 1second stop


Sorry for my mistakes

hehehe

norman
Feb 1 '07 #13
Killer42
8,435 Expert 8TB
Nop, SLEEP is an WIN32 API function it acts like a delay() function in ANSI C
Ah! Thanks for the reminder. I think I used it, years ago.
Feb 1 '07 #14
willakawill
1,646 1GB
In the interests of clarity for those scouring these pages for tidbits, perhaps you mean:
Expand|Select|Wrap|Line Numbers
  1. Private Sub StopForAWhile(byval milliseconds as Integer)
  2.  
  3. Sleep milliseconds ' stop for (milliseconds/1000) seconds
  4.  
  5. end sub
This is also a useful way to call sleep:
Expand|Select|Wrap|Line Numbers
  1. Private Sub WaitSec(ByVal secs as Integer)
  2.  
  3. Sleep secs * 1000 ' stop for secs seconds
  4.  
  5. end sub
Feb 1 '07 #15
UmDois
2
There was an error ("+) in the text i posted, but that was not the reason for my problem with GSM modem in VB6.

I found the solution: two more commands BEFORE the real string:

MSComm.Output = ""
MSComm.OutputBufferSize = 0
MSComm.Output = "the real string tou want to send"

And it works.
Feb 2 '07 #16
Killer42
8,435 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Private Sub WaitSec(ByVal secs as Integer)
  2.   Sleep secs * 1000 ' stop for secs seconds
  3. end sub
In a case like this I recommend using Single rather than Integer for the number of seconds. It allows finer control, for example pausing for 1½ seconds.
Feb 2 '07 #17
Congrats to all, I think our efforts paid up. The problem has been solved he he he.
So, good luck with your GSM Modem Project and thanks for the Information about the 2 lines of codes. I don't know about those codes and I never tried that before, but the more important is your program is now up and running. Happy coding with AT Commands

And about SLEEP sleep function, ya you are right SLEEP secs * 1000 I think this is the most clear example than mine.

Sleep secs * 1000 'seconds to wait

And I made a mistake again ha ha ha, Instead of using INTEGER for the Variable (millimseconds) use LONG data type in my last example.


Norman
Feb 3 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kees Bakelaar | last post by:
Hi all, This is not really a VB question, however, i am stuck a modem problem The modem is connected to a cristie teleport with a speed of 9600 bps. How can i set the modems DTE speed at...
1
by: Anne | last post by:
Hi NG I got a problem. I use the following code to print out reports imidiately: Docmd.openReport "RptCase", acviewNormal This works fine at the office and at home, but at a customer it...
0
by: Filips Benoit | last post by:
New attempt: previous discussion 18/09/2004 stopt ! W2000 office2000 Added ref to 'Microsoft CDO for NTS 1.2 Library' No code error BUT NO emails send What's missing? Please help!
5
by: Cc | last post by:
hi, I making a program to control modem , I had follow example from MS website on how to access serial port but still don't know how to make modem dial . Is there any example on how I could make...
11
by: tnhoe | last post by:
Hi, I am looking for above. Any recommendation ? The GSM modem is a data card with phone chip in notebook which can send sms directly without going through other sms gateway URL. I only need...
17
by: Franc Zabkar | last post by:
My D-Link DSL-302G modem/router has a real-time clock whose settings are volatile. To avoid hand keying the date/time via the modem's JS interface, I wonder if there is a way to copy the JS code to...
1
by: vgonepudi | last post by:
Hi, Requirement: I want to send numeric message to pager. For that I have developed an application in VC++. My application takes pager number as input and dials that number through my local...
0
by: Tym | last post by:
Not sure this is the right group - but here goes. I kinda expect Dick Grier to jump in on this one ;-) I've got a windows app in VB.Net 2005 which sends and receives text messages via a USM...
5
by: Tym | last post by:
Not sure this is the right group - but here goes. I kinda expect Dick Grier to jump in on this one ;-) I've got a windows app in VB.Net 2005 which sends and receives text messages via a USM...
2
by: muruganyuva | last post by:
hi, in my project i'm sending the data from source to destination with the help of modem. one modem at the source and other at the destination. at first i'm initializing the source modem. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.