SQL Data-recording with Redundant Servers

I have have a Standalone CitectSCADA System (2015) which executes Cicode on an event triggered by a PLC to log batch data to SQL.  The Cicode then "confirms" the datarecord by writting back to the PLC.  We are upgrading to running redundant 2018R2 CitectSCADA servers but I am unsure of how to configure the Cicode/event to only execute on one server (switching to the other in the event of failure).

  • Hi Tony,
    How about something like this? Call TaskNew() to start TaskOnAServer on both servers at startup. Each one will check if it the active server and only the active one will do the work.
    Kind regards
    David



    INT
    FUNCTION IsActiveServer()

    STRING sLocalServerName
    INT iResult;

    iResult = 0;
    sLocalServerName = ServerInfoEx ( "Server" , 0 , "IOServer" ) ;
    IF(IODeviceInfo("SomeDevice" , 17) = sLocalServerName) THEN
    iResult = 1;
    END

    RETURN iResult;
    END



    FUNCTION TaskOnAServer()

    WHILE 1 DO // endless loop

    IF (IsActiveServer() = 0) THEN
    WHILE (IsActiveServer() = 0) DO // if not currently the active server
    Sleep(10);
    END

    ELSE
    WHILE (IsActiveServer() = 1) DO // if currently the active server

    DoSomething(); // the thing you want only the active server to do

    Sleep(1); // sleep a bit
    END
    END

    END // while

    END
  • Instead of using loops it is probably better to use tagsubscriptions. You can use the TagSubscribe() for that, there are various parameters you can define. In the callback function you can define the logging of data to the SQL and the confirmation to the controller. I usually also subscribe the values that have to go into the SQL database. In that way you don't have to use TagRead(), which can have a negative influence on the performance if you use it heavilly. You can start the subscription on the Alarm or Report Server. In the callback function use IF StrToInt(ServerInfoEx ("Alarm/Report" , 0)) = 1 THEN to only do the logging and confirmation once on the 'active' server component. The callback function is only triggered when the value of the subscribed tag changes.
  • Just use a report. Reports are only run on the active Report server, and can call any Cicode function, as well as be called on trigger or periodically.