Applies To:
  • CitectSCADA 5.xx, 5.40 Service Pack A

MsgOpen() returns a handle even though the message session is not online.

For example, if a client is started and no server is running, trying CiCode function MsgOpen("alarm", 0, 0) will return a handle even if the client is not attached to any alarm server.

Using that message handle in other message functions may result in unexpected behavior.


A new CiCode Function - INT MsgState(INT hMsg) has been added.

Users should call MsgState(hMsg) with the message session handle returned from MsgOpen(Name, Mode, Fn) to verify the status of that message session.

If the status of the message session is online, the message session handle is truly valid and the callback function - "Fn" (the third argument in MsgOpen) is set effectively.

Example code on how to use this MsgState().

** This code will open a connection to the alarms server from
** the client side. The client will call the Prompt function
** remotely if the connection is online. The Prompt function will
** execute on the alarm server and display "Hello Alarm Server"
** on the prompt line. Otherwise, the client will display the status
** of the connection on local machine's prompt line.
    INT hAlarm;
    hAlarm = MsgOpen("Alarm", 0, 0);
    SELECT CASE MsgState(hAlarm)
    CASE -1
        Prompt("Cannot Open to Alarm Server");
    CASE 0
        Prompt("Message session to Alarm Server is OFFLINE");
    CASE 1
        Prompt("Message session to Alarm Server is ONLINE");
        MsgRPC(hAlarm, "Prompt", "^"Hello Alarm Server^"", 1);
    CASE 2
        Prompt("Message session to Alarm Server is CONNECTING");
    CASE 3
        Prompt("Message session to Alarm Server is DISCONNECTING");

CIT has confirmed this to be a problem in Citect for Windows versions up to 5.40 Service Pack B. This problem has been fixed in version 5.41.