In this example, will present the way how making SMS delivery program with Delphi, basically, data in data communication series between Delphi and mobile phone happen in Format Protocol Data Unit (PDU). The destination number of sending Message and message that will be sent through Delphi program that is made have to be changed into PDU Form first, next is the data will be sent through serial port to mobile phone.
To make the send SMS Application , please enter the following component to Form 1.
No | Component Name | Properties | Value |
Button1 | Caption | Connect | |
Button2 | Caption | DisConnect | |
Button3 | Caption | Convert to PDU | |
Button4 | Caption | Send to HP | |
Button5 | Caption | Clear | |
Button6 | Caption | Start Send SMS | |
Button7 | Caption | Set Port | |
Edit1 | Text | - | |
Edit2 | Text | <Type The SMS here> | |
Edit3 | Text | - | |
Label1 | Caption | 1) Destination Number : | |
Label2 | Caption | 2 | |
Label3 | Caption | PDU length | |
Label4 | Caption | Label length | |
ComLed1 | - | - | |
Memo1 | - | - | |
Memo2 | - | - | |
Comport1 | - | - |
Then type the following source code:
No | Component | Event | Source Code |
1 | Button1 | OnClick | ComPort1.Open; |
2 | Button2 | OnClick | ComPort1.Close; |
3 | Button3 | OnClick | var tujuan, isi :string; begin isi := Edit3.Text; tujuan := Edit2.Text; PDU := ConvertText(IM3smsc,'','',tujuan,'','','',isi); PDU := PDU+#$1A; memo1.Text := PDU; Label4.Caption := inttostr(lkirim-1); |
4 | Button4 | OnClick | var str : string; begin str := Edit1.Text+#13#10; Comport1.WriteStr(str); |
5 | Button5 | OnClick | Memo1.Clear; Memo2.Clear; |
6 | Button6 | OnClick | var str : string; begin str := PDU+#13#10; Comport1.WriteStr(str); end; |
7 | Button7 | OnClick | comport1.ShowSetupDialog; |
8 | Comport1 | OnRxChar | var str : string; begin Comport1.ReadStr(str,Count); Memo2.Text := Memo2.Text + str; |
IMPORTANT Don’t forget to : Add the variable below in upper implementation PDU : string; type the code below in under implementation const sOK = 'OK'; sERROR = 'ERROR'; ProXLsmsc ='62818445009'; Simpatismsc ='6281100000'; Mentarismsc ='62816124'; IM3smsc ='62855000000'; var lkirim : integer; function text2PDU(text:string):string; var PDU : string; geser,panjang,tmp,tmp2,tmp3,n:byte; begin PDU :=''; panjang :=length(text); PDU :=PDU+inttohex(panjang,2); geser :=0; for n :=1 to panjang-1 do begin tmp2 :=ord(text[n]); if geser<>0 then tmp2 :=tmp2 shr geser; tmp :=ord(text[n+1]); if geser=7 then begin geser :=0; end else begin tmp3 :=8-(geser+1); //zero_020988@yahoo.co.id if tmp3<>0 then tmp:=tmp shl tmp3; PDU :=PDU+inttohex((tmp or tmp2),2); inc(geser); end; end; if geser<7 then begin tmp2:=ord(text[panjang]); if(geser<>0)then tmp2:=tmp2 shr geser; PDU:=PDU+inttohex(tmp2,2); end; result:=PDU; end; function ConvertText(smsc,tipe,ref,tujuan,bentuk,skema, validitas,isi:string):string; var PDU,tmp :string; p, i :byte; begin PDU := ''; If length(smsc)=0 then begin result :=''; exit; end; if length(tipe)=0 then tipe :='11'; if length(ref)=0 then ref :='00'; if length(bentuk)=0 then bentuk :='00'; if length(skema)=0 then skema :='00'; if length(validitas)=0 then validitas :='FF'; If length(isi)=0 then begin result :=''; exit; end; if smsc[1]='0' then tmp :='81'+smsc else tmp :='91'+smsc; if(length(tmp)mod 2)<>0 then tmp :=tmp+'F'; p := length(tmp); PDU :=PDU + inttohex(p div 2,2) + tmp[1] + tmp[2]; for i:= 2 to length(tmp)div 2 do begin PDU :=PDU+tmp[i*2]; PDU :=PDU+tmp[(i*2)-1]; end; PDU :=PDU+tipe; PDU :=PDU+ref; if tujuan[1]='+' then tujuan:=copy(tujuan,2,length(tujuan)-1); PDU :=PDU+inttohex(length(tujuan),2); if(length(tujuan)mod 2)<>0 then tujuan:=tujuan+'F'; if tujuan[1]='0' then PDU :=PDU+'81' else begin PDU :=PDU+'91'; end; for i :=1 to length(tujuan)div 2 do begin PDU :=PDU+tujuan[i*2]; PDU :=PDU+tujuan[(i*2)-1]; end; PDU :=PDU+bentuk; PDU :=PDU+skema; PDU :=PDU+validitas; tmp := Text2PDU(isi); PDU :=PDU+tmp; i := length(tmp); lkirim := (length(PDU) - p) div 2; result :=PDU; end; |
This is the result of application execution:
Reference :
www.bengkelprogram.com
Septian Herlan Permana (Yogyakarta State University)
I hope this article can give benefit to the visitors, readers, developer and me. Thanks for visiting and availability for sharing this article by pressing
Share this on Facebook |