2009年11月12日

AT Command Send Unicode Message

How to Send SMS Messages from a Computer
3GPP UMTS Specification Release 6

Unit1.pasunit Unit1;

interface

uses
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs,
QStdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
public
end;

var
Form1: TForm1;

implementation
{$R *.xfm}

function WStrToHex(ws: WideString): string;
var
i: integer;
begin
Result := '';
for i := 1 to Length(ws) do begin
Result := Format('%s%.4x', [Result, Word(ws[i])]);
end;
Result := Format('%.2x%s', [length(ws) * 2, Result]);
end;

function swapphone(Phone: string): string;
var
b: Char;
i, ln: Integer;
Internationalnumber: Boolean;
interstr: string;
begin
Internationalnumber := Phone[1] = '+';
ln := Length(Phone);
if Internationalnumber then begin
Result := PChar(@Phone[2]);
Dec(ln);
end else begin
Result := Phone;
end;
if (ln mod 2) = 1 then begin
Result := Result + 'F';
end;
i := 1;
while (i < Length(Result)) do begin
b := Result[i];
Result[i] := Result[i + 1];
Result[i + 1] := b;
Inc(i, 2);
end;
if Internationalnumber then begin
interstr := '91';
end else begin
interstr := '81';
end;
Result := Format('%.2x%s%s', [ln ,interstr ,Result]);
end;


procedure TForm1.Button1Click(Sender: TObject);
var
msgstr: string;
pln, mln: Integer;
begin
msgstr := Format('0001FF%S0008%s',[
swapphone(Edit3.Text), WStrToHex(Edit1.Text)]);
Memo1.Clear;
Memo1.Lines.Add(Format('AT+CMGW=%d',[(Length(msgstr) div 2) -1]));
Memo1.Lines.Add(msgstr);
end;

end.
Unit1.dfmobject Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 4
Top = 32
Width = 75
Height = 25
Caption = 'Binary Code'
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 4
Top = 8
Width = 289
Height = 21
TabOrder = 1
Text = '手機'
end
object Edit2: TEdit
Left = 4
Top = 60
Width = 617
Height = 21
TabOrder = 2
end
end

沒有留言:

網誌存檔