/// <summary> /// alarm event handler to perform task basis on event state changed /// </summary> /// <param name="sender"></param> /// <param name="adr"></param> /// <param name="EventData"></param> public void handler_OnEventNotify(BacnetClient sender, BacnetAddress adr, BacnetEventNotificationData EventData) { string val = adr.ToString() + ":" + EventData.initiatingObjectIdentifier.type + ":" + EventData.initiatingObjectIdentifier.instance + ":" + EventData.eventObjectIdentifier.type + ":" + EventData.eventObjectIdentifier.instance; Console.WriteLine(val + " " + EventData.fromState + " to " + EventData.toState + " " + EventData.notifyType.ToString()); string lsDeviceDetail = EventData.initiatingObjectIdentifier.type + ":" + EventData.initiatingObjectIdentifier.instance; string lsInstanceDetail = EventData.eventObjectIdentifier.type + ":" + EventData.eventObjectIdentifier.instance; string lsEventState = EventData.fromState + " to " + EventData.toState; AlarmEventChangesToUI(lsDeviceDetail, lsInstanceDetail, lsEventState); }
public void SendIntrinsectEvent(BacnetObjectId SenderObject, BacnetEventNotificationData.BacnetNotifyTypes notifyType, BacnetEventNotificationData.BacnetEventTypes evenType, BacnetEventNotificationData.BacnetEventStates fromstate, BacnetEventNotificationData.BacnetEventStates tostate) { if ((m_PROP_RECIPIENT_LIST == null) || (m_PROP_RECIPIENT_LIST.Count == 0)) { return; } BacnetEventNotificationData bacnetEvent = new BacnetEventNotificationData(); // The struct is the same of all recipients, except one attribut bacnetEvent.notificationClass = m_PROP_OBJECT_IDENTIFIER.instance; bacnetEvent.initiatingObjectIdentifier = Device; bacnetEvent.eventObjectIdentifier = SenderObject; bacnetEvent.toState = tostate; bacnetEvent.fromState = fromstate; bacnetEvent.notifyType = notifyType; bacnetEvent.eventType = evenType; BacnetGenericTime timeStamp = new BacnetGenericTime(); timeStamp.Tag = BacnetTimestampTags.TIME_STAMP_DATETIME; timeStamp.Time = DateTime.Now; bacnetEvent.timeStamp = timeStamp; bacnetEvent.priority = 127; for (int i = 0; i < m_PROP_RECIPIENT_LIST.Count; i++) { bool DoASend = true; DeviceReportingRecipient devReportEntry = (DeviceReportingRecipient)m_PROP_RECIPIENT_LIST[i].Value; // Time is OK ? if (TimeSpan.Compare(DateTime.Now.TimeOfDay, devReportEntry.fromTime.TimeOfDay) == -1) { DoASend = false; } if (TimeSpan.Compare(devReportEntry.toTime.TimeOfDay, DateTime.Now.TimeOfDay) == -1) { DoASend = false; } // Day is OK ? int DayOfWeek = (int)DateTime.Now.DayOfWeek; if (DayOfWeek == 0) { DayOfWeek = 7; // Put Sunday at the end of the enumaration } DayOfWeek = DayOfWeek - 1; // start at 0 if ((devReportEntry.WeekofDay.value[0] & (1 << DayOfWeek)) == 0) { DoASend = false; } // new State is OK ? if ((tostate == BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_OFFNORMAL) && ((devReportEntry.evenType.value[0] & 1) != 1)) { DoASend = false; } if ((tostate == BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_NORMAL) && ((devReportEntry.evenType.value[0] & 2) != 2)) { DoASend = false; } if ((tostate == BacnetEventNotificationData.BacnetEventStates.EVENT_STATE_FAULT) && ((devReportEntry.evenType.value[0] & 4) != 4)) { DoASend = false; } // Find the receiver endPoint KeyValuePair <BacnetClient, BacnetAddress>?recipient = null; if ((devReportEntry.adr != null) && (Mydevice.DirectIp != null)) { recipient = new KeyValuePair <BacnetClient, BacnetAddress> ( Mydevice.DirectIp, devReportEntry.adr ); } else { try { recipient = Mydevice.SuroundingDevices[devReportEntry.Id.instance]; } catch { } } if (recipient == null) { DoASend = false; } if (DoASend == true) { uint processIdentifier = devReportEntry.processIdentifier; object bacnetEventlock = new object(); // we need to change safely one element in the struct System.Threading.ThreadPool.QueueUserWorkItem((o) => { lock (bacnetEventlock) { bacnetEvent.processIdentifier = processIdentifier; recipient.Value.Key.SendUnconfirmedEventNotification(recipient.Value.Value, bacnetEvent); } }, null); } } }
/*****************************************************************************************************/ /* 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 = 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); } Console.WriteLine(val + " " + EventData.fromState + " to " + EventData.toState + " " + EventData.notifyType.ToString()); }
/*****************************************************************************************************/ /* 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()); }
/*****************************************************************************************************/ /* This is the objective of this sample ! */ /*****************************************************************************************************/ static void handler_OnEventNotify(BacnetClient sender, BacnetAddress adr, BacnetEventNotificationData EventData) { string val = adr.ToString() + ":" + EventData.initiatingObjectIdentifier.type + ":" + EventData.initiatingObjectIdentifier.instance + ":" + EventData.eventObjectIdentifier.type + ":" + EventData.eventObjectIdentifier.instance; Console.WriteLine(val + " " + EventData.fromState + " to " + EventData.toState + " " + EventData.notifyType.ToString()); }
public void SendUnconfirmedEventNotification(BacnetAddress adr, BacnetEventNotificationData eventData) { Trace.WriteLine("Sending Event Notification ... ", null); EncodeBuffer b = GetEncodeBuffer(m_client.HeaderLength); NPDU.Encode(b, BacnetNpduControls.PriorityNormalMessage, adr, null, DEFAULT_HOP_COUNT, BacnetNetworkMessageTypes.NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, 0); APDU.EncodeUnconfirmedServiceRequest(b, BacnetPduTypes.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BacnetUnconfirmedServices.SERVICE_UNCONFIRMED_EVENT_NOTIFICATION); Services.EncodeEventNotifyUnconfirmed(b, eventData); m_client.Send(b.buffer, m_client.HeaderLength, b.offset - m_client.HeaderLength, adr, false, 0); }
public IAsyncResult BeginAlarmAcknowledgement(BacnetAddress adr, BacnetObjectId objid, BacnetEventNotificationData.BacnetEventStates eventState, String AckText, BacnetGenericTime evTimeStamp, BacnetGenericTime ackTimeStamp, bool wait_for_transmit, byte invoke_id = 0) { Trace.WriteLine("Sending AlarmAcknowledgement ... ", null); if (invoke_id == 0) invoke_id = unchecked(m_invoke_id++); EncodeBuffer b = GetEncodeBuffer(m_client.HeaderLength); NPDU.Encode(b, BacnetNpduControls.PriorityNormalMessage, adr.RoutedSource, null, DEFAULT_HOP_COUNT, BacnetNetworkMessageTypes.NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, 0); APDU.EncodeConfirmedServiceRequest(b, BacnetPduTypes.PDU_TYPE_CONFIRMED_SERVICE_REQUEST | (m_max_segments != BacnetMaxSegments.MAX_SEG0 ? BacnetPduTypes.SEGMENTED_RESPONSE_ACCEPTED : 0), BacnetConfirmedServices.SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0); Services.EncodeAlarmAcknowledge(b, 57, objid, (uint)eventState, AckText, evTimeStamp, ackTimeStamp); //send BacnetAsyncResult ret = new BacnetAsyncResult(this, adr, invoke_id, b.buffer, b.offset - m_client.HeaderLength, wait_for_transmit, m_transmit_timeout); ret.Resend(); return ret; }
// FChaxel public bool AlarmAcknowledgement(BacnetAddress adr, BacnetObjectId objid, BacnetEventNotificationData.BacnetEventStates eventState, String AckText, BacnetGenericTime evTimeStamp, BacnetGenericTime ackTimeStamp, byte invoke_id = 0) { using (BacnetAsyncResult result = (BacnetAsyncResult)BeginAlarmAcknowledgement(adr, objid, eventState, AckText, evTimeStamp, ackTimeStamp, true, invoke_id)) { for (int r = 0; r < m_retries; r++) { if (result.WaitForDone(m_timeout)) { Exception ex; EndAlarmAcknowledgement(result, out ex); if (ex != null) return false; else return true; } if (r < (m_retries - 1)) result.Resend(); } } return false; }