Esempio n. 1
0
        private void LoadProperties()
        {
            RecipientsTab.Controls.Clear();

            // Two properties
            List <BacnetPropertyReference> props = new List <BacnetPropertyReference>();

            props.Add(new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_RECIPIENT_LIST, ASN1.BACNET_ARRAY_ALL));
            props.Add(new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_PRIORITY, ASN1.BACNET_ARRAY_ALL));
            IList <BacnetReadAccessResult> PropertiesValues;

            comm.ReadPropertyMultipleRequest(adr, object_id, props, out PropertiesValues);

            foreach (BacnetPropertyValue aProp in PropertiesValues[0].values)
            {
                // priorities are common to all recipients
                if (aProp.property.propertyIdentifier == (uint)BacnetPropertyIds.PROP_PRIORITY)
                {
                    P_Off.Text    = aProp.value[0].Value.ToString();
                    P_Fault.Text  = aProp.value[1].Value.ToString();
                    P_Normal.Text = aProp.value[2].Value.ToString();
                }
                else
                {
                    // a TabPage in the TabControl for each recipient
                    for (int i = 0; i < aProp.value.Count / 7; i++)
                    {
                        // convert the List<BacnetValue> into a DeviceReportingRecipient
                        DeviceReportingRecipient recipient = new DeviceReportingRecipient(aProp.value[i * 7], aProp.value[i * 7 + 1], aProp.value[i * 7 + 2], aProp.value[i * 7 + 3], aProp.value[i * 7 + 4], aProp.value[i * 7 + 5], aProp.value[i * 7 + 6]);

                        TabPage NewTab = new System.Windows.Forms.TabPage();
                        NewTab.Text = NewTab.Name = i.ToString();

                        // Create a Usercontrol and put it into the TabPage
                        RecipientUserCtrl content = new RecipientUserCtrl(NewTab, recipient);
                        content.DeviceAddrOK += new Action <RecipientUserCtrl, bool>(content_DeviceAddrOK);

                        NewTab.Controls.Add(content);
                        RecipientsTab.Controls.Add(NewTab);

                        labelEmpty.Visible = false;
                    }
                }
            }
        }
Esempio n. 2
0
        private void WriteProperties()
        {
            try // Write Priorities
            {
                List <BacnetValue> PropVal = new List <BacnetValue>();

                PropVal.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, Convert.ToUInt32(P_Off.Text)));
                PropVal.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, Convert.ToUInt32(P_Fault.Text)));
                PropVal.Add(new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, Convert.ToUInt32(P_Normal.Text)));

                comm.WritePropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRIORITY, PropVal);
            }
            catch { }
            try  // Write recipient List
            {
                List <BacnetValue> PropVal = new List <BacnetValue>();
                foreach (TabPage t in RecipientsTab.Controls)
                {
                    if (t.Name != "Not Set") // Entry is OK ?
                    {
                        RecipientUserCtrl        r = (RecipientUserCtrl)t.Controls[0];
                        DeviceReportingRecipient newrp;
                        if (r.adr != null) // recipient is an IP address
                        {
                            newrp = new DeviceReportingRecipient(r.WeekOfDay, r.fromTime.Value, r.toTime.Value, r.adr, Convert.ToUInt16(r.ProcessId.Text), r.AckRequired.Checked, r.EventType);
                        }
                        else // recipient is a deviceId
                        {
                            newrp = new DeviceReportingRecipient(r.WeekOfDay, r.fromTime.Value, r.toTime.Value, new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, r.deviceid), Convert.ToUInt16(r.ProcessId.Text), r.AckRequired.Checked, r.EventType);
                        }

                        PropVal.Add(new BacnetValue(newrp));
                    }
                }

                comm.WritePropertyRequest(adr, object_id, BacnetPropertyIds.PROP_RECIPIENT_LIST, PropVal);
            }
            catch { }
        }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
 public void AddReportingRecipient(DeviceReportingRecipient recipient)
 {
     m_PROP_RECIPIENT_LIST.Add(new BacnetValue(recipient));
 }
Esempio n. 5
0
        /*****************************************************************************************************/
        static void InitDeviceObjects()
        {
            // create the device object with StructuredView acceptation
            device = new DeviceObject(deviceId, "Device test", "A test Device", true);

            // ANALOG_INPUT:0 uint
            // initial value 0
            ana0 = new AnalogInput <double>
                   (
                0,
                "Ana0 Sin double",
                "Ana0 Sin double",
                0,
                BacnetUnitsId.UNITS_AMPERES
                   );
            ana0.m_PROP_HIGH_LIMIT = 50;
            ana0.m_PROP_LOW_LIMIT  = -50;
            ana0.m_PROP_DEADBAND   = 5;
            ana0.Enable_Reporting(true, 0);

            device.AddBacnetObject(ana0);   // don't forget to do this

            // Binary Output
            device.AddBacnetObject(new BinaryOutput(0, "Bin Out", "An output", false));

            // Create A StructuredView
            StructuredView s = new StructuredView(0, "Content", "A View");

            // register it
            device.AddBacnetObject(s);  // don't forget to do this

            BaCSharpObject b;

            // ANALOG_VALUE:0 double with Priority Array
            //
            b = new AnalogValue <double>
                (
                0,
                "Ana0 Double",
                "Ana0 Double",
                5465.23,
                BacnetUnitsId.UNITS_BARS,
                true
                );
            s.AddBacnetObject(b); // Put it in the view

            b.OnWriteNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnWriteNotify);

            // ANALOG_OUTPUT:1 int with Priority Array on Present Value
            b = new AnalogOutput <int>
                (
                1,
                "Ana1 int",
                "Ana1 int",
                (int)56,
                BacnetUnitsId.UNITS_DEGREES_CELSIUS
                );
            s.AddBacnetObject(b); // Put it in the view

            b.OnWriteNotify += new BaCSharpObject.WriteNotificationCallbackHandler(handler_OnWriteNotify);

            // MULTI_STATE_OUTPUT:4 with 6 states
            MultiStateOutput m = new MultiStateOutput
                                 (
                4,
                "MultiStates",
                "MultiStates",
                1,
                6
                                 );

            for (int i = 1; i < 7; i++)
            {
                m.m_PROP_STATE_TEXT[i - 1] = new BacnetValue("Text Level " + i.ToString());
            }

            s.AddBacnetObject(m); // in the view

            StructuredView s2 = new StructuredView(1, "Complex objects", "Complex objects");

            s.AddBacnetObject(s2);

            // TREND_LOG:0 with int values
            // new TrendLog can be changed by new TrendLogCustom
            trend0 = new TrendLog(0, "Trend signed int", "Trend signed int", 200, BacnetTrendLogValueType.TL_TYPE_SIGN);
            s2.AddBacnetObject(trend0); // in the second level view
            // fill Log with more values than the size
            for (int i = 0; i < 300; i++)
            {
                DateTime current = DateTime.Now.AddSeconds(-300 + i);
                if ((i > 200) && (i < 210))   // simulate some errors in the trend
                {
                    trend0.AddValue(new BacnetError(), current, 0, BacnetTrendLogValueType.TL_TYPE_ERROR);
                }
                else
                {
                    trend0.AddValue((int)(i * Math.Sin((float)i / 0.01)), current, 0);
                }
            }

            trend0.AddValue(new BacnetError(), DateTime.Now, 0, BacnetTrendLogValueType.TL_TYPE_ERROR);

            // BACFILE:0
            // File access right me be allowed to the current user
            // for read and for write if any
            b = new BacnetFile
                (
                0,
                "A file",
                "File description",
                "c:\\RemoteObject.xml",
                false
                );
            s2.AddBacnetObject(b); // in the second level view

            NotificationClass nc = new NotificationClass
                                   (
                0,
                "An alarm sender",
                "Alarm description",
                device.PROP_OBJECT_IDENTIFIER
                                   );

            device.AddBacnetObject(nc);

            // Put two elements into the NC recipient List

            // Valid Day
            BacnetBitString week = new BacnetBitString();

            for (int i = 0; i < 7; i++)
            {
                week.SetBit((byte)i, true);                         // Monday to Sunday
            }
            // transition
            BacnetBitString transition = new BacnetBitString();

            transition.SetBit(0, true); // To OffNormal
            transition.SetBit(1, true); // To Fault
            transition.SetBit(2, true); // To Normal

            DeviceReportingRecipient r = new DeviceReportingRecipient
                                         (
                week,                          // week days
                DateTime.MinValue.AddDays(10), // fromTime
                DateTime.MaxValue,             // toTime
                new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, 4000),
                (uint)4,                       // processid
                true,                          // Ack required
                transition                     // transition
                                         );

            nc.AddReportingRecipient(r);

            r = new DeviceReportingRecipient
                (
                week,
                DateTime.MinValue.AddDays(10),
                DateTime.MaxValue,
                new BacnetAddress(BacnetAddressTypes.IP, 0, new Byte[6] {
                255, 255, 255, 255, 0xBA, 0xC0
            }),
                (uint)4,
                true,
                transition
                );

            nc.AddReportingRecipient(r);

            // Create a Schedule
            Schedule sch = new Schedule(0, "Schedule", "Schedule");

            // MUST be added to the device list before modification
            device.AddBacnetObject(sch);

            // a link to the internal analog output
            sch.AddPropertyReference(new BacnetDeviceObjectPropertyReference
                                     (
                                         new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_OUTPUT, 1),
                                         BacnetPropertyIds.PROP_PRESENT_VALUE)
                                     );
            // a link to analog output through the network : could be on another device than itself
            sch.AddPropertyReference(new BacnetDeviceObjectPropertyReference
                                     (
                                         new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_OUTPUT, 1),
                                         BacnetPropertyIds.PROP_PRESENT_VALUE,
                                         new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, 4000))
                                     );

            sch.PROP_SCHEDULE_DEFAULT = (int)452;

            // Schedule a change today in 60 seconds
            sch.AddSchedule
            (
                DateTime.Now.DayOfWeek == 0 ? 6 : (int)DateTime.Now.DayOfWeek - 1, // Monday=0, Sunday=6
                DateTime.Now.AddSeconds(10), (int)900
            );
            sch.PROP_OUT_OF_SERVICE = false;    // needed after all initialization to start the service

            // One empty Calendar, could be fullfill with yabe

            Calendar cal = new Calendar(0, "Test Calendar", "A Yabe calendar");

            device.AddBacnetObject(cal);
        }