Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi ComPort. Change Button Connect> Disconnect + Sort Listing (https://www.delphipraxis.net/206366-comport-change-button-connect-disconnect-sort-listing.html)

R1z0 14. Dez 2020 22:52

Delphi-Version: 7

ComPort. Change Button Connect> Disconnect + Sort Listing
 
Liste der Anhänge anzeigen (Anzahl: 1)
Greetings,
I'm not local. I'm sorry for mistakes.I have a code to connect to a 3d printer.

Code:
procedure TForm1.btnConnectClick(Sender: TObject);
begin
ComPort.Port := ComComboBox1.Text; // hier der Port als String
ComPort.BaudRate := br115200;
ComPort.DataBits := dbSeven;
ComPort.StopBits := sbOneStopBit;
ComPort.Parity.Bits := prEven;
ComPort.Buffer.InputSize := 1024; // musst du anpassen
ComPort.Buffer.OutputSize := 1024; // musst du anpassen

  begin
try
  ComPort.Open;
  if ComPort.Connected then
  begin
    Memo.Text := Memo.Text + 'Connected to the com serial port ('+ComPort.Port+')';
    Memo.Lines.Add(''); //
  end
  else
    Memo.Text := Memo.Text + 'Failed to open com serial port ('+ComPort.Port+')';
    Memo.Lines.Add(''); //
 Except on E : Exception do
  begin
    Memo.Text := Memo.Text + 'ERROR opening connection: Details> '+E.Message;
    Memo.Lines.Add(''); //
   end
   end
end;
end;

procedure TForm1.ComPortOpen(Sender: TObject);
begin
  btnConnect.Caption := 'Disconnect';
end;

procedure TForm1.ComPortClose(Sender: TObject);
begin
  if btnConnect <> nil then
    btnConnect.Caption := 'Connection';
end;
I don't know how to append this code to change the button

Code:
begin
  if ComPort.Connected then
    ComPort.Close
  else
    ComPort.Open;
end;
And how do I sort the Listing so that Echo is on each line

Code:
procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str: String;

begin
  ComPort.ReadStr(Str, Count);
  Memo.Text := Memo.Text + Str;
  Memo.Lines.Add('');
end;
my idea
start
echo:Marlin 2.0.5.3

echo:
Free Memory: 1156 PlannerBufferBytes: 1200

echo:V76 stored settings retriev
ed (656 bytes; crc 27057)
echo: G21 ; Units in mm (mm)
echo: M149 C ; Units in Celsius

ech
o:; Filament settings: Disabled
echo: M200 D1.75
echo: M200 D0
echo:; Steps per unit:
echo: M92 X80.00 Y80.00 Z400.00 E415.00

echo:; Maximum feedrates (units/s):
echo: M203 X500.00 Y500.00 Z10.00 E50.00
echo:; Maximum Acceleration (units/s2):
echo: M201 X500.00 Y500.00 Z100.00 E5000.00
echo:; Acceleration (units/s2
): P<print_accel> R<retract_accel> T<travel_accel>


UPDATE

Line spacing resolved. Removal echo code
Code:
 procedure TForm1.ComPortRxChar(Sender: TObject; Count: Integer);
var
  Str: String;

begin
  ComPort.ReadStr(Str, Count);
  Memo.Text := Memo.Text + Str;
  [B][U] Memo.Lines.Text := StringReplace(Memo.Lines.Text,'echo:','',[rfReplaceAll, rfIgnoreCase]);[/U][/B]
  Memo.Lines.Add('');
end;
and increase the Max length

Thank you for the answers and advice

TurboMagic 15. Dez 2020 18:33

AW: ComPort. Change Button Connect> Disconnect + Sort Listing
 
You mix direct setting of memo text and Memo.lines.add.
And the sLineBreak constant can be used to add a Linebreak to a string in a cross platform way.

himitsu 15. Dez 2020 19:46

AW: ComPort. Change Button Connect> Disconnect + Sort Listing
 
At the end of Memo.Text is always an linebrak.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:46 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz