Hola Egostar.
Este codigo copila bien, no me da error alguno pero no corre del todo bien, me manda los hex 02 00 pero el micro no manda los 8 hex.
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, CPort, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ComPort1: TComPort;
procedure Button1Click(Sender: TObject);
procedure ComPortRxChar(Sender: TObject; Count: Integer);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure AddHexString(S : String; Lines : TStrings );
var AddS, HexS, CopyS : String;
i : Integer;
const SLen = 8;
begin
while Length(S) > 0 do
begin
AddS := Copy(S,1,SLen);
HexS := '';
Delete(S,1,SLen);
for i := 1 to SLen do
begin
CopyS := Copy(AddS,i,1);
if CopyS <> '' then
HexS := HexS + ' ' + Format('%2.2x',[Byte(CopyS[1])]) else
HexS := HexS + ' ';
end;
while Length(AddS) < SLen do
AddS := AddS + ' ';
for i := 1 to SLen do
case AddS[i] of
#0..#31 : AddS[i] := '.';
#127 : AddS[i] := '.';
end;
Lines.Add(HexS+' : '+AddS);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Comport1.Connected:=true;
Comport1.WriteStr(#2#0);
end;
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
Str: String;
begin
ComPort1.ReadStr(Str, Count);
If Str= 'Hi-LOGIC' then
ShowMessage('Ya estamos conectados')
else ShowMessage('Ya nos la pellizcamos');
end;
end.
Un Saludo.