jaykhatri
asked on
Error Sending SMS using PDU mode
Hi Experts,
I have been trying to send the message this way:
Dim firstarg As Integer = Convert.ToInt32(pdudata.Su bstring(0, 2))
firstarg = firstarg * 2
tmp = pdudata.Substring(2)
tmp = tmp.Substring(firstarg)
firstarg = tmp.Length \ 2
port.WriteLine("AT+CMGF=0" & vbCrLf)
Thread.Sleep(500)
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
'txtsms.Text += Encoding.ASCII.GetString(i nbuf);
tmp = port.ReadExisting()
port.WriteLine("AT+CMGS=" & Convert.ToString(19) & vbCrLf)
Thread.Sleep(500)
MsgBox(port.ReadExisting() )
port.WriteLine("0011000A91 1909101535 700000AA05 E8329BFD06 " & Chr(26) & vbCrLf) 'I used constant value for testing purpose
MsgBox(port.ReadExisting() ) 'Here port shows 'ERROR'
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
Can you suggest where I am wrong, SMS is going using Text Mode.
Please provide me the solution at the earliest.
Best Regards
Jaidev Khatri
I have been trying to send the message this way:
Dim firstarg As Integer = Convert.ToInt32(pdudata.Su
firstarg = firstarg * 2
tmp = pdudata.Substring(2)
tmp = tmp.Substring(firstarg)
firstarg = tmp.Length \ 2
port.WriteLine("AT+CMGF=0"
Thread.Sleep(500)
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
'txtsms.Text += Encoding.ASCII.GetString(i
tmp = port.ReadExisting()
port.WriteLine("AT+CMGS=" & Convert.ToString(19) & vbCrLf)
Thread.Sleep(500)
MsgBox(port.ReadExisting()
port.WriteLine("0011000A91
MsgBox(port.ReadExisting()
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
Can you suggest where I am wrong, SMS is going using Text Mode.
Please provide me the solution at the earliest.
Best Regards
Jaidev Khatri
ASKER
MsgBox(port.ReadExisting() ) --> show like this > (this is what we see in hyperterminal after we send CMGF)
Ok I did some changes. Hope these are significant to your suggestion
Dim firstarg As Integer = Convert.ToInt32(pdudata.Su bstring(0, 2))
firstarg = firstarg * 2
tmp = pdudata.Substring(2)
tmp = tmp.Substring(firstarg)
firstarg = tmp.Length \ 2
port.WriteLine("ate0" & vbCrLf)
port.WriteLine("AT+CMGF=0" & vbCrLf)
Thread.Sleep(500)
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
'txtsms.Text += Encoding.ASCII.GetString(i nbuf);
tmp = port.ReadExisting()
port.WriteLine("AT+CMGS=" & Convert.ToString(19) & vbCrLf)
Thread.Sleep(500)
port.Write("0011000A911909 1015357000 00AA05E832 9BFD06" & Chr(26))
Thread.Sleep(500)
port.Write(Chr(26))
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
Still message is not going.
Please check and can u suggest me exactly where to put change.
Thanks & Best Regards
Jaidev Khatri
Ok I did some changes. Hope these are significant to your suggestion
Dim firstarg As Integer = Convert.ToInt32(pdudata.Su
firstarg = firstarg * 2
tmp = pdudata.Substring(2)
tmp = tmp.Substring(firstarg)
firstarg = tmp.Length \ 2
port.WriteLine("ate0" & vbCrLf)
port.WriteLine("AT+CMGF=0"
Thread.Sleep(500)
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
'txtsms.Text += Encoding.ASCII.GetString(i
tmp = port.ReadExisting()
port.WriteLine("AT+CMGS=" & Convert.ToString(19) & vbCrLf)
Thread.Sleep(500)
port.Write("0011000A911909
Thread.Sleep(500)
port.Write(Chr(26))
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
Still message is not going.
Please check and can u suggest me exactly where to put change.
Thanks & Best Regards
Jaidev Khatri
1) Send an ATZ command first.
2) You need a read routine which construct a buffer. You then read bytes into the buffer. You then search for a CR/LF and if so return the buffer up to the CR/LF. You delete that portion plus the CR/LF and the next time you append the data onto the end of that in the buffer. If you don't find CR/LF in the buffer, you wait 500 ms, try again and if these is no data error.
3) Then after each command you check that the read routine returns OK, if not error message and give out what you have read.
4) After an OK you should get the command prompt which is a > and after sending a command I think you also get a CR/LF. My code, which is not in VB, ignores blank or empty lines. Some phones/modems sometimes sends extra blank lines, so that's a handy feature anyway.
PS: I hope you have initialised the Port correctly. I actually use 9600 Baud, because some phones can't take the speed (in fact when using Hyperterminal to test the baud rate is almost zero!)
2) You need a read routine which construct a buffer. You then read bytes into the buffer. You then search for a CR/LF and if so return the buffer up to the CR/LF. You delete that portion plus the CR/LF and the next time you append the data onto the end of that in the buffer. If you don't find CR/LF in the buffer, you wait 500 ms, try again and if these is no data error.
3) Then after each command you check that the read routine returns OK, if not error message and give out what you have read.
4) After an OK you should get the command prompt which is a > and after sending a command I think you also get a CR/LF. My code, which is not in VB, ignores blank or empty lines. Some phones/modems sometimes sends extra blank lines, so that's a handy feature anyway.
PS: I hope you have initialised the Port correctly. I actually use 9600 Baud, because some phones can't take the speed (in fact when using Hyperterminal to test the baud rate is almost zero!)
ASKER
Dim prt As New System.IO.Ports.SerialPort ("com8", 9600, IO.Ports.Parity.None, 8, IO.Ports.StopBits.One)
this is how I am configuring the port.
I tried using ATZ to reset modem. But nothing its not working.
this is how I am configuring the port.
I tried using ATZ to reset modem. But nothing its not working.
ASKER
OK, I tried the same thing simply in hyper terminal.
Thats has given an error.
I tried this
AT
AT+CMGF=0
AT+CMGS=19
>0011000A91190910153570000 0AA05E8329 BFD06 <ctrl z>
ERROR
Doing it programatically is the next milestone, but its still not working even in hyperterminal.
Thats has given an error.
I tried this
AT
AT+CMGF=0
AT+CMGS=19
>0011000A91190910153570000
ERROR
Doing it programatically is the next milestone, but its still not working even in hyperterminal.
ASKER
Hello I tried using this PDU in hyper terminal and it worked for me.
But when I try the same thing in VB.Net 2005, it is not working, I tried all the combinaton of Thread.Sleep. It is not working.
Please let me know how can I achieve this.
But when I try the same thing in VB.Net 2005, it is not working, I tried all the combinaton of Thread.Sleep. It is not working.
Please let me know how can I achieve this.
ASKER
The Last working PDU in hyperterminal is this = 0021000C911909101535700000 02E834
So I made changes in my code like that
port.WriteLine("AT+CMGF=0" & vbCrLf)
MsgBox(port.ReadExisting)
port.WriteLine("AT+CMGS=15 " & vbCrLf)
MsgBox(port.ReadExisting)
Thread.Sleep(5000)
port.WriteLine("0021000C91 1909101535 70000002E8 34" & Chr(26))
Thread.Sleep(10000)
'read = New Byte(port.BytesToRead - 1) {}
'port.Read(read, 0, read.Length)
Not only this, I tried all the combinations, but still no success. Please help me out. I am sure the problem is in the line port.WriteLine("0021000C91 1909101535 70000002E8 34" & Chr(26))
I even tried to baud rate 9600, even tried to lower it to even 100. But still its shows 'ERROR'.
Can u please figure out the problem and let me have the exact change so that I may send sms from it.
Thanks & Best Regards
Jaidev Khatri
So I made changes in my code like that
port.WriteLine("AT+CMGF=0"
MsgBox(port.ReadExisting)
port.WriteLine("AT+CMGS=15
MsgBox(port.ReadExisting)
Thread.Sleep(5000)
port.WriteLine("0021000C91
Thread.Sleep(10000)
'read = New Byte(port.BytesToRead - 1) {}
'port.Read(read, 0, read.Length)
Not only this, I tried all the combinations, but still no success. Please help me out. I am sure the problem is in the line port.WriteLine("0021000C91
I even tried to baud rate 9600, even tried to lower it to even 100. But still its shows 'ERROR'.
Can u please figure out the problem and let me have the exact change so that I may send sms from it.
Thanks & Best Regards
Jaidev Khatri
ASKER
Hi BigRat,
As far as I understood by your post is to wait until port send the OK message.
I did the same and there is always a OK message, instead of the last statement that is >PDUcode and ctrl z
I will be thankful if you can send the code in vb.net or c#.net.
Best Regards
Jaidev Khatri
As far as I understood by your post is to wait until port send the OK message.
I did the same and there is always a OK message, instead of the last statement that is >PDUcode and ctrl z
I will be thankful if you can send the code in vb.net or c#.net.
Best Regards
Jaidev Khatri
So you can send the SMS using the following in hyper terminal?
AT+CMGF=0 <Enter>
AT+CMGS=15 <Enter>
>0021000C91190910153570000 002E834 <Ctrl-z>
and the modem replies with OK code. and the message is sent?
If yest then you can try to replace vbCrLf with VbCr. in your code.
Also you should first test sending via Text mode.
AT+CMGF=0 <Enter>
AT+CMGS=15 <Enter>
>0021000C91190910153570000
and the modem replies with OK code. and the message is sent?
If yest then you can try to replace vbCrLf with VbCr. in your code.
Also you should first test sending via Text mode.
ASKER
Thank you very much for your reply imarshad,
I tested the same code with text mode and its running very fine. Regarding vbcrlf replacement. I have already tried with all the combinations of it vbcr, vbcrlf, vblf everything. I was just thinking that I am not giving enough time to the connection to send the sms so I did wait upto 10000.
Still I have no clue whats wrong with my code. In my Msgbox its shows ERROR.
No description of Error so that I may trace accordingly.
Best Regards
Jaidev Khatri
I tested the same code with text mode and its running very fine. Regarding vbcrlf replacement. I have already tried with all the combinations of it vbcr, vbcrlf, vblf everything. I was just thinking that I am not giving enough time to the connection to send the sms so I did wait upto 10000.
Still I have no clue whats wrong with my code. In my Msgbox its shows ERROR.
No description of Error so that I may trace accordingly.
Best Regards
Jaidev Khatri
Two things.
First AT or ATZ ought to be sent to reset the device.
Second, when a message is sent one gets a CMGS: reply with the message number. Do you see such a reply on Hyperterminal?
First AT or ATZ ought to be sent to reset the device.
Second, when a message is sent one gets a CMGS: reply with the message number. Do you see such a reply on Hyperterminal?
ASKER
Yeah i am resetting the device.
Second as far as I understood your query means : When all is complete and I press ctrl+z. I get message on hyperterminal like '+cms' and some digit.
Second as far as I understood your query means : When all is complete and I press ctrl+z. I get message on hyperterminal like '+cms' and some digit.
ASKER
I suspect there is problem in chr(26). Should it be done exactly what i am doing. I am in doubt.
>>I get message on hyperterminal like '+cms' and some digit.
Yes, actually the number counts up, so after each message you next the next number.
>>I suspect there is problem in chr(26)
No 26 is Hex 1A and that is CTRL/Z since Z is hex 5A and the control takes away hex 40.
Would you care to post the ENTIRE code for the message sending?
Yes, actually the number counts up, so after each message you next the next number.
>>I suspect there is problem in chr(26)
No 26 is Hex 1A and that is CTRL/Z since Z is hex 5A and the control takes away hex 40.
Would you care to post the ENTIRE code for the message sending?
ASKER
This is the total code:
Public Sub Senddata(ByVal port As SerialPort, ByVal pdudata As String)
Dim firstarg As Integer = Convert.ToInt32(pdudata.Su bstring(0, 2))
firstarg = firstarg * 2
tmp = pdudata.Substring(2)
tmp = tmp.Substring(firstarg)
firstarg = tmp.Length \ 2
port.WriteLine("atz" & vbCr)
port.WriteLine("ate0" & vbCr)
port.WriteLine("AT+CMGF=0" & vbCr)
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
'txtsms.Text += Encoding.ASCII.GetString(i nbuf);
tmp = port.ReadExisting()
port.WriteLine("AT+CMGS=15 " & vbCr)
Thread.Sleep(1000)
port.WriteLine("0021000C91 1909101535 70000002E8 34" & Chr(26))
Thread.Sleep(5000)
port.DiscardOutBuffer()
'read = New Byte(port.BytesToRead - 1) {}
'port.Read(read, 0, read.Length)
End Sub
and the port object is this:
Dim prt As New System.IO.Ports.SerialPort ()
With prt
.PortName = "com8"
.BaudRate = 19200
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
prt.Open()
send.Senddata(prt, sendmsg) //here sendmsg is string but I am not using this string in the message
prt.Close()
I am using vs 2005 with Dot Net Framework 2.0 and using VB.Net Language.
Public Sub Senddata(ByVal port As SerialPort, ByVal pdudata As String)
Dim firstarg As Integer = Convert.ToInt32(pdudata.Su
firstarg = firstarg * 2
tmp = pdudata.Substring(2)
tmp = tmp.Substring(firstarg)
firstarg = tmp.Length \ 2
port.WriteLine("atz" & vbCr)
port.WriteLine("ate0" & vbCr)
port.WriteLine("AT+CMGF=0"
read = New Byte(port.BytesToRead - 1) {}
port.Read(read, 0, read.Length)
'txtsms.Text += Encoding.ASCII.GetString(i
tmp = port.ReadExisting()
port.WriteLine("AT+CMGS=15
Thread.Sleep(1000)
port.WriteLine("0021000C91
Thread.Sleep(5000)
port.DiscardOutBuffer()
'read = New Byte(port.BytesToRead - 1) {}
'port.Read(read, 0, read.Length)
End Sub
and the port object is this:
Dim prt As New System.IO.Ports.SerialPort
With prt
.PortName = "com8"
.BaudRate = 19200
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
prt.Open()
send.Senddata(prt, sendmsg) //here sendmsg is string but I am not using this string in the message
prt.Close()
I am using vs 2005 with Dot Net Framework 2.0 and using VB.Net Language.
ASKER
And yes since everything was not working I used pduspy software to get the pdu string.
ASKER
please let me know if you need more details.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i tried replacing writeline with write bu still error is coming. Do I need to replace anything else also.
ASKER
Thank you very very much BigRat, I tried something more after replacing with write.
I did
port.WriteLine("AT+CMGS=15 " & vbLf)
instead of
port.WriteLine("AT+CMGS=15 " & vbCr)
Just send the first sms from this program.
Thank you very very much.
If i will have any query I will return but obviously with new question :)
Jaidev Khatri
I did
port.WriteLine("AT+CMGS=15
instead of
port.WriteLine("AT+CMGS=15
Just send the first sms from this program.
Thank you very very much.
If i will have any query I will return but obviously with new question :)
Jaidev Khatri
I ask because with Echo on the phone will reply to port.WriteLine("AT+CMGS=" & Convert.ToString(19) & vbCrLf) withe the command you sent, plus CR/LF plus OK plus CR/LR and these characters are NOT send all at once but bit by bit, so if you are too fast you think you have read all the messages but there's still some there.
The correct way to prgram this is 1) turn echo off and 2) check EVERY response form EVERY command for errors and 3) read data UNTIL you get CR/LF and then, and only then, look at what you've got.
I suspect that ReadExisting just reads what is in the buffer. It probably does NOT read until it finds the CR/FL sequence.