Click here to Skip to main content
15,890,897 members
Articles / Programming Languages / Visual Basic
Article

Using VB.NET to Encode SMS and EMS

Rate me:
Please Sign up or sign in to vote.
4.69/5 (30 votes)
31 May 2005CPOL7 min read 373.9K   16.8K   126   67
An article on SMS and EMS Encoders.

Image 1

Introduction

Hi, we're back again to generate the PDU code while we have known how to decode PDU code. But at first, sorry for the late publishing of my PDU encoder as I was busy for a long time. These classes are written for my own program, but they can be easily implemented in your project. And this tiny demo program can be used to get the correct PDU code from your setting so as to convince your AT command test work. I'll show how to do this later in this article.

Background

It was last year that I did some work on SMS and EMS PDU code encoding and decoding. And I wrote my PDU Decoder to help me get the PDU strings returned from the mobile. That article has been read by more than twenty thousands people all over the world. Some one pointed out the bugs hidden in my decoder and they helped me to improve my decoder.

But my encoder, although I have done it in February this year, I have it shown to the world in the hot summer. I'm sorry again for this.

Like the decoder, this encoder also was created according to GSM 03.40. But I use 3GPP TS 23.040 V6.5.0 for reference. The link to these documents can be found at the end of this article.

OK. Here we start, I'll introduce my encoder step by step and hope it will give you a hand when designing an encoder.

The architecture of this encoder

The most important parts, public class SMS and ConcatenatedShortMessage, are under the namespace SMS and Encoder. Figure 1 shows this.

Image 2

The SMS class is foundation of SMS and EMS. It has the basic elements required for SMS. Figure 2 shows you the SMS class. I'll explain how this class works in detail later.

Please note that I have set a group of protected variables prefixed with TP. These variables' names can be easily found in 3GPP or GSM documents. And there're also a set of properties, e.g. ServiceCenterNumber, TP_Status_Report_Request. When you set these properties, they prepare the correct PDU string and store them in protected variables for future use.

This class implements one function GetSMSPDUCode() to generate PDU code. This function simply joins the protected variables in a certain order to get a PDU code. Another function FirstOctet() contains the first octet data in PDU code. We can use it in some particular occasions.

We know that EMS is composed of several SMSs. Each SMS has TP_UserDataHeader set which is different from simple SMS. We can easily inherent from SMS to create the base of EMS. And please note the Concatenated Short Message is only part of EMS, which allows you to send messages containing more than 160 ASCII characters or 70 Unicode characters. You can inherent the SMS class and build another portion of EMS.

From figure 2 you can see an Integer variable named TotalMessages. It tells you how many SMS PDU Codes are generated. And note the GetEMSPDUCode(), it returns a number of SMS PDU codes. I'll explain this later.

Image 3

How it really works?

In order to demonstrate and explain the details about how this encoder works, let us open my demo program in Visual Studio.

First, please find function GetPDU() in the Form and make a checkpoint. We will trace it down.

Then build and start this program. Fill the blanks according to the picture shown at the beginning of this article and then click Get PDU Code button.

The program stops at the checkpoint. Let's trace down the code. It first check the coding scheme and user data length to ensure if EMS will be used. Please note that the SMSObject is an object type. It will be blind to a specific type of SMS or EMS. Going down the code, we see it sets ServiceCenterNumber and other properties.

Please trace into ServiceCenterNumber property and you can see it prepares PDU code from your setting. The final result is stored in a protected variable SC_Number. Similar process happen to all the properties.

Then, according to the type of SMSObject, we use GetSMSPDUCode() or GetEMSPDUCode() to get PDU codes.

Function details

Let's look into the detail of the GetSMSPDUCode function:

VB
Public Overridable Function GetSMSPDUCode() As String
    Dim PDUCode As String
    'Check User Data Length
    If TP_DCS = ENUM_TP_DCS.DefaultAlphabet Then
        If TP_UD.Length > 280 Then 
            Throw New Exception("User Data is TOO LONG for SMS")
    End If
    If TP_DCS = ENUM_TP_DCS.UCS2 Then
        If TP_UD.Length > 280 Then 
            Throw New Exception("User Data is TOO LONG for SMS")
    End If
    'Make PDUCode
    PDUCode = SC_Number
    PDUCode += FirstOctet()
    PDUCode += Format(TP_MR, "X2")
    PDUCode += TP_DA
    PDUCode += Format(TP_PID, "X2")
    PDUCode += Format(TP_DCS, "X2")
    PDUCode += Format(TP_VP, "X2")
    PDUCode += Format(TP_UDL, "X2")
    PDUCode += TP_UD
    Return PDUCode
