Arsip: Scanning data SMS dr serial


by tofix in Sistem more 12 years ago 4049
hi para delphi'ers sy mo tanya. gini nih..
sy sdg tugas akhir ttg komunikasi data : identifiksi SMS dr HP yg trkoneksi pd port sial. Utk smntara sy udh berhsil (prog trlampir) utk identifiks nomer sms,yaitu nmr 1 (dgn bantuan perintah "copy(s,x,y)" dr data sms). shg (dlm program itu), jika ada SMS baru (blm dibc) pd inbox (otomtis no 1), mk lakukan sesuatu (nantinya utk 'gerakin motor',utk smntr hny 'Show msg').
SAYA INGIN PROGRAM TERUS BERJALAN,DAN SANNING DATA SMS TERUS, SHG JK ADA SMS BARU LGSG DIIDENTIFIKASI. (utk smntara sy pake tombol utk jlnkan Procedure CekSMS)

jd intinya algoritma programnya adl:

1.kirim AT+CMGL=0 //utk minta list SMS yg blm dbc,jk "button Aktif" ditkn
2.baca SMS
3.Samakan nomor SMS //utk cr sms nmr 1
4.jk SAMA mk 'show msg' OPEN
5.AT+CMGD=1 //hapus SMS nmr 1
6.Ulangi keatas "step 1"//ini INTI MASALAHNYA pengulangan tanpa tekan "buton aktif " lagi,jd sistem aktif Forever gituh..

dlm Program ini sy pake komponen TComport thx atas bantuanyya...




  unit Unit1;
  
  interface
  
  uses
  Windows, Messages, SysUtils, DateUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CPort, ExtCtrls;
  
  type
  TForm1 = class(TForm)
  CP: TComPort;
  Button1: TButton;
  Button2: TButton;
  ED: TEdit;
  MM: TMemo;
  
  procedure Button1Click(Sender: TObject);
  procedure CPRxChar(Sender: TObject; Count: Integer);
  procedure Button2Click(Sender: TObject);
  
  
  private
  { Private declarations }
  public
  { Public declarations }
  procedure CekSMS(var MM: tMemo); // dilewatkan ke tmemo
  end;
  
  
  const sOK =#13#10'OK';
  sERROR =#13#10'ERROR';
  
  var
  Form1: TForm1;
  
  implementation
  
  {$R *.dfm}
  
  
  procedure TForm1.CekSMS(var MM: tMemo);
  var
  
  nosms,s, str: string;
  n, m : textfile;
  wkt: TDateTime;
  i : integer;
  begin
  assignfile(n, 'data1.txt');  //data1 at comand
  rewrite(n);
  
  for i := 0 to 1 do
  begin
  CP.WriteStr('AT+CMGL=' + IntToStr(i)+#13);
  wkt := Now;
  repeat
  CP.ReadStr(str,CP.InputCount);
  s := str;
  write(n, s);
  until (pos('OK', s) > 0) or (pos('ERROR', s) > 0) or (SecondsBetween(wkt,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
  nosms := copy(s, 8, pos(',',s)-8); //hanya copy no sms,utk isi sms
  assignfile(m,'data2.txt');   //data2 utk nosms,dan isi
  rewrite(m);
  
  
  wkt := Now;
  write(m, nosms);
  CloseFile(m);
  
  if nosms = '1'  then
  begin
  ShowMessage('OPEN');
  end else
  begin
  ShowMessage('dont care');
  end;
  
  CP.WriteStr('AT+CMGD=' + nosms +#13);//hpusno sms =1
  repeat
  CP.ReadStr(str,CP.InputCount);
  s := str;
  
  until (pos('OK', s) > 0) or (pos('ERROR', s) > 0) or (SecondsBetween(wkt,now) > 180);
  
  end;
  end;
  CloseFile(n);
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  var Str: String;
  begin
  if ED.Text = '' then
  begin
  ShowMessage('Command harus diisikan');
  exit;
  end;
  Str := ED.Text +#13#10;
  CP.WriteStr(Str);
  end;
  procedure TForm1.CPRxChar(Sender: TObject; Count: Integer);
  var Str: String;
  begin
  CP.ReadStr(Str, Count);
  MM.Text := MM.Text + Str;
  end;
  
  
  
  procedure TForm1.Button2Click(Sender: TObject);
  begin
  CekSMS(MM);
  end;
  
  end.
  
  
  
  
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com