potetojb
Member level 3
- Joined
- Feb 25, 2006
- Messages
- 63
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Johor,Malaysia
- Activity points
- 1,931
thedesolatesoul said:Okay potetojb, I've checked your program and there are a few things to modify although its a very well written program.
When you set the InputLen to Zero, that means that the MSComm control will read the whole line at once so you dont need to worry about buffer sizes.
You dont need to send ATE0 i.e. the echo off command.
You also need to send an SMS message format command
i.e. AT+CMGF=1 to see the text messages
When you want to reveive the message using AT+CMGR dont use AT+CMGR=1
because the message numbers dont always start from 1. They could be anything like 800,860 etc.
So first you need to download the whole list of SMS messages using the AT+CMGL command.
Then you need to process the list and get the message number you want from it and then read it.
I've used a Motorola C975 to check this and been able to successfully download the message.
Here's the code. I suppose you only need to change the COM port.
Private Sub Command1_Click()
Dim sms As String
Dim buffer$
Dim MsgNumber(100) As Integer
With MSComm1
.CommPort = 4
.Settings = "9600,N,8,1"
.InputLen = 0
.Handshaking = comNone
.PortOpen = True
End With
'Report Mobile Equipment Error ( enable )
MSComm1.Output = "AT+CMEE=1" & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""
'Set SMS format to Text
MSComm1.Output = "AT+CMGF=1" & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
buffer$ = ""
'Receive List from Mobile
MSComm1.Output = "AT+CMGL" & Chr$(13)
Do
DoEvents
buffer$ = MSComm1.Input
If buffer$ <> "" Then
Text1.Text = Text1.Text & vbCr & buffer$
List1.AddItem Replace(buffer$, Chr(13) & Chr(10), " ") 'remove all the carriage returns before adding to the listbox
End If
Loop Until InStr(buffer$, "OK")
buffer$ = ""
'Now we have to parse the received list of messages
'This contains messages from the inbox, outbox, etc etc
'My motorola was giving "REC READ" for inbox messages
'For eg: +CMGL: 843, "REC READ", "+923452914470"
J = 0
For I = 0 To List1.ListCount - 1
If InStr(List1.List(I), "REC READ") Then 'This is from the Inbox
MsgNumber(J) = Val(Mid(List1.List(I), 9, InStr(List1.List(I), ",") - 9))
J = J + 1
End If
Next
'Now getting the highest number which will hopefully be the newest SMS
SMSNumber = 0
For I = 0 To J - 1
If MsgNumber(I) > SMSNumber Then
SMSNumber = MsgNumber(I)
End If
Next
'Received read message
MSComm1.Output = "AT+CMGR=" & SMSNumber & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & MSComm1.Input
Loop Until InStr(buffer$, "OK")
Text1.Text = Text1.Text & vbCr & buffer$
Text2.Text = buffer$
buffer$ = ""
MSComm1.PortOpen = False
End Sub
Also check out these sites.
**broken link removed**
http://www.etsi.org/ for standards 300 642
[/url]
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?