Which server am I connected to?

I have seen a lot of functions that give information on the servers, but the one i am looking for is elusive.

ServerIsOnline wil give me the status of the servers - both the primary and standby.

However, I am only communicating to one of them at a time.

How would I find out which one I am talking to?

  • Hi Michael,

    The concept of primary and standby is different for every Citect process (Alarm Server, Trend Server, Report Server and I/O Servers).
    A client could be connected to the primary trend server as well as the standby alarm server. For I/O it's even more complicated because there is no primary or standby server as such. Each I/O device can have a primary and a standby definition, and these can reside on any I/O server in your setup.

    If you want to know what I/O server your client is talking to for a specific I/O device, you can use the following function:

    sCurrentIOServer = IODeviceInfo(sIODevice, 17); // returns the name of the active I/O server

    This syntax only works if your primary and standby I/O devices are configured with the exact same name.
    If the names of a redundant I/O device pair are not the same, you first have to find out the I/O device number (aka unit number) before you can find the active server:

    iUnitNr = StrToInt(IODeviceInfo(sIODevice, 11)); // returns the I/O device number
    sCurrentIOServer = IODeviceInfo(iUnitNr, 17); // returns the name of the active I/O server

    To find out which Alarm server you are connected to use:

    bConnectedToStandbyServer = StrToInt(ServerInfo("Alarm", 2); // returns 0 if connected to primary server, otherwise 1

    This works for Trend and Report servers as well, just replace the word "Alarm" with "Trend" or "Report".
  • The way I have always thought about this is that one server was doing the bulk of the communications, and the standby was monitoring it. The Alarm server is redundant, with 2 running at the same time, where the Trend and Report have 1 running and one not.
    I've worked thorugh this pretty well with the servers. Still having trouble in the I/O.
    For example, I would like to read the number of errors from an I/O device.
    IODeviceInfo("Device",20,sCluster)
    Client side functions (3) work fine, but it seems that the number of errors is a server side function.
    MsgRPC should get this, but if it is set as unblocked, it does not return a result and if it is set as blocked, the code trips an error and doesn't complete.
    How would you display the number of errors for an IODevice on the graphics?
  • Hi Michael,

    MsgRPC calls can only return information when set to blocking. To be able to display this information, you could run a cicode function on the I/O server that writes the information to a Variable Tag at certain intervals:

    FUNCTION MyIODeviceInfoLoop(STRING sIODevice, STRING sTagName)

    STRING sActiveServer;

    STRING sNumberOfErrors;

    WHILE TRUE DO

    sActiveServer = IODeviceInfo(sIODevice, 17);

    IF ProcessIsServer("IOServer", "", sActiveServer) THEN

    // We are the active I/O server for this I/O device

    sNumberOfErrors = IODeviceInfo(sIODevice, 20);

    TagWrite(sTagName, sNumberOfErrors);

    END

    SleepMS(1000);  // Update the info every second

    END

    END

     

    You can start this function on both I/O servers using:

    TaskNew("MyIODeviceInfoLoop", "^"Device^", ^"DeviceInfoTag^"", 8);

    assuming your I/O device is called "Device" and the tag you like to display is called "DeviceInfoTag".

     

    Best regards,

    Patrick