End Function

This function first checks the coding and determines if the length of user data is longer than the maximum size. Then every prepared PDU code is added to the variable PDUCode. Note the PDU codes are added by a certain order. So it is an easy task to modify the order or add some more PDU codes simply by changing the order or adding the other PDU codes to PDUCode. This gives my class flexibility and extensibility.

Here are also two core functions: Encode7Bit() and EncodeUCS2(). You can treat UCS2 as Unicode and use AscW function to get Unicode character.

But Encode7Bit is much more complex. In order to ease this encoding, I use several help functions such as BitsToHex, CharTo7Bits and so on. First I convert hex number to binary and join them together, then I split them into 8 bits. Please refer to GSM documents for detailed information about 7 bit encoding.

Let us take a look at GetEMSPDUCode():

VB
Public Function GetEMSPDUCode() As String()
    Select Case tp_dcs
        Case ENUM_TP_DCS.UCS2
            TotalMessages = (TP_UD.Length / 4) \ 66 + ((TP_UD.Length / 4 Mod 66) = 0)
        Case ENUM_TP_DCS.DefaultAlphabet
            TotalMessages = (tp_ud.Length \ 266) - ((tp_ud.Length Mod 266) = 0)
    End Select

    Dim Result(TotalMessages) As String
    Dim tmpTP_UD As String
    Dim i As Integer
    TP_UDHI = 2 ^ 6
    Dim Reference As Integer = Rnd(1) * 65536
    '16bit Reference Number 'See 3GPP Document
    For i = 0 To TotalMessages
        Select Case tp_dcs
            Case ENUM_TP_DCS.UCS2
                tmpTP_UD = Mid(TP_UD, i * 66 * 4 + 1, 66 * 4)
                'When TP_UDL is odd, the max length of an Unicode string 
                'in PDU code is 66 Charactor.
                'See [3GPP TS 23.040 V6.5.0 (2004-09] 9.2.3.24.1
            Case ENUM_TP_DCS.DefaultAlphabet
                tmpTP_UD = Mid(tp_ud, i * 133 * 2 + 1, 133 * 2)
        End Select
        Result(i) = SC_Number
        Result(i) += FirstOctet()
        Result(i) += Format(TP_MR, "X2")
        Result(i) += TP_DA
        Result(i) += Format(TP_PID, "X2")
        Result(i) += Format(TP_DCS, "X2")
        Result(i) += Format(TP_VP, "X2")
        If tp_dcs = ENUM_TP_DCS.UCS2 Then
            TP_UDL = tmpTP_UD.Length / 2 + 6 + 1 '6:IE
        End If
        If tp_dcs = ENUM_TP_DCS.DefaultAlphabet Then
            TP_UDL = Fix((tmpTP_UD.Length + 7 * 2) * 4 / 7) '6:length of IE
        End If
        Result(i) += Format(TP_UDL, "X2")
        Result(i) += "060804" 'TP_UDHL and some of Concatenated message
        Result(i) += Format(Reference, "X4")
        Result(i) += Format(TotalMessages + 1, "X2")
        Result(i) += Format(i + 1, "X2")
        Result(i) += tmpTP_UD
    Next
Return Result

As you can see, the above code is similar to GetSMSPDUCode(). But you can also see TP_UDHI is set indicating that TP_UDH appears in TP_UD. Note TP_UDL is calculated during the loop process. As I mentioned in my source code, it also has problems treating TP_UDL while the TP_DCS is DefaultAlphabet. To get details on how EMS is created, please refer to 3GPP TS 23.040 V6.5.0.

Let us send an SMS!

I'm happy to show you that it's so easy to send an SMS to a certain number. In this demonstration, I'll show you how to get my account information using my PDU Encoder, Microsoft HyperTerminal and my PDU Decoder. My phone is Siemens M55, and note some AT commands may not work on your phone or GSM Modem.

