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.
hi,
can you help me how to implement this function?
Please download the source code from http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=54140&lngWId=1 and change the line which I have said in this post.
Hope this will help
Regards,
could you please help me to convert this source code to C#.
Thanks
Eric
I do have code in C#. I will upload as soon as possible and will share it with community.
i tried to send long conconate sms using vb. All is well, sms also going on receiver mobile, but problem is this how unicode send in long sms. plz give me an example/function.
hiteshagja – were you able to post in C#? Also – do you have a C# sample of sending long sms?
Hi hiteshagja plz send me the source code in C#. i’m very very thankful to u.
my email address is fahim_bilwani72@hotmail.com