Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Daten aus TClientSocket verarbeiten (https://www.delphipraxis.net/206692-daten-aus-tclientsocket-verarbeiten.html)

jaenicke 20. Jan 2021 20:02

AW: Daten aus TClientSocket verarbeiten
 
Hier mal ein Beispiel mit Indy und ohne dieses ganze String-Gehampel:
Delphi-Quellcode:
procedure TFormX.SendCommand(
  const APrio: Byte; //Priorität des befehls
  const ACommand: Byte; // unser Befehl, 8 Bits
  const ASubCommand: Byte; // unser Unterbefehl, 8 Bits
  const AHash: SmallInt; // unser Hash, 16 Bits
  const ADLC: Byte; //Anzahl der Datenbytes im CAN-Paket, 1 Byte
  const AUID: Integer; // Zieladresse des Objektes auf dem CAN, 32 Bits
  const AResponseBit: Byte); // wenn wir als PC-Programm senden, ist dieses Bit immer 0
var
  StartWord: SmallInt; // die Kombination aus Prio, Command und Responsebit
  CommandBytes: TIdBytes;
begin
  SetLength(CommandBytes, 13);
  StartWord := ( ((APrio SHL 12) + (ACommand SHL 1) + (AResponseBit AND 1)) AND 255 );
  CommandBytes[0] := (StartWord SHR 8) AND 255;
  CommandBytes[1] := StartWord AND 255;
  CommandBytes[2] := (AHash SHR 8) AND 255;
  CommandBytes[3] := AHash AND 255;
  CommandBytes[4] := ADLC AND 255;
  CommandBytes[5] := ((AUID SHR 24) AND 255); // Big Endian encoding
  CommandBytes[6] := ((AUID SHR 16) AND 255);
  CommandBytes[7] := ((AUID SHR 8) AND 255);
  CommandBytes[8] := (AUID AND 255);
  CommandBytes[9] := ASubCommand;
  CommandBytes[10] := 0;
  CommandBytes[11] := 0;
  CommandBytes[12] := 0;

  IdTCPClient.IOHandler.Write(CommandBytes);
end;

// Aufruf:
  SendCommand(0, // Byte - wir haben keine Priorität immer 0
    0, // Byte - 0x00 = 0 Systembefehl
    1, // Power ON - System Go (0x01)
    18193, // SmallInt - wie im Beispiel, kann aber auch &h0300 sein (als Minimum)
    5, // Byte
    0, // Integer - UID = 0 bedeutet: sende den Befehl an alle
    0);


Alle Zeitangaben in WEZ +1. Es ist jetzt 21:27 Uhr.
Seite 2 von 2     12   

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