First let's produce an SMS PDU Code. Start my program, and fill the Number, Options and User Data as shown in Figure 3. Then press "Get PDU Code" button to get PDU code and length for AT which will be used later. Press "Copy to Clipboard" to copy PDU Code to clipboard.

Image 4

Start HyperTerminal program. I give this session a name "Send SMS Demo" and I choose COM3 which is the port my phone is connected to. Then follow these instructions:

<CR> equals to Enter key of your keyboard.

Step 1: Type AT<CR> and ensure the device is ready.

Step 2: Type AT+CPMS="MT","MT","MT"<CR> to set preferred memory storage. Here I set it to Mobile Terminal.

Step 3: Type AT+CMGS=12<CR>. The number 12.

Step 4: Paste PDU code to HyperTerminal and press CTRL+Z to end the input. At this time your phone will send SMS to the number you specified. Here my destination number is 1861 from which I can get my account info.

Step 5: After a while I can see my phone receive a status report and my account info.

Step 6: Type AT+CMGL=1 to list the incoming message. Here it returns:

+CMGL: 1,1,,166
0891683108200805F0066104818116505013612455005050136124550000FFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
+CMGL: 2,1,,83
0891683108200805F00404A1811600085050136164350044672C67085DF24F7F75288BDD8D39003A
00350031002E00340037002052694F5998845B586B3E003A00350039002E0033003600204F1860E0
003A00370039002E00350031

Step 7: Use my PDU Decoder to decode above PDU codes. Note there're some Chinese characters.

SMS_STATUS_REPORT
Send time:2005-5-31 16:42:55 Receive time:2005-5-31 16:42:55 Status:Success
SMS_RECEIVED
From:1861 Time:2005-5-31 16:46:53
±¾ÔÂÒÑʹÓû°·Ñ:51.47 Ê£ÓàÔ¤´æ¿î:59.36 ÓÅ»Ý:79.51

You can see that it's an easy task to manually send and receive SMSs though my tools and HyperTerminal. Be glad to use them to ease your test work!

Reference

Note

You can use and modify my code freely. If you find some bugs or improve my code, please contact me. This will help me to fix bugs and also it will help a lot of people all over the world! Thanks for reading my article and thanks again for using my code!

Contact me

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
I'm a undergraduate student in UESTC in China.
I have being learing computer for more than ten years. And now studying programming and have some software made by myself.
I learned SMS technology and did some work on OBEX, PDU, AT commands, IrDA and so on.
If you have interested in this field, please contact me.
And see more on my web site: http://www.hesicong.net

Comments and Discussions

 
GeneralRe: How to Send a free SMS? Help Pin
aspdev34-Aug-05 20:15
aspdev34-Aug-05 20:15 
GeneralRe: How to Send a free SMS? Help Pin
hesicong5-Aug-05 3:12
hesicong5-Aug-05 3:12 
AnswerRe: How to Send a free SMS? Help Pin
Oslec17-Oct-05 19:02
Oslec17-Oct-05 19:02 
AnswerRe: How to Send a free SMS? Help Pin
xaml.net13-Jan-07 2:13
xaml.net13-Jan-07 2:13 
GeneralLink to &quot;GSM 03.40&quot; document is dead. Pin
janfe13-Jul-05 21:23
janfe13-Jul-05 21:23 
GeneralRe: Link to &quot;GSM 03.40&quot; document is dead. Pin
hesicong14-Jul-05 6:42
hesicong14-Jul-05 6:42 
GeneralRe: Link to &quot;GSM 03.40&quot; document is dead. Pin
janfe21-Jul-05 6:25
janfe21-Jul-05 6:25 
Generalpleasssee help me....!!!! Pin
Baktir26-Jul-05 8:38
Baktir26-Jul-05 8:38 
hai mr.hesicong, my name is zacky baktir, i'm come from
indonesia,n i'm newbie in programming,but i'm
interesting to learn more about programming,especially
using VB6. 1 weeks ago i have made sms aplication using
VB6 n the conection i used RS-232,n it works. i can send
n receive sms from PC using RS-232. n then i want to
develop my conection using GSM modem,i used iTegno 300
GSM modem that use USB as the conection.

in my VB6 application i have to change port n then
baudrate,but it\'s not working.is there any diffrence
between using RS-232 n USB,coz when i used RS232 i make
MSCOMM....may be u can help me by solving this problem,
coz i want to dedicated this aplication in my office
soon.

this my application when i used RS-232 as the connection
n then i chane to iTegno GSM modem using USB:

************formsms.frm*************
Public text1 As String

Private Sub Timer1_Timer()
Form1.Show
End Sub
************formsms.frm************

************module func_prop.bas******
Function BINER7(ByVal angka As Integer) As String
If angka > 1 Then
Dim I As Integer
Dim hasil(8) As Integer
Dim SISA(8) As Integer

I = 1
Do
hasil(I) = Int(angka / 2)
SISA(I) = angka Mod 2
angka = hasil(I)
I = I + 1
BINER7 = SISA(I - 1) & BINER7
Loop Until hasil(I - 1) < 2
BINER7 = hasil(I - 1) & BINER7
BINER7 = String$(7 - Len(BINER7), \"0\") & BINER7
ElseIf angka = 1 Then
BINER7 = \"0000001\"
ElseIf angka = 0 Then
BINER7 = \"0000000\"
End If
End Function

Function BINER4(ByVal angka As Integer) As String
If angka > 1 Then
Dim I As Integer
Dim hasil(5) As Integer
Dim SISA(5) As Integer

I = 1
Do
hasil(I) = Int(angka / 2)
SISA(I) = angka Mod 2
angka = hasil(I)
I = I + 1
BINER4 = SISA(I - 1) & BINER4
Loop Until hasil(I - 1) < 2
BINER4 = hasil(I - 1) & BINER4
BINER4 = String$(4 - Len(BINER4), \"0\") & BINER4
ElseIf angka = 1 Then
BINER4 = \"0001\"
ElseIf angka = 0 Then
BINER4 = \"0000\"
End If
End Function

Function DEBINER7(ByVal huruf As String) As Integer
Dim angka(8) As Integer

For I = 1 To 7
angka(I) = Val(Mid(huruf, I, 1))
DEBINER7 = DEBINER7 + angka(I) * 2 ^ (7 - I)
Next I

End Function
Function DEBINER4(ByVal huruf As String) As Integer
Dim angka(5) As Integer

For I = 1 To 4
angka(I) = Val(Mid(huruf, I, 1))
DEBINER4 = DEBINER4 + angka(I) * 2 ^ (4 - I)
Next I

End Function

Function TOOTH(ByVal karakter As String) As Integer
Dim pc As Integer

pc = Asc(karakter)

If pc = 64 Then
TOOTH = 0
ElseIf pc = 36 Then
TOOTH = 2
ElseIf pc = 223 Then
TOOTH = 30
ElseIf pc >= 32 And pc <= 35 Then
TOOTH = pc
ElseIf pc >= 37 And pc <= 63 Then
TOOTH = pc
ElseIf pc = 95 Then
TOOTH = 64
ElseIf pc >= 65 And pc <= 90 Then
TOOTH = pc
ElseIf pc = 196 Then
TOOTH = 91
ElseIf pc = 214 Then
TOOTH = 92
ElseIf pc = 220 Then
TOOTH = 94
ElseIf pc = 168 Then
TOOTH = 96
ElseIf pc >= 97 And pc <= 122 Then
TOOTH = pc
ElseIf pc = 228 Then
TOOTH = 123
ElseIf pc = 246 Then
TOOTH = 124
ElseIf pc = 252 Then
TOOTH = 126
End If

End Function

Function DETOOTH(ByVal pc As Integer) As String
Dim TOOTH As Integer

If pc = 0 Then
TOOTH = 64
ElseIf pc = 2 Then
TOOTH = 36
ElseIf pc = 30 Then
TOOTH = 223
ElseIf pc >= 32 And pc <= 35 Then
TOOTH = pc
ElseIf pc >= 37 And pc <= 63 Then
TOOTH = pc
ElseIf pc = 64 Then
TOOTH = 95
ElseIf pc >= 65 And pc <= 90 Then
TOOTH = pc
ElseIf pc = 91 Then
TOOTH = 196
ElseIf pc = 92 Then
TOOTH = 214
ElseIf pc = 94 Then
TOOTH = 220
ElseIf pc = 96 Then
TOOTH = 168
ElseIf pc >= 97 And pc <= 122 Then
TOOTH = pc
ElseIf pc = 123 Then
TOOTH = 228
ElseIf pc = 124 Then
TOOTH = 246
ElseIf pc = 126 Then
TOOTH = 252
End If

DETOOTH = Chr(TOOTH)
End Function


Function UbahIsi(ByVal strIsi As String) As String
Dim pj As Integer
Dim potongan() As String
Dim empatan() As String
Dim hasil() As String
Dim tamp As String

pj = Len(strIsi)

ReDim potongan(pj + 1)
ReDim empatan(pj + 1, 3)
ReDim hasil(pj + 1, 3)

tamp = String$(pj, \"0\")

For I = 1 To pj
tamp = tamp & BINER7(TOOTH(Mid(strIsi, pj - I +
1, 1)))
Next I

For I = pj To 1 Step -1
potongan(I) = Mid(tamp, (8 * (I - 1)) + 1, 8)
empatan(I, 1) = Mid(potongan(I), 1, 4)
empatan(I, 2) = Mid(potongan(I), 5, 4)
hasil(I, 1) = Hex$(DEBINER4(empatan(I, 1)))
hasil(I, 2) = Hex$(DEBINER4(empatan(I, 2)))
UbahIsi = UbahIsi & hasil(I, 1) & hasil(I, 2)
Next I

End Function
Function UbahNo(ByVal strNomor As String) As String
Dim pj As Integer
Dim tamp() As String
Dim hasil() As String

pj = Len(strNomor)

If pj Mod 2 = 1 Then strNomor = strNomor & \"F\"

pj = Len(strNomor)

ReDim tamp(pj / 2 + 1)
ReDim hasil(pj / 2 + 1, 3)

For I = 1 To pj / 2
tamp(I) = Mid(strNomor, (I - 1) * 2 + 1, 2)
hasil(I, 1) = Right(tamp(I), 1)
hasil(I, 2) = Left(tamp(I), 1)
UbahNo = UbahNo & hasil(I, 1) & hasil(I, 2)
Next I

End Function

Function balikinIsi(ByVal Isi As String) As String
Dim pj As Integer
Dim splits() As String
Dim tmp As String, tmp1 As String
Dim bnr() As String
Dim d7() As String
Dim i7() As Integer

pj = Len(Isi)
ReDim splits(pj / 2)
ReDim bnr(pj)


For I = 0 To pj / 2 - 1
splits(I) = balik(Mid(Isi, 2 * I + 1, 2))
tmp = tmp + splits(I)
Next I
tmp = StrReverse(tmp)

For I = 0 To pj - 1
bnr(I) = BINER4(antiHex(Mid(tmp, I + 1, 1)))
tmp1 = tmp1 & bnr(I)
Next I
tmp1 = Right(tmp1, pj / 2 * 7)

ReDim d7(Len(tmp1) / 7)
ReDim i7(Len(tmp1) / 7)

For I = 0 To Len(tmp1) / 7 - 1
d7(I) = Mid(tmp1, 7 * I + 1, 7)
i7(I) = DEBINER7(d7(I))
d7(I) = DETOOTH(i7(I))
balikinIsi = d7(I) & balikinIsi
Next I
End Function

Function balikinNo(ByVal strNo As String) As String
Dim pj As Integer
Dim splits() As String

pj = Len(strNo)
ReDim splits(pj / 2 - 1)

If Left(strNo, 1) = \"9\" Then
For I = 0 To pj / 2 - 2
splits(I) = balik(Mid(strNo, 2 * I + 3, 2))
balikinNo = balikinNo & splits(I)
balikinNo = Replace(balikinNo, \"F\", \"\")
Next I
Else
balikinNo = 62
For I = 0 To pj / 2 - 2

If I = 0 Then
splits(I) = Left((Mid(strNo, 2 * I + 3,
2)), 1)
Else
splits(I) = balik(Mid(strNo, 2 * I + 3,
2))
End If
balikinNo = balikinNo & splits(I)
balikinNo = Replace(balikinNo, \"F\", \"\")
Next I
End If
End Function

Function balikinDt(ByVal strDt As String) As String
Dim splits(6) As String
For I = 0 To 5
splits(I) = balik(Mid(strDt, 2 * I + 1, 2))
balikinDt = balikinDt & splits(I)
Next I
End Function


Function str2dt(ByVal strDt As String) As Date
Dim spl(6) As String
spl(0) = Mid(strDt, 3, 2)
spl(1) = Mid(strDt, 5, 2)
spl(2) = Mid(strDt, 1, 2)
spl(3) = Mid(strDt, 7, 2)
spl(4) = Mid(strDt, 9, 2)
spl(5) = Mid(strDt, 11, 2)
str2dt = CDate(spl(0) & \"/\" & spl(1) & \"/\" & spl(2)
& \" \" & _
spl(3) & \":\" & spl(4) & \":\" & spl(5))
End Function

Function balik(ByVal strDuo As String) As String
balik = Right(strDuo, 1) & Left(strDuo, 1)
End Function

Function lng2hex(ByVal lngBil As Long) As String
lng2hex = Hex$(lngBil)
If Len(lng2hex) = 1 Then
lng2hex = \"0\" & lng2hex
End If
End Function

Function hex2lng(ByVal strHex As String) As Long
Dim strH(2) As String
Dim intL(2) As Integer

strH(0) = Left(strHex, 1)
strH(1) = Right(strHex, 1)

For I = 0 To 1
If Asc(strH(I)) >= 48 And Asc(strH(I)) <= 57
Then
intL(I) = Asc(strH(I)) - 48
ElseIf Asc(strH(I)) >= 65 And Asc(strH(I)) <= 70
Then
intL(I) = Asc(strH(I)) - 55
End If
Next I

hex2lng = 16 * intL(0) + intL(1)
End Function

Function antiHex(ByVal strHex As String) As Integer
If Asc(strHex) >= 48 And Asc(strHex) <= 57 Then
antiHex = Asc(strHex) - 48
ElseIf Asc(strHex) >= 65 And Asc(strHex) <= 70 Then
antiHex = Asc(strHex) - 55
End If
End Function
*******************module func_prop.bas********

*******************module terima.bas********
Function terima() As String

Dim LISTING(2) As String
Dim splits() As String

Dim no() As String
Dim pdu() As String
Dim no1() As String
Dim no2() As String
Dim tmpdu() As String
Dim intPdu() As Integer
Dim Balas As String
Dim waktu As Date

Dim con As Object
Dim rs As Object
Dim sSQL As String

Dim mscomm2 As Object
Set mscomm2 = CreateObject(\"MSCOMMLIB.MSCOMM\")

terima = \"\"

With mscomm2

On Error GoTo err_handler

.CommPort = 4 \'itegno detect COM 4
.Settings = \"115200,N,8,1\" \'baudrate of itegno
max 115200
.InputLen = 0
.PortOpen = True

waktu = Now

Do
.Output = \"ATE1\" & Chr$(13)
Do
DoEvents
buffer$ = buffer$ & .Input
Loop Until InStr(buffer$, \"OK\") Or
InStr(buffer$, \"ERROR\") Or Now > DateAdd(\"s\", 10, waktu)
Loop Until InStr(buffer$, \"OK\") Or Now >
DateAdd(\"s\", 10, waktu)

If InStr(buffer$, \"OK\") Then
Set con = CreateObject(\"ADODB.Connection\")
Set rs = CreateObject(\"ADODB.Recordset\")
\'Set rs5 = CreateObject(\"ADODB.Recordset\")
con.Open \"ODBC_SMS_DATA\", \"\", \"\"
sSQL = \"SELECT * FROM tblTerima\"
rs.Open sSQL, con, 1, 3
\'sSQL5 = \"SELECT * FROM tblBalas\"
\'rs5.Open sSQL5, con, 1, 3

For j = 0 To 1
buffer1$ = \"\"
buffer4$ = \"\"
Do
.Output = \"AT+CMGL=\" & j & Chr$(13)
Do
DoEvents
buffer1$ = buffer1$ & .Input
Loop Until InStr(buffer1$, \"OK\") Or
InStr(buffer1$, \"ERROR\")
Loop Until InStr(buffer1$, \"OK\")

LISTING(j) = buffer1$
splits() = Split(LISTING(j), Chr$(13), ,
vbTextCompare)
If UBound(splits()) < 5 Then
Jum_terima = Jum_terima
Else
jum = (UBound(splits()) - 4) / 2
Jum_terima = Jum_terima + jum

ReDim no(jum + 1)
ReDim pdu(jum + 1)
ReDim tmpdu(jum + 1, 3)
ReDim intPdu(jum + 1, 3)

For I = 1 To jum
no(I) = splits(I * 2)
pdu(I) = splits(I * 2 + 1)
Next I

For I = 1 To jum
no1() = Split(no(I), \" \", ,
vbTextCompare)
no(I) = no1(1)
Next I

For I = 1 To jum
no2() = Split(no(I), \",\", ,
vbTextCompare)
no(I) = no2(0)
Next I

For I = 1 To jum
Do
.Output = \"AT+CMGD=\" & no(I)
& Chr$(13)
Do
DoEvents
buffer4$ = buffer4$ & .Input
Loop Until InStr(buffer4$,
\"OK\") Or InStr(buffer4$, \"ERROR\")
Loop Until InStr(buffer4$, \"OK\")
Next I

For I = 1 To jum
intPdu(I, 0) = 5 + 2 *
hex2lng(Mid(pdu(I), 2, 2)) \'1 + pj + smsc + 04
intPdu(I, 1) = 4 +
hex2lng(Mid(pdu(I), intPdu(I, 0) + 1, 2)) \'pj + 91/81 +
dari
If intPdu(I, 1) Mod 2 = 1 Then
intPdu(I, 1) = intPdu(I, 1) + 1 \'gjl jd gnp
tmpdu(I, 0) = Mid(pdu(I),
intPdu(I, 0) + 3, intPdu(I, 1) - 2) \'91/81 + dari
tmpdu(I, 1) = Mid(pdu(I),
intPdu(I, 0) + intPdu(I, 1) + 5, 12) \'waktu
intPdu(I, 2) =
hex2lng(Mid(pdu(I), intPdu(I, 0) + intPdu(I, 1) + 19, 2)
) \'pj isi
tmpdu(I, 2) = Mid(pdu(I),
intPdu(I, 0) + intPdu(I, 1) + 21, Len(pdu(I)) -
intPdu(I, 0) - intPdu(I, 1) - 20)
If Len(tmpdu(I, 2)) < intPdu(I,
2) * 2 Then
tmpdu(I, 2) = tmpdu(I, 2) &
String$((intPdu(I, 2) * 2 - Len(tmpdu(I, 2))), \"0\")
End If
Next I

For I = 1 To jum
Kpd = balikinNo(tmpdu(I, 0))
Jam_Pesan =
str2dt(balikinDt(tmpdu(I, 1)))
Isi_Berita =
UCase(balikinIsi(tmpdu(I, 2)))
\'Balas = VBalas(Kpd, Jam_Pesan,
Trim(Isi_Berita))
Form1.Show
\'catat isi SMS terima dalam
tabel TblTerima
rs.AddNew
rs(1).Value = no(I)
rs(2).Value = Kpd
rs(3).Value = Jam_Pesan
rs(4).Value = Isi_Berita
rs.Update
Next I
End If
Next j

rs.Close
Set rs = Nothing
con.Close
End If
.PortOpen = False
Set mscomm2 = Nothing
End With
err_handler:
If Err.Number = 8005 Or Err.Number = 8002 Then
Set mscomm2 = Nothing
Exit Function
End If
End Function

*******************module terima.bas********
*******************module main_prop.bas********

Sub Main()
Dim text1 As String
Dim intJml As Integer
Dim objSMS As Object
On Error GoTo err_handler
Dim Isi_Pesan As String
Dim Kpd As String

Form1.Show

Isi_Pesan = terima()

err_handler:
If Err.Number = 0 Then
End
End If
End
End Sub
**********************module main_prop.bas********

is there any diffrence between using RS-232 n USB,coz
when test the itegno GSM modem that using USB, from
hyperterminal it detect n it can work.but when i put in
my application the GSM modem not response when received
SMS,i mean the sms is not move to the database like
ussualy i get when i\'m using RS-232.

pleasse help mr.hesicong...i\'m waiting for your reply...
.thanks for your attention reading this mail....thank u.
..

i hope in this forum i can develop my programming knowledge
GeneralRe: pleasssee help me....!!!! Pin
hesicong26-Jul-05 17:51
hesicong26-Jul-05 17:51 
GeneralRe: pleasssee help me....!!!! Pin
Member 30541153-Mar-10 6:37
Member 30541153-Mar-10 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.