PDA

View Full Version : Send HEX code to mobile with pascal



Zandis
21-03-2004, 02:00 PM
Here I read about "How to make reset phone soft with VB" - http://blight.dk/nokia/pcorner/gettingstarted.php
But I interesting how to do this with pascal or delphi.

As I understand, first what I must to do is seperate hex code and each byte send throught COM port in byte(decimal), yes?
For exapmple if I must send hex code B3 A0 AA C4
B3 A0 AA C4 code in decimal is 179 160 170 196

var f:text;
b:byte;
begin
assign(f,'COM1');
rewrite(f);
b:=179;
writeln(f,b);
b:=160;
writeln(f,b);
b:=170;
writeln(f,b);
b:=196;
writeln(f,b);
close(f);
end.

This is not working :(. Can anybody show me some other way to send that code to phone?

Help please.
Thanx

Ice Draagon
22-03-2004, 03:54 AM
Let's assume we have a Serial COM port component named COMM
First initialize the COM port:

// First, set COMM properties
Comm.Port:='COM1';
If memBUSType='FBUS' then
begin
Comm.BaudRate:=br115200;
Comm.Parity.Bits:=prNone;
end;
If memBUSType='MBUS' then
begin
Comm.BaudRate:=br9600;
Comm.Parity.Bits:=prOdd;
end;
Comm.DataBits:=dbEight;
Comm.StopBits:=sbOneStopBit;
Comm.FlowControl.ControlRTS:=rtsDisable;
Comm.FlowControl.ControlDTR:=dtrEnable;

Comm.Buffer.InputSize:=1024;
Comm.Open;
FConnected:=Comm.Connected;

If FConnected then
begin
If memBUSType='FBUS' then WritePort(StringOfChar(#$55,80));
If memBUSType='MBUS' then WritePort(#$1F#$00#$1D#$D0#$00#$01#$04#$01#$CS );
//CS is computed
end;


//------------------------
procedure xxxx.WritePort(Bytes:String);
var xLen,Len,iResult:Integer;
TXChar:String;
begin
xLen:=8;
Repeat
Len:=Length(Bytes);
If xLen>Len then xLen:=Len;
TXChar:=LeftStr(Bytes,xLen);
iResult:=Comm.WriteStr(TXChar);
Delete(Bytes,1,xLen);
Until Length(Bytes)=0;
end;


Basically, that's how to initialize the phone.

The procedure WRITEPORT is used to correctly send the bytes to the phone.

Zandis
22-03-2004, 02:28 PM
Thanx a lot mate.