Sending SMS in PDu mode programatically in VB.Net
-
Hi, I have been struggling to send sms using pdu mode in vb.net, My code is working fine for Text Mode, even I am sending sms from Hyperterminal with PDU command. When I try the same PDU in VB.Net code. The same is not working. I trying waiting for the port to respond. Used Thread.Sleep upto 10000ms but not succeed. Below is my code in VS 2005 (2.0 Framework) Dim firstarg As Integer = Convert.ToInt32(pdudata.Substring(0, 2)) firstarg = firstarg * 2 tmp = pdudata.Substring(2) tmp = tmp.Substring(firstarg) firstarg = tmp.Length \ 2 port.WriteLine("atz" & vbCrLf) port.WriteLine("ate0" & vbCrLf) port.WriteLine("AT+CMGF=0" & vbCrLf) read = New Byte(port.BytesToRead - 1) {} port.Read(read, 0, read.Length) 'txtsms.Text += Encoding.ASCII.GetString(inbuf); tmp = port.ReadExisting() port.WriteLine("AT+CMGS=15" & vbCrLf) Thread.Sleep(1000) port.WriteLine("0021000C91190910153570000002E834" & Chr(26)) Thread.Sleep(5000) port.DiscardOutBuffer() 'read = New Byte(port.BytesToRead - 1) {} 'port.Read(read, 0, read.Length) I tried using msgbox and found that everything is going perfect except the last command i.e. 0021.... chr(26) The given pdu is working in hyperterminal. Can u figure out the problem for me. Your solution will be highly appreciable as I am tired trying various combinations. Thanking you in the meantime. Jaidev Khatri
-
Hi, I have been struggling to send sms using pdu mode in vb.net, My code is working fine for Text Mode, even I am sending sms from Hyperterminal with PDU command. When I try the same PDU in VB.Net code. The same is not working. I trying waiting for the port to respond. Used Thread.Sleep upto 10000ms but not succeed. Below is my code in VS 2005 (2.0 Framework) Dim firstarg As Integer = Convert.ToInt32(pdudata.Substring(0, 2)) firstarg = firstarg * 2 tmp = pdudata.Substring(2) tmp = tmp.Substring(firstarg) firstarg = tmp.Length \ 2 port.WriteLine("atz" & vbCrLf) port.WriteLine("ate0" & vbCrLf) port.WriteLine("AT+CMGF=0" & vbCrLf) read = New Byte(port.BytesToRead - 1) {} port.Read(read, 0, read.Length) 'txtsms.Text += Encoding.ASCII.GetString(inbuf); tmp = port.ReadExisting() port.WriteLine("AT+CMGS=15" & vbCrLf) Thread.Sleep(1000) port.WriteLine("0021000C91190910153570000002E834" & Chr(26)) Thread.Sleep(5000) port.DiscardOutBuffer() 'read = New Byte(port.BytesToRead - 1) {} 'port.Read(read, 0, read.Length) I tried using msgbox and found that everything is going perfect except the last command i.e. 0021.... chr(26) The given pdu is working in hyperterminal. Can u figure out the problem for me. Your solution will be highly appreciable as I am tired trying various combinations. Thanking you in the meantime. Jaidev Khatri
This function worked for me. It sends a PDU message.
Private Sub PDUSMS()
If Comport = "" Then MsgBox("Please Choose A connection") : Return
smsPort.PortName = Comport
smsPort.BaudRate = "115200"
smsPort.Parity = Parity.None
smsPort.DataBits = 8
smsPort.StopBits = StopBits.One
smsPort.Handshake = Handshake.RequestToSend
smsPort.DtrEnable = True
smsPort.RtsEnable = True
smsPort.NewLine = vbCrLfIf Not (smsPort.IsOpen = True) Then smsPort.Open() End If At\_length = "17" PDU\_code = "079144772800800011000C914477529628010000AA03E8721E" 'smsPort.WriteLine("AT" & vbCrLf) 'System.Threading.Thread.Sleep(2000) 'Pause to allow last command to get to phone smsPort.WriteLine("AT+CMGF=0" & vbCrLf) 'open space for new message System.Threading.Thread.Sleep(2000) 'Pause to allow last command to get to phone smsPort.WriteLine("AT+CSMS=0" & vbCrLf) 'open space for new message System.Threading.Thread.Sleep(2000) 'Pause to allow last command to get to phone smsPort.WriteLine("AT+CMGS=" + At\_length + vbCrLf) '+ Chr(34) + At\_length + Chr(34) + System.Threading.Thread.Sleep(2000) 'Pause to allow last command to get to phone smsPort.WriteLine(PDU\_code + Chr(26)) 'number to send message to + vbCrLf + System.Threading.Thread.Sleep(2000) If smsPort.IsOpen = True Then smsPort.Close() End If End Sub