Feeds:
Posts
Comments

Posts Tagged ‘Text to PDU’

Text Message must be encoded properly into PDU before submitting it to network. [Note: this is applicable if you are going to send SMS in PDU mode]. In this post I am going to explain how you can do this, but before that please download sample code from Planet Source code. This code contains Convert, Sending and Receiving modules. Frankly speaking I have got encoding/decoding logic from this code and it works perfectly for me. Only thing missing in this code is Padding Bit logic. Code is quite simpler and easily understandable. Please go through it and tell me if you have problem encoding text message into PDU.

How to add Padding bit for multipart SMS PDU?
Open the code > go to Convert Module > Find “CharHex”  Method.
Do replace this function with the code shown below.

Public Function CharHex(ByVal Txt As String, ByVal bit As Integer, ByVal PaddingBit As Boolean)
Dim i As Integer, bin As String, nbin As String, n As String
Dim bil As Integer, sisa As Integer, lbin As Integer, nol As String
bin = ""
nbin = ""
If bit = 7 Then
For i = 1 To Len(Txt) Step 2
n = Mid(Txt, i, 2)
bin = HexToBin(n) & bin
Next
bil = Len(bin) \ bit
sisa = Len(bin) Mod bit
For i = 1 To (Len(bin) - sisa) Step bit
' MsgBox Chr$(HexToDec(BinToHex(Mid(bin, i + Sisa, bit))))
nbin = Chr$(HexToDec(BinToHex(Mid(bin, i + sisa, bit)))) & nbin
Next
Else
For i = 1 To Len(Txt)
n = Mid(Txt, i, 1)
bin = Biner(Asc(n)) & bin
Next
If PaddingBit = True Then
bin = bin + "0"
End If
sisa = Len(bin) Mod bit
If sisa > 0 Then
For i = 1 To bit - sisa
nol = nol & "0"
Next
End If
bin = nol & bin
bil = Len(bin) \ bit
For i = 1 To bil
nbin = nbin & BinToHex(Mid(bin, Len(bin) + 1 - bit * i, bit))
Next
End If
CharHex = nbin
End Function

That’s it !!
Do let me know if you have any problem encoding text to PDU.

Update:

I am getting lot or queries regarding Message PDU for single message and concatenated message. So What I have done is I have created a quick sample to generate PDU for single message and for multipart SMS.

Go to my new website www.hiteshagja.com to download sample code

Advertisements

Read Full Post »