Forum Delphi.cz

Odchytávač reklamy - nevkládejte sem => Léčka na nováčky => Téma založeno: jarada 05-03-2017, 20:13:42

Název: problem comport 5 baudrate
Přispěvatel: jarada 05-03-2017, 20:13:42
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CPort ;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Edit1: TEdit;
    ComPort1: TComPort;
    procedure FormCreate(Sender: TObject);
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure Button1Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
    rx : string;
 count : integer;
 timer : integer;
implementation

{$R *.dfm}

 function StringToHex(S: String): string;
var n: Integer;
begin
     Result:= '';
  for n := 1 to length (S) do
      Result:= Result+IntToHex(ord(S[n]),2);
end;

function HexToString(H: String): String;
var n: Integer;
begin
  Result:= '';
  for n := 1 to length (H) div 2 do
    Result:= Result+Char(StrToInt('$'+Copy(H,(n+1)*2+1,2)));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
comport1.CustomBaudRate := 5;
comport1.BaudRate:=brcustom;
comport1.Port:='COM1';
comport1.Open;

end;

procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
begin
         memo1.Lines.Add(inttostr(comport1.ReadStr(rx,count)));
 end;

procedure TForm1.Button1Click(Sender: TObject);
begin
      comport1.Close;
      application.Terminate;
end;

end.