yevabas,
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
public
end;
function HexToInt(NumHex: String): Int64;
var
Form1: TForm1;
implementation
{$R *.dfm}
function HexToInt(NumHex: String): Int64;
var
i, j : Integer;
Hex : String;
AuxStr : String;
NumDec: Int64;
PowerHex: Int64;
AuxPower : Extended;
begin
NumDec := 0;
j := Length(NumHex);
for i := j downto 1 do
begin
AuxPower := Power(16,j-i);
AuxStr := FloatToStr(AuxPower);
PowerHex := StrToInt(AuxStr);
Hex := NumHex[i];
if (Hex ='A') then Hex := '10';
if (Hex ='B') then Hex := '11';
if (Hex ='C') then Hex := '12';
if (Hex ='D') then Hex := '13';
if (Hex ='E') then Hex := '14';
if (Hex ='F') then Hex := '15';
NumDec := NumDec + StrToInt(Hex) * PowerHex;
end;
Result := NumDec;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BufferPort : Array[1..80] of Byte; i : Integer;
DataPort : String;
begin
FillChar(BufferPort, Sizeof(BufferPort), 0);
for i:= 1 to 80 do
begin
BufferPort[i] := 169 + i;
end;
for i:= 1 to 80 do
begin
DataPort := DataPort + IntToHex(BufferPort[i],2);
end;
Memo1.Lines.Add(DataPort);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
BufferPort : Array[1..80] of Byte; i, j : Integer;
DataPort : String;
SerialPort : String;
NumHex : String;
begin
FillChar(BufferPort, Sizeof(BufferPort), 0);
Serialport := '010203040506070809AABBCCDDEEFF';
j := 1;
for i:= 1 to Length(SerialPort) do
begin
if (i Mod 2 <> 0) then
begin
NumHex := Copy(SerialPort,i,2);
BufferPort[j] := HexToInt(NumHex);
Inc(j);
end;
end;
for i:= 1 to 80 do
begin
DataPort := DataPort + IntToHex(BufferPort[i],2);
end;
Memo1.Lines.Add(DataPort);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i : Integer;
DataPort : String;
SerialPort : String;
NumHex : String;
begin
Serialport := '010203040506070809AABBCCDDEEFF';
for i:= 1 to Length(SerialPort) do
begin
if (i Mod 2 <> 0) then
begin
NumHex := Copy(SerialPort,i,2);
DataPort := DataPort + NumHex;
end;
end;
Memo1.Lines.Add(DataPort);
end;
end.
El código anterior muestra tres versiones que simulan recibir datos Hexadecimales de un Puerto Serial y visualizan la data recibida en un Control TMemo, quizás alguna versión se adapte a tu proyecto.
Espero sea útil
Nelson.