Example #1
0
        /*****************************************************************************************************/
        /* This is the objective of this sample !                                                            */
        /*****************************************************************************************************/
        static void handler_OnEventNotify(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetEventNotificationData EventData, bool need_confirm)
        {
            string val;

            // if event enrollment dispaly which datapoint is being watched
            if (EventData.eventObjectIdentifier.type == BacnetObjectTypes.OBJECT_EVENT_ENROLLMENT)
            {
                IList <BacnetValue> values;
                sender.ReadPropertyRequest(adr, EventData.eventObjectIdentifier, BacnetPropertyIds.PROP_OBJECT_PROPERTY_REFERENCE, out values);

                BacnetDeviceObjectPropertyReference obj = (BacnetDeviceObjectPropertyReference)values[0].Value;
                val = adr.ToString() + ":" + EventData.initiatingObjectIdentifier.type + ":" + EventData.initiatingObjectIdentifier.instance + ":" + EventData.eventObjectIdentifier.type + ":" + EventData.eventObjectIdentifier.instance + " object Type : " + obj.objectIdentifier.type + " object Instance :" + obj.objectIdentifier.instance + " object Property :" + obj.propertyIdentifier;
            }
            else
            {
                val = adr.ToString() + ":" + EventData.initiatingObjectIdentifier.type + ":" + EventData.initiatingObjectIdentifier.instance + ":" + EventData.eventObjectIdentifier.type + ":" + EventData.eventObjectIdentifier.instance;
            }

            if (need_confirm)
            {
                sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_EVENT_NOTIFICATION, invoke_id);
            }

            // Just to show how Acknowledgement can be programmed. Never Ack an alarm like this without tested the source, the reason, ... and normally with a human action
            if (EventData.ackRequired)
            {
                sender.AlarmAcknowledgement(adr, EventData.eventObjectIdentifier, EventData.toState, "Alarmlistener", EventData.timeStamp, new BacnetGenericTime(DateTime.Now, BacnetTimestampTags.TIME_STAMP_DATETIME));
            }


            Console.WriteLine(val + " " + EventData.fromState + " to " + EventData.toState + " " + EventData.notifyType.ToString());
        }
Example #2
0
        private void AckBt_Click(object sender, EventArgs e)
        {
            TreeNode tn = TAlarmList.SelectedNode;

            if (tn == null)
            {
                return;
            }
            while (tn.Parent != null)
            {
                tn = tn.Parent;                                                          // go up
            }
            BacnetGetEventInformationData alarm = (BacnetGetEventInformationData)tn.Tag; // the alam content

            bool SomeChanges = false;

            for (int i = 0; i < 3; i++)                                 // 3 transitions maybe to be ack To_Normal, To_OfNormal, To_Fault
            {
                if (alarm.acknowledgedTransitions.ToString()[i] == '0') // Transition to be ack, 1 means ok/already done
                {
                    BacnetGenericTime bgt;

                    if (alarm.eventTimeStamps != null)
                    {
                        bgt = alarm.eventTimeStamps[i];
                    }
                    else // Deprecate Execution of GetAlarmSummary
                    {
                        // Read the event time stamp, we do not have it
                        IList <BacnetValue> values;
                        if (comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_EVENT_TIME_STAMPS, out values, 0, (uint)i) == false)
                        {
                            Trace.TraceWarning("Error reading PROP_EVENT_TIME_STAMPS");
                            return;
                        }
                        String   s1 = ((BacnetValue[])(values[0].Value))[0].ToString(); // Date & 00:00:00 for Hour
                        String   s2 = ((BacnetValue[])(values[0].Value))[1].ToString(); // 00:00:00 & Time
                        DateTime dt = Convert.ToDateTime(s1.Split(' ')[0] + " " + s2.Split(' ')[1]);
                        bgt = new BacnetGenericTime(dt, BacnetTimestampTags.TIME_STAMP_DATETIME);
                    }

                    // something to clarify : BacnetEventStates or BacnetEventEnable !!!
                    BacnetEventNotificationData.BacnetEventStates eventstate = (BacnetEventNotificationData.BacnetEventStates)(2 - i);

                    if (comm.AlarmAcknowledgement(adr, alarm.objectIdentifier, eventstate, AckText.Text, bgt,
                                                  new BacnetGenericTime(DateTime.Now, BacnetTimestampTags.TIME_STAMP_DATETIME)) == true)
                    {
                        alarm.acknowledgedTransitions.SetBit((byte)i, true);
                        SomeChanges = true;
                    }
                }

                if (SomeChanges)
                {
                    FillTreeNode();
                }
            }
        }