The main component that is used in making the application is Comport. This component is used to get Brand, Type, IMEI, Operator Network, and Service Center through Serial Communication. Then the data that is gained through serial communication is processed to be visualized in MEMO components.
The component below is needed in making application to get information on Mobile Phone: Brand, Type, IMEI, Operator Network, and Service Center using Delphi.
Insert this following component to the design form area
No | Component Name | Properties | Value |
1 | Label1 | Caption | Merk |
2 | Label2 | Caption | Type |
3 | Label3 | Caption | IMEI |
4 | Label4 | Caption | Network Operator |
5 | Label5 | Caption | Service Center |
6 | Label6 | Caption | Access Hand Phone Information : Merk, Type, IMEI, Networ Operator, Service Center With Delphi |
7 | Memo1 | Lines | Memo1 |
8 | Memo2 | Lines | Memo2 |
9 | Memo3 | Lines | Memo3 |
10 | Memo4 | Lines | Memo4 |
11 | Memo5 | Lines | Memo5 |
12 | Button1 | Caption | Get Mobile Phone Information |
13 | Button2 | Caption | Set Serial Port |
Arrange the components into this picture below:
Serial Communication Delphi-Comport>Delphi Access SMS :Getting information on mobile phone: Brand, Type, IMEI, Operator Network, Service Center using Delphi (Part 2 : Variable, Function and the Procedure)
Before writing the source code to connect Personal Computer and Mobile Phone, and also source code to get mobile phone information, declare the global variable as follows:
tanda_receive,BatasStr,tanda_thistime,tanda_motion: string;
item: Tstrings;
ReceiveText: WideString;
ReadyState,koneksi,tanda_info,sms_sign: Boolean;
add a Constantan:
const
sOK = #13#10'OK';
After that make some Private Function and Procedure to access mobile phone information, Before make it, function and procedure have to be declared first as follows:
Then type function and procedure as follows:
No | Name | Source code |
1 | function TForm1.SendGetData(Teks, Batas: String): String; | function TForm1.SendGetData(Teks, Batas: String): String; var waktu: TDateTime; begin ReadyState := False; BatasStr := Batas; ReceiveText := ''; waktu := now; comport1.WriteStr(Teks); while (Not ReadyState) and (SecondsBetween(waktu, Now) < 10) do Application.ProcessMessages; Result := ReceiveText; end; |
2 | function Tform1.Cek_koneksi; | function Tform1.Cek_koneksi; var s:string; begin s:=SendGetData('ATE1'+#13, sOK); if pos(sOK,s)>0 then koneksi:=true else koneksi:=false; Result := pos(sOK, s) > 0; end; |
3 | procedure TForm1.getInfo; | procedure TForm1.getInfo; var c: string; begin if Pos('AT+CGMI', ReceiveText) > 0 then begin c:=copy(Receivetext,pos('AT+ CGMI',ReceiveText)+10,length(ReceiveText)); memo1.Text:=c; end; if Pos('AT+GMM', ReceiveText) > 0 then begin c:=copy(Receivetext,pos('AT+GMM', ReceiveText)+9,length(ReceiveText)); memo2.Text:=c; end; if Pos('AT+CGSN', ReceiveText) > 0 then begin c:=copy(Receivetext,pos('AT+CGSN', ReceiveText)+10,length(ReceiveText)); memo3.Text:=c; end; if Pos('+COPS:', ReceiveText) > 0 then begin c := copy(ReceiveText, pos('+COPS:', ReceiveText) + 7, length(ReceiveText)); memo4.Text:=c; end; if Pos('+CSCA:', ReceiveText) > 0 then begin c := copy(ReceiveText, pos('+CSCA:', ReceiveText) + 7, length(ReceiveText)); memo5.Text:=c; tanda_receive:='OK'; end; end; |
Serial Communication Delphi-Comport>Delphi Access SMS :Getting information on mobile phone: Brand, Type, IMEI, Operator Network, Service Center using Delphi(Part 4: the source code)
Check all source code so that become as follows:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CPortCtl, ComCtrls, ExtCtrls, Buttons, CPort,DateUtils,StrUtils;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
ComPort1: TComPort;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Memo4: TMemo;
Memo5: TMemo;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComPort1RxChar(Sender: TObject; Count: Integer);
private
function SendGetData(Teks, Batas: String): String;
function Cek_koneksi: Boolean;
procedure getInfo(buffer: string);
{ Private declarations }
public
{ Public declarations }
end;
const
sOK = #13#10'OK';
var
Form1: TForm1;
tanda_receive,BatasStr,tanda_thistime,tanda_motion: string;
item: Tstrings;
ReceiveText: WideString;
ReadyState,koneksi,tanda_info,sms_sign: Boolean;
implementation
{$R *.dfm}
function TrimAll(t: string): string;
var s: string;
begin
s := trim(t);
s := copy(s, 2, length(s) - 2);
result := s;
end;
function TForm1.SendGetData(Teks, Batas: String): String;
var
waktu: TDateTime;
begin
ReadyState := False;
BatasStr := Batas;
ReceiveText := '';
waktu := now;
comport1.WriteStr(Teks);
while (Not ReadyState) and (SecondsBetween(waktu, Now) < 10)
do Application.ProcessMessages;
Result := ReceiveText;
end;
function Tform1.Cek_koneksi;
var s:string;
begin
s:=SendGetData('ATE1'+#13, sOK);
if pos(sOK,s)>0 then koneksi:=true
else koneksi:=false;
Result := pos(sOK, s) > 0;
end;
procedure TForm1.getInfo;
var
c: string;
begin
if Pos('AT+CGMI', ReceiveText) > 0 then
begin
c:=copy(Receivetext,pos('AT+CGMI',ReceiveText)+10,length(ReceiveText));
memo1.Text:=c;
end;
if Pos('AT+GMM', ReceiveText) > 0 then begin
c:=copy(Receivetext,pos('AT+GMM',ReceiveText)+9,length(ReceiveText));
memo2.Text:=c;
end;
if Pos('AT+CGSN', ReceiveText) > 0 then begin
c:=copy(Receivetext,pos('AT+CGSN',ReceiveText)+10,length(ReceiveText));
memo3.Text:=c;
end;
if Pos('+COPS:', ReceiveText) > 0 then begin
c := copy(ReceiveText, pos('+COPS:', ReceiveText) + 7, length(ReceiveText));
memo4.Text:=c;
end;
if Pos('+CSCA:', ReceiveText) > 0 then begin
c := copy(ReceiveText, pos('+CSCA:', ReceiveText) + 7, length(ReceiveText));
memo5.Text:=c;
tanda_receive:='OK';
end;
end;
procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var Str: String;
begin
comport1.ReadStr(Str, Count);
ReceiveText := ReceiveText + Str;
If (Not ReadyState) And (Pos(BatasStr, ReceiveText) > 0) Then Begin
ReadyState := True;
End;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if comport1.Connected then
begin
if cek_koneksi then
begin
//listview1.Clear;
getinfo(SendGetData('AT+CGMI'+#13, sOK));
getinfo(SendGetData('AT+GMM'+#13, sOK));
getinfo(SendGetData('AT+CGSN'+#13, sOK));
getinfo(SendGetData('AT+COPS?'+#13, sOK));
getinfo(SendGetData('AT+CSCA?'+#13, sOK));
SendGetData('AT+CMGf=0'+#13, sOK);
SendGetData('AT+CSMS=0'+#13, sOK);
tanda_info:=true;
end
else
begin
ShowMessage('Failed to Connect');
tanda_info:=false;
end;
end
else
begin
MessageDlg('Setting Serial First !!!',mtinformation, [mbYes],0);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if comport1.Connected then
comport1.Connected:=false;
comport1.ShowSetupDialog;
comport1.Connected:=true;
end;
end.
Execute the application that is made then manage the port connection by pressing set serial button, connect the mobile phone and PC through serial port or USB port, connect by Get Mobile Phone Information button so that the program visualization will be as follows:
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 |