Einzelnen Beitrag anzeigen

Benutzerbild von jaenicke
jaenicke

Registriert seit: 10. Jun 2003
Ort: Berlin
9.349 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: Daten aus TClientSocket verarbeiten

  Alt 20. Jan 2021, 20:02
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);
Sebastian Jänicke
Alle eigenen Projekte sind eingestellt, ebenso meine Homepage, Downloadlinks usw. im Forum bleiben aktiv!
  Mit Zitat antworten Zitat