|
-
May 6th, 2013, 03:14 AM
#1
Thread Starter
New Member
how to create a program that receives messages using at commands in vb 2010?
hey guys i really need some help.
i tried this codes below that i created but it cant receive messages. and if it can i like to read it directly in Richtextbox.
here is the code:
Public Sub receive()
If srPort.IsOpen = True Then
Try
With srPort
.WriteLine("AT")
.WriteLine("AT+CMGF=1" & Chr(34) & vbCrLf)
.WriteLine("AT+CSCS=""PCCP437""" & Chr(34) & vbCrLf)
.WriteLine("AT+CPMS=""SM""" & Chr(34) & vbCrLf)
.WriteLine("AT+CMGL=""REC UNREAD""" & receiveRT.Text & vbCrLf)
End With
Catch ex As Exception
End Try
End If
End Sub
-
May 6th, 2013, 06:56 AM
#2
Re: how to create a program that receives messages using at commands in vb 2010?
You're trying to read yet....:-
Code:
.WriteLine("AT+CSCS=""PCCP437""" & Chr(34) & vbCrLf)
You seriously don't expect a function named "WriteLine" to do any thing like reading, do you ?
-
May 6th, 2013, 08:00 AM
#3
Re: how to create a program that receives messages using at commands in vb 2010?
A couple of suggestions.
1) Don't use WriteLine. Use Write. For example
.WriteLine("AT+CMGF=1" & Chr(34) & vbCrLf)
would be
.Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)
Note that the string is concatenated with CR because this is the default modem end-of-command character. Sending linefeeds is not required.
2) After each write put a readline to read the results.
I'd not use the With style. Try it like this
Code:
Dim s As String
srPort.Write("AT" & ControlChars.Cr)
s = srPort.ReadLine
Debug.WriteLine(s)
srPort.Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)
s = srPort.ReadLine
Debug.WriteLine(s)
If the command returns more that one line you will need multiple readlines to get the results.
Use code tags when you post code.
Last edited by dbasnett; May 6th, 2013 at 08:03 AM.
-
May 6th, 2013, 09:11 AM
#4
Thread Starter
New Member
Re: how to create a program that receives messages using at commands in vb 2010?
 Originally Posted by dbasnett
A couple of suggestions.
1) Don't use WriteLine. Use Write. For example
.WriteLine("AT+CMGF=1" & Chr(34) & vbCrLf)
would be
.Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)
Note that the string is concatenated with CR because this is the default modem end-of-command character. Sending linefeeds is not required.
2) After each write put a readline to read the results.
I'd not use the With style. Try it like this
Code:
Dim s As String
srPort.Write("AT" & ControlChars.Cr)
s = srPort.ReadLine
Debug.WriteLine(s)
srPort.Write("AT+CMGF=1" & Chr(34) & ControlChars.Cr)
s = srPort.ReadLine
Debug.WriteLine(s)
If the command returns more that one line you will need multiple readlines to get the results.
Use code tags when you post code.
sir will i be able to read my sms directly in textbox?
-
May 6th, 2013, 10:28 AM
#5
Re: how to create a program that receives messages using at commands in vb 2010?
Start with the code I posted. Do the debug statements show the output? If they do then 's' will contain the responses and since a TextBox.Text is a string you should be able to set the .Text with variable 's'. If you have multiple strings set the MultLine property of the textbox to true and use AppendText.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|