Professional Documents
Culture Documents
5. Setelah komponen terinstall, tutup Delphi dan Save Project, klik Yes.
8. Pilih properti BaudRate, DeviceName, dan FlowControl sesuai dengan piranti yang
digunakan. Untuk Siemens pilih BaudRate br19200 dan FlowControl None, untuk
DeviceName pilih sesuai port komputer yang anda gunakan, misalnya COM1.
9. Tambahkan komponen Button dan Memo ke dalam Form1. Ubah properti Caption dari
Button1 menjadi Connect.
10. Sebelumnya pastikan untuk melengkapi nama unit yang digunakan pada bagian uses.
Unit yang belum secara otomatis ditambahkan adalah DateUtils.
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, XComDrv, DateUtils;
11. Tambahkan juga variable global yang akan digunakan yaitu Buffer bertipe WideString
dan ReadyState bertipe Boolean.
var
Form1: TForm1;
Buffer: WideString;
ReadyState: Boolean;
12. Kemudian klik dua kali pada Button1, tambahkan kode program berikut pada
procedure TForm1.Button1Click :
procedure TForm1.Button1Click(Sender: TObject);
var
waktu: TDateTime;
begin
XComm1.OpenDevice;
ReadyState := False;
Buffer := '';
waktu := now;
XComm1.SendString('ATE1'#13);
while (Not ReadyState) and (SecondsBetween(waktu, Now) < 10)
do Application.ProcessMessages;
Memo1.Text := Buffer;
if Pos('OK',Buffer) > 0 then
ShowMessage('Koneksi Berhasil');
end;
13. Tampilkan jendela Object Inspector pada Tab Events, klik dua kali pada Event
OnData dan tambahkan pada kode program berikut pada procedure
TForm1.XComm1Data :
begin
XComm1.ReadString(data);
Buffer := Buffer + data;
if (not ReadyState) and (Pos(#13#10'OK', Buffer) > 0) then
begin
ReadyState := True;
end;
end;
14. Klik menu Run-Run untuk menjalankan program, kemudian coba klik Button1 :
15. Tambahkan dua buah Button, ubah Caption-nya menjadi Read SMS dan Delete
SMS :
16. Klik dua kali pada Button2 (Read SMS) , tambahkan kode program berikut pada
procedure TForm1.Button2Click :
procedure TForm1.Button2Click(Sender: TObject);
var
waktu: TDateTime;
begin
ReadyState := False;
Buffer := '';
waktu := now;
XComm1.SendString('AT+CPMS=MT'#13);
while (Not ReadyState) and (SecondsBetween(waktu, Now) < 10)
do Application.ProcessMessages;
Memo1.Text := Buffer;
ReadyState := False;
Buffer := '';
waktu := now;
XComm1.SendString('AT+CMGL=4'#13);
while (Not ReadyState) and (SecondsBetween(waktu, Now) < 10)
do Application.ProcessMessages;
Memo1.Lines.Append(Buffer);
end;
17. Klik menu Run-Run untuk menjalankan program, kemudian coba klik Button2
(Read SMS), terlihat isi SMS-SMS yang ada pada piranti dengan format AT Command
dan PDU :
18. Klik dua kali pada Button3 (Delete SMS) , tambahkan kode program berikut pada
procedure TForm1.Button3Click :
procedure TForm1.Button3Click(Sender: TObject);
var
waktu: TDateTime;
begin
ReadyState := False;
Buffer := '';
waktu := now;
XComm1.SendString('AT+CMGD=1'#13);
while (Not ReadyState) and (SecondsBetween(waktu, Now) < 10)
do Application.ProcessMessages;
Memo1.Text := Buffer;
end;
19. Klik menu Run-Run untuk menjalankan program, kemudian coba klik Button3 :
20. Setelah SMS nomor 1 terhapus, jika Button2 (Read SMS) diklik lagi maka tampak
SMS teratas telah hilang :
COMPORT
procedure listSMS(var Memo: tMemo);
var
smsc, tipe, pengirim, bentuk, skema, tanggal, batas, isi, nomer, s,str : string;
n : textfile;
waktu: TDateTime;
i : integer;
begin
assignfile(n,'sms.txt');
rewrite(n);
for i := 0 to 1 do begin
comport.WriteStr( 'AT+CMGL=' + IntToStr(i) + #13);
waktu := now;
repeat
comport.ReadStr(str,comport.inputcount);
s := str;
write(n, s);
until (pos('OK', s) > 0) or (pos('ERROR', s) > 0) or (SecondsBetween(waktu,now) >
180);
end;
closefile(n);
reset(n);
readln(n, s);
while (not eof(n)) do begin
readln(n, s);
if copy(s, 1, 7) = '+CMGL: ' then begin
nomer := copy(s, 8, pos(',', s) - 8);
comport.WriteStr( 'AT+CMGD=' + nomer + #13);
waktu := now;
repeat
comport.ReadStr(str,comport.inputcount);
s := str;
.. .. CP.OnRxChar :
Quote:
procedure TForm1.CPRxChar(Sender: TObject; Count: Integer);