"ON AIR Schalter" soll auf Verbindungsabbruch reagieren

Funktioniert:

const
  BUTTONNAME = 'SIGNAL.ENC';

var
  Count: integer;
  EncoderState: Array of integer;

procedure OnLoad; 
var
  i: integer;
begin
  Count := Encoder.GetConnections.GetCount;
  SetLength(EncoderState, Count);
  for i := 0 to Count - 1 do
  begin
    if Encoder.GetConnections.GetItem(i).GetState = ecsConnected then
      EncoderState[i] := 1
    else
      EncoderState[i] := 0;
  end;
end;

procedure OnEncoderConnectionStateChange(Connection: IEncoderConnection; 
  OldState, NewState: TEncoderConnectionState);
var
  i, c: integer;
begin
  i := Encoder.GetConnections.IndexOf(Connection);
  if NewState = ecsConnected then
    EncoderState[i] := 1
  else if (NewState = ecsDisconnected) AND (OldState = ecsConnected) then
    EncoderState[i] := 0;
  c := 0;
  Encoder.GetConnections.BeginRead;
  try
    for i := 0 to Count - 1 do
      c := c + EncoderState[i];
    if c = 0 then
      ExecuteCommand(BUTTONNAME + ' BACKGROUNDCOLOR #FF0000')
    else if c = Count then
      ExecuteCommand(BUTTONNAME + ' BACKGROUNDCOLOR #00FF00')
    else
      ExecuteCommand(BUTTONNAME + ' BACKGROUNDCOLOR #FFFF00');
  finally
    Encoder.GetConnections.EndRead;
  end;
end;

begin
end.

[Statischer Text namens SIGNAL.ENC ändert die Farbe:

  • Grün: Alle Encoder sind verbunden,

  • rot: Kein Encoder ist verbunden,

  • gelb: Mindestens ein Encoder (jedoch nicht alle) ist getrennt.]

Danke, @Torben!

5 Likes