示例#1
0
        public int InitializeAeObjects(string url)
        {
            int connectResult = (int)EnumResultCode.E_FAIL;

            m_executionOptions = new ExecutionOptions();
            m_executionOptions.ExecutionType    = EnumExecutionType.ASYNCHRONOUS;
            m_executionOptions.ExecutionContext = 0;

            try
            {
                m_aeSession      = new MyAeSession(url);
                m_aeSubscription = new MyAeSubscription(m_aeSession);

                connectResult = m_aeSession.Connect(true, false, new ExecutionOptions());

                uint[] categoryIds = new uint[]
                {
                    (uint)CategoriesAndAttribute.Categories.System_alarm,
                    (uint)CategoriesAndAttribute.Categories.Process_alarm,
                    (uint)CategoriesAndAttribute.Categories.Operation_record
                };
                m_aeSubscription.FilterCategories = categoryIds;

                AeReturnedAttributes[] returnedAttributes = new AeReturnedAttributes[categoryIds.Length];
                for (int i = 0; i < categoryIds.Length; i++)
                {
                    List <uint> temp         = CategoriesAndAttribute.getAttributeIDsFromCategoryID(categoryIds[i]);
                    uint[]      attributeIds = new uint[temp.Count];
                    attributeIds          = temp.ToArray();
                    returnedAttributes[i] = new AeReturnedAttributes();
                    returnedAttributes[i].AttributeIds = attributeIds;
                    returnedAttributes[i].CategoryId   = categoryIds[i];
                }
                m_aeSubscription.ReturnedAttributes = returnedAttributes;
            }
            catch (Exception exc)
            {
                GetApplication().Trace(
                    EnumTraceLevel.ERR,
                    EnumTraceGroup.USER,
                    "OpcClient::InitializeAeObjects",
                    exc.ToString());
            }   //    end try...catch

            return(connectResult);
        }       //    end InitializeAeObjects
示例#2
0
        // method that handles the AeSubscription.AeEventsReceived event; it displays on the console the received events
        public static void HandleEventsReceived(AeSubscription anAeSubscription, bool refresh, bool lastRefresh, AeEvent[] events)
        {
            for (int i = 0; i < events.Length; i++)
            {
                string time               = events[i].OccurenceTime.AddHours(8).ToString();
                string bitNumber          = events[i].SourcePath;
                string bitNumberDescribe  = string.Empty;
                string aeType             = string.Empty;
                string priority           = events[i].Severity.ToString();
                string realTimeValue      = string.Empty;
                string limitValue         = string.Empty;
                string engineeringUnit    = string.Empty;
                string aeDescribe         = events[i].Message;
                string device             = string.Empty;
                string area               = string.Empty;
                string operatingFloor     = string.Empty;
                string operatingPersonnel = string.Empty;
                string extension_1        = string.Empty;
                string extension_2        = string.Empty;
                string extension_3        = string.Empty;
                string extension_4        = string.Empty;
                string extension_5        = string.Empty;

                string messageType = events[i].Category.ToString();
                string isDCS       = string.Empty;

                string aeSubType     = string.Empty;
                string areaNumber    = string.Empty;
                string stationNumber = string.Empty;
                string alarmLevel    = string.Empty;
                string alarmOff      = string.Empty;
                string alarmBlink    = string.Empty;
                string alarmFilter   = string.Empty;
                string ackRequired   = string.Empty;
                string quality       = string.Empty;

                if (events[i].EventType == EnumEventType.CONDITION)
                {
                    aeType      = ((AeCondition)events[i]).ConditionName;
                    aeSubType   = ((AeCondition)events[i]).SubConditionName;
                    ackRequired = ((AeCondition)events[i]).AckRequired.ToString();
                    quality     = ((AeCondition)events[i]).Quality.ToString();
                }

                ArrayList     attributes = events[i].Attributes;
                List <string> temp       = CategoriesAndAttribute.getAttributeNamesFromCategoryID(events[i].Category);
                for (int j = 0; j < events[i].Attributes.Count; j++)
                {
                    if (temp[j].Equals("Data_value"))
                    {
                        realTimeValue = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Engineering_unit"))
                    {
                        engineeringUnit = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Area_number"))
                    {
                        areaNumber = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Station_number"))
                    {
                        stationNumber = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_level"))
                    {
                        alarmLevel = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_off"))
                    {
                        alarmOff = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_blink"))
                    {
                        alarmBlink = attributes[j].ToString();
                    }
                    if (temp[j].Equals("Alarm_filter"))
                    {
                        alarmFilter = attributes[j].ToString();
                    }
                }

                AEInfos oneAEInfo = new AEInfos
                {
                    Time               = time,
                    BitNumber          = bitNumber,
                    BitNumberDescribe  = bitNumberDescribe,
                    AEType             = aeType,
                    Priority           = priority,
                    RealTimeValue      = realTimeValue,
                    LimitValue         = limitValue,
                    EngineeringUnit    = engineeringUnit,
                    AEDescribe         = aeDescribe,
                    Device             = device,
                    Area               = area,
                    OperatingFloor     = operatingFloor,
                    OperatingPersonnel = operatingPersonnel,
                    Extension_1        = extension_1,
                    Extension_2        = extension_2,
                    Extension_3        = extension_3,
                    Extension_4        = extension_4,
                    Extension_5        = extension_5,

                    MessageType = messageType,
                    IsDCS       = isDCS,

                    AESubType     = aeSubType,
                    AreaNumber    = areaNumber,
                    StationNumber = stationNumber,
                    AlarmLevel    = alarmLevel,
                    AlarmOff      = alarmOff,
                    AlarmBlink    = alarmBlink,
                    AlarmFilter   = alarmFilter,
                    AckRequired   = ackRequired,
                    Quality       = quality
                };

                MessageQueueTool.EnMessage(oneAEInfo);

                File.AppendAllText(@"./AEInfos.json", JsonConvert.SerializeObject(oneAEInfo, Formatting.Indented) + "\n");
                if (new FileInfo(@"./AEInfos.json").Length >= 50 * 1024 * 1024)
                {
                    File.Delete(@"./AEInfos_backup.json");
                    File.Move(@"./AEInfos.json", @"./AEInfos_backup.json");
                }
            }//end  for
        }