使用 Delphi 對手機(jī)通訊的編程
發(fā)布時間:2008-10-05 閱讀數(shù): 次 來源:網(wǎng)樂原科技
希望對喜歡編程的朋友有幫助,最近在整理所有手機(jī)的編程,可能會出一書,交廣州華瑩出版。
unit PanasonicGD;
interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, RXClock, ExtCtrls, RXCtrls, Gauges, OoMisc, AdPort, DsFancyButton;
type TPanasonicGD92 = class(TForm)
SoftwareTitle: TRxLabel;
ComPortItem: TPanel;
PhoneInfo: TPanel;
ComPort1: TRadioButton;
ComPort2: TRadioButton;
ComPort3: TRadioButton;
ComPort4: TRadioButton;
Com1Port: TRxLabel;
Com2Port: TRxLabel;
Com3Port: TRxLabel;
Com4Port: TRxLabel;
RealClock: TRxClock;
Autohor: TRxLabel;
SoftwareVersion: TRxLabel;
PhoneIMEI: TRxLabel;
GD92SW: TEdit;
GD92IMEI: TEdit;
JobItem: TPanel;
ProcessInfo: TPanel;
PhoneLockCode: TRxLabel;
GD92CODE: TEdit;
ProcessBar: TGauge;
PromptInfo: TPanel;
UserInfo: TLabel;
ComPort: TApdComPort;
ExitProgram: TDsFancyButton;
TestMode: TDsFancyButton;
ReadInfo: TDsFancyButton;
Chinese: TDsFancyButton;
ExitTestMode: TDsFancyButton;
function GetCOMData(Count: integer): string;
procedure ExitProgramClick(Sender: TObject);
procedure TestModeClick(Sender: TObject);
procedure ComPortTriggerAvail(CP: TObject; Count: word); procedure ChineseClick(Sender: TObject);
procedure ExitTestModeClick(Sender: TObject);
procedure ReadInfoClick(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var PanasonicGD92: TPanasonicGD92;
ResponseArray: array[1..300] of string;
Step: integer;
PanaGD9xIMEI: string;
PanaGD9xCode: string;
PanaGD9xSW: string;
DoStop: boolean;
implementation
{$R *.DFM}
function TPanasonicGD92.GetCOMData(Count: integer): string;
var I: integer;begin
Result := ';
for I := 1 to Count do
Result := Result + IntToHex(byte(ComPort.GetChar), 02);
end;
procedure TPanasonicGD92.ExitProgramClick(Sender: TObject);
begin
Close;
end;
procedure TPanasonicGD92.TestModeClick(Sender: TObject);
begin
if TestMode.Caption = 'Stop Jobs' then
DoStop := True else
begin
TestMode.Caption := 'Stop Jobs';
Step := 1;
if ComPort1.Checked then
ComPort.ComNumber := 1;
if ComPort2.Checked then
ComPort.ComNumber := 2;
if ComPort3.Checked then
ComPort.ComNumber := 3;
if ComPort4.Checked then
ComPort.ComNumber := 4;
UserInfo.Caption := 'Press Phone Power On Key ...'; ResponseArray[Step] := '00';
while Step = 1 do begin Application.ProcessMessages;
if DoStop then
begin
TestMode.Caption := 'Test Mode';
Exit;
end;
end;
ProcessBar.Progress := 0;
ReadInfo.Enabled := True;
Chinese.Enabled := True;
ExitTestMode.Enabled := True;
UserInfo.Caption := 'Phone Test Mode OK !';
end;
end;
procedure TPanasonicGD92.ChineseClick(Sender: TObject);
begin
Step := 5;
ProcessBar.ForeColor := clLime;
ResponseArray[Step] := '00800110';
ComPort.PutChar(#$00);
ProcessBar.Progress := 4;
ComPort.PutChar(#$80);
ProcessBar.Progress := 8;
ComPort.PutChar(#$02);
ProcessBar.Progress := 12;
ComPort.PutChar(#$E2);
ProcessBar.Progress := 15;
ComPort.PutChar(#$00);
ProcessBar.Progress := 19;
while Step = 5 do begin Application.ProcessMessages;
if DoStop then Exit;
end;
Step := 6;
ResponseArray[Step] := '00800110';
ComPort.PutChar(#$00);
ProcessBar.Progress := 23;
ComPort.PutChar(#$80);
ProcessBar.Progress := 27;
ComPort.PutChar(#$03);
ProcessBar.Progress := 31;
ComPort.PutChar(#$9A);
ProcessBar.Progress := 35;
ComPort.PutChar(#$00);
ProcessBar.Progress := 38;
ComPort.PutChar(#$FF);
ProcessBar.Progress := 42;
while Step = 6 do begin
Application.ProcessMessages;
if DoStop then Exit;
end;
Step := 7;
ResponseArray[Step] := '00800110';
ComPort.PutChar(#$00);
ProcessBar.Progress := 46;
ComPort.PutChar(#$80);
ProcessBar.Progress := 50;
ComPort.PutChar(#$0B);
ProcessBar.Progress := 54;
ComPort.PutChar(#$CB);
ProcessBar.Progress := 58;
ComPort.PutChar(#$02);
ProcessBar.Progress := 62;
ComPort.PutChar(#$00);
ProcessBar.Progress := 65;
ComPort.PutChar(#$00);
ProcessBar.Progress := 69;
ComPort.PutChar(#$00);
ProcessBar.Progress := 73;
ComPort.PutChar(#$00);
ProcessBar.Progress := 77;
ComPort.PutChar(#$07);
ProcessBar.Progress := 81;
ComPort.PutChar(#$00);
ProcessBar.Progress := 85;
ComPort.PutChar(#$00);
ProcessBar.Progress := 88;
ComPort.PutChar(#$00);
ProcessBar.Progress := 92;
ComPort.PutChar(#$00);
ProcessBar.Progress := 96;
ComPort.PutChar(#$00);
ProcessBar.Progress := 100;
while Step = 7 do
begin
Application.ProcessMessages;
if DoStop then Exit;
end;
ProcessBar.Progress := 0;
UserInfo.Caption := 'Chinese Language Active OK !';
end;
procedure TPanasonicGD92.ExitTestModeClick(Sender: TObject);
begin
ExitTestMode.Enabled := False;
Step := 30;
ResponseArray[Step] := '0080015A';
ProcessBar.ForeColor := clRed;
ProcessBar.Progress := 0;
ComPort.PutChar(#$00);
ProcessBar.Progress := 25;
ComPort.PutChar(#$80);
ProcessBar.Progress := 50;
ComPort.PutChar(#$01);
ProcessBar.Progress := 75;
ComPort.PutChar(#$23);
ProcessBar.Progress := 100;
while Step = 30 do begin
Application.ProcessMessages;
if DoStop then Exit;
end;
ProcessBar.Progress := 0;
ReadInfo.Enabled := False;
Chinese.Enabled := False;
TestMode.Enabled := True;
UserInfo.Caption := 'Phone Exit Test Mode OK !'; TestMode.Caption := 'Stop';
end;
procedure TPanasonicGD92.ReadInfoClick(Sender: TObject);
var IMEI92: string;
Code92: string;
Soft92: string;
begin
Step := 20;
UserInfo.Caption := 'Please Wait ...'; ProcessBar.ForeColor := clBlue;
ProcessBar.Progress := 0;
ComPort.PutChar(#$00);
ProcessBar.Progress := 8;
ComPort.PutChar(#$80);
ProcessBar.Progress := 15;
ComPort.PutChar(#$01);
ProcessBar.Progress := 23;
ComPort.PutChar(#$98);
ProcessBar.Progress := 31;
while Step = 20 do begin Application.ProcessMessages;
if DoStop then Exit;
end;
Code92 := Copy(PanaGD9xCode, 10, 1);
Code92 := Code92 + Copy(PanaGD9xCode, 12, 1);
Code92 := Code92 + Copy(PanaGD9xCode, 14, 1);
Code92 := Code92 + Copy(PanaGD9xCode, 16, 1);
Code92 := Code92 + Copy(PanaGD9xCode, 18, 1); GD92CODE.Text := Code92;
ProcessBar.Progress := 0;
UserInfo.Caption := 'Read Phone Code OK !'; Step := 21;
ComPort.PutChar(#$00);
ProcessBar.Progress := 38;
ComPort.PutChar(#$80);
ProcessBar.Progress := 46;
ComPort.PutChar(#$01);
ProcessBar.Progress := 53;
ComPort.PutChar(#$90);
ProcessBar.Progress := 62;
while Step = 21 do
begin
Application.ProcessMessages;
if DoStop then Exit;
end;
IMEI92 := Copy(PanaGD9xIMEI, 10, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 12, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 14, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 16, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 18, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 20, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 22, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 24, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 26, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 28, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 30, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 32, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 34, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 36, 1);
IMEI92 := IMEI92 + Copy(PanaGD9xIMEI, 38, 1); GD92IMEI.Text := IMEI92;
UserInfo.Caption := 'Read Phone IMEI OK !';
Step := 22;
ComPort.PutChar(#$00);
ProcessBar.Progress := 69;
ComPort.PutChar(#$80);
ProcessBar.Progress := 77;
ComPort.PutChar(#$02);
ProcessBar.Progress := 85;
ComPort.PutChar(#$94);
ProcessBar.Progress := 92;
ComPort.PutChar(#$00);
ProcessBar.Progress := 100;
while Step = 22 do
begin
Application.ProcessMessages;
if DoStop then Exit;
end;
Soft92 := 'GAD' + Copy(PanaGD9xSW, 16, 1);
Soft92 := Soft92 + Copy(PanaGD9xSW, 18, 1);
Soft92 := Soft92 + 'A' + Copy(PanaGD9xSW, 22, 1); Soft92 := Soft92 + Copy(PanaGD9xSW, 24, 1);
GD92SW.Text := Soft92;
ProcessBar.Progress := 0;
UserInfo.Caption := 'Read Phone Info OK !';
end;
procedure TPanasonicGD92.ComPortTriggerAvail(CP: TObject; Count: word);
var ST: string; Rs: string; // I: Integer;begin if Step = 1 then
begin
ProcessBar.Progress := 0;
ComPort.PutChar(#$00);
ProcessBar.Progress := 25;
ComPort.PutChar(#$80);
ProcessBar.Progress := 50;
ComPort.PutChar(#$01);
ProcessBar.Progress := 75;
ComPort.PutChar(#$5C);
ProcessBar.Progress := 100;
end; St := GetCOMData(Count);
Rs := ResponseArray[Step];
if Step = 20 then begin
PanaGD9xCode := St;
Rs := St;
end;
if Step = 21 then
begin
PanaGD9xIMEI := St; Rs := St;
end;
if Step = 22 then begin
PanaGD9xSW := St;
Rs := St;
end;
if Pos(Rs, St) > 0 then
Inc(Step);
end;
end.