// Read start and stop dates validity for the schedule
        private void ReadEffectivePeriod()
        {
            IList <BacnetValue> value;

            try
            {
                if (comm.ReadPropertyRequest(adr, schedule_id, BacnetPropertyIds.PROP_EFFECTIVE_PERIOD, out value))
                {
                    DateTime dt = (DateTime)value[0].Value;
                    if (dt.Ticks != 0)  // it's the way always date (encoded FF-FF-FF-FF) is put into a DateTime struct
                    {
                        TxtStartDate.Text = dt.ToString("d");
                    }
                    else
                    {
                        TxtStartDate.Text = "Always";
                    }

                    dt = (DateTime)value[1].Value;
                    if (dt.Ticks != 0)
                    {
                        TxtEndDate.Text = dt.ToString("d");
                    }
                    else
                    {
                        TxtEndDate.Text = "Always";
                    }
                }
            }
            catch
            {
            }
        }
        public static LightStateEntity GetConfLightState(int?deviceID)
        {
            var bacnetDeviceFromDB = lutronEntities.BACnetDevices
                                     .Where(x => x.device_id == deviceID &&
                                            x.object_instance == (int?)LutronObjectType.Lighting_State)
                                     .Select(x => x).FirstOrDefault();


            IList <BacnetValue> loBacnetValueList;
            BacnetAddress       loBacnetAddress;

            loBacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.network_id);

            loBacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, bacnetDeviceFromDB.routed_source,
                                                             (ushort)bacnetDeviceFromDB.routed_net);
            if (bacNetClient == null)
            {
                bacNetClient = BackNetClientInit.NewBackNetClient();
            }
            bacNetClient.ReadPropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE,
                                                                                 (uint)LutronObjectType.Lighting_State), BacnetPropertyIds.PROP_PRESENT_VALUE, out loBacnetValueList);

            if (loBacnetValueList != null && loBacnetValueList.Count > 0)
            {
                return(new LightStateEntity {
                    DeviceID = (Int32)deviceID, LightState = Convert.ToBoolean(loBacnetValueList.FirstOrDefault().Value)
                });
            }
            else
            {
                return(new LightStateEntity {
                    DeviceID = (Int32)deviceID, LightState = null
                });
            }
        }
        /// <summary>
        /// Toggle Lighting State
        /// </summary>
        /// <param name="fiDeviceID"></param>
        /// <param name="fbToggleStatus"></param>
        private void ToggleLutronLight(int fiDeviceID, bool fbToggleStatus)
        {
            using (var loESDLutronEntities = new ESDLutronEntities())
            {
                var loBACnetDeviceDetail = loESDLutronEntities.BACnetDevices
                                           .Where(x => x.device_id == fiDeviceID &&
                                                  x.object_instance == (int?)LutronObjectType.Lighting_State)
                                           .Select(x => x).FirstOrDefault();

                if (loBACnetDeviceDetail != null && loBACnetDeviceDetail.object_instance != null)
                {
                    BacnetAddress loBacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, loBACnetDeviceDetail.network_id);
                    loBacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, loBACnetDeviceDetail.routed_source, (ushort)loBACnetDeviceDetail.routed_net);

                    IList <BacnetValue> loBacnetValueList;
                    moBacnetClient.ReadPropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_PRESENT_VALUE, out loBacnetValueList);


                    BacnetValue   loBacnetNewValue = new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ENUMERATED, fbToggleStatus == true ? 1 : 0);
                    BacnetValue[] loWriteValue     = { loBacnetNewValue };

                    moBacnetClient.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_PRESENT_VALUE, loWriteValue);

                    //BacnetValue[] loNewBacnetValue = { new BacnetValue(Convert.ToSingle(111)) };

                    ////bacnet_client.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_ACTION, loNewBacnetValue);
                    ////bacnet_client.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0), BacnetPropertyIds.PROP_PRESENT_VALUE, loNewBacnetValue);
                    //bacnet_client.WritePropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, 0), BacnetPropertyIds.PROP_PRESENT_VALUE, loNewBacnetValue);
                }
            }

            //bool ret = WriteScalarValue(1, new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, 2), BacnetPropertyIds.PROP_PRESENT_VALUE, loNewValue);
        }
        /// <summary>
        /// Get current light state for device
        /// </summary>
        /// <param name="fiDeviceID"></param>
        /// <returns></returns>
        private bool GetLutronLightState(Int32 fiDeviceID)
        {
            IList <BacnetValue> loBacnetValueList;

            using (var loESDLutronEntities = new ESDLutronEntities())
            {
                var loBACnetDeviceDetail = loESDLutronEntities.BACnetDevices
                                           .Where(x => x.device_id == fiDeviceID &&
                                                  x.object_type.ToUpper() == LutronFloorObjectType.Lighting_State)
                                           .Select(x => x).FirstOrDefault();


                BacnetAddress loBacnetAddress;
                loBacnetAddress = new BacnetAddress(BacnetAddressTypes.IP, loBACnetDeviceDetail.network_id);
                loBacnetAddress.RoutedSource = new BacnetAddress(BacnetAddressTypes.IP, loBACnetDeviceDetail.routed_source, (ushort)loBACnetDeviceDetail.routed_net);

                moBacnetClient.ReadPropertyRequest(loBacnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_BINARY_VALUE, (uint)loBACnetDeviceDetail.object_instance), BacnetPropertyIds.PROP_PRESENT_VALUE, out loBacnetValueList);
            }

            if (loBacnetValueList != null && loBacnetValueList.Count > 0)
            {
                return(Convert.ToBoolean(Convert.ToInt32(loBacnetValueList[0].Value)));
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
 private BacnetValue ReadScalarValue(BacnetAddress adr, BacnetObjectId oid,
                                     BacnetPropertyIds pid, byte invokeId = 0, uint arrayIndex = uint.MaxValue)
 {
     try
     {
         BacnetValue NoScalarValue = Bacnet_client.ReadPropertyRequest(adr, oid, pid, arrayIndex);
         return(NoScalarValue);
     }
     catch (Exception ex)
     {
         Log("Err:" + ex.Message);
     }
     return(new BacnetValue());
 }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
0
 IList <BacnetValue> ReadScalarValue(BacnetAddress adr, BacnetObjectId oid,
                                     BacnetPropertyIds pid, byte invokeId = 0, uint arrayIndex = uint.MaxValue)
 {
     try
     {
         IList <BacnetValue> NoScalarValue;
         var rst = Bacnet_client.ReadPropertyRequest(adr, oid, pid, out NoScalarValue, invokeId, arrayIndex);
         if (!rst)
         {
             return(null);
         }
         return(NoScalarValue);
     }
     catch { }
     return(null);
 }
Exemplo n.º 8
0
        private void LoadCalendar()
        {
            IList <BacnetValue> values;

            comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DATE_LIST, out values);

            if ((values != null) && (values.Count == 1))
            {
                calendarEntries = (BACnetCalendarEntry)values[0].Value;
            }
            else
            {
                calendarEntries         = new BACnetCalendarEntry(); // empty
                calendarEntries.Entries = new List <object>();
            }

            dateSelect.SelectionRange = new SelectionRange(DateTime.Now, DateTime.Now);

            listEntries.Items.Clear();
            foreach (object e in calendarEntries.Entries)
            {
                listEntries.Items.Add(e);
            }

            //  calendarView will be updated by the calendarView_LoadItems event
            SetCalendarDisplayDate(DateTime.Now);
        }
        private void bacnet_client_OnIam(BacnetClient sender, BacnetAddress adr, uint device_id, uint max_apdu, BacnetSegmentations segmentation, ushort vendor_id)
        {
            this.Invoke((MethodInvoker) delegate
            {
                ListViewItem itm = m_list.Items.Add(adr.ToString());
                itm.Tag          = new KeyValuePair <BacnetAddress, uint>(adr, device_id);
                itm.SubItems.Add("");

                //read name
                IList <BacnetValue> values;
                if (bacnet_client.ReadPropertyRequest(adr, new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, device_id), BacnetPropertyIds.PROP_OBJECT_NAME, out values))
                {
                    itm.SubItems[1].Text = (string)values[0].Value;
                }
            }, null);
        }
Exemplo n.º 10
0
        /*****************************************************************************************************/
        private static bool ReadScalarValue(int device_id, BacnetObjectId bacnetObjet, BacnetPropertyIds propriete, out BacnetValue value)
        {
            BacnetAddress       adr;
            IList <BacnetValue> noScalarValue;

            value = new BacnetValue(null);

            // Looking for the device
            adr = DeviceAddr((uint)device_id);
            if (adr == null)
            {
                return(false);  // not found
            }

            // Property Read
            if (bacnetClient.ReadPropertyRequest(adr, bacnetObjet, propriete, out noScalarValue) == false)
            {
                return(false);
            }

            value = noScalarValue[0];
            return(true);
        }
        // Only for MULTIPLE TREND LOG
        private int ReadNumberofCurves(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            IList <BacnetValue> value;

            try
            {
                if (!comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_LOG_DEVICE_OBJECT_PROPERTY, out value))
                {
                    return(0);
                }
                return(value == null ? 0 : value.Count);
            }
            catch
            {
                return(0);
            }
        }
Exemplo n.º 12
0
        public ScheduleDisplay(ImageList img_List, BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            InitializeComponent();
            this.comm        = comm;
            this.adr         = adr;
            this.schedule_id = object_id;

            // Get the Present_Value data Type, used for new value in the schedule
            // ... replaced if some other values found in the scheduling
            try
            {
                IList <BacnetValue> value;
                comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRESENT_VALUE, out value);

                if ((value != null) && (value.Count != 0) && (value[0].Tag != BacnetApplicationTags.BACNET_APPLICATION_TAG_NULL))
                {
                    ScheduleType = value[0].Tag;
                }
            }
            catch { }


            for (int i = 1; i < 12; i++)
            {
                ScheduleDataType.Items.Add(GetNiceName((BacnetApplicationTags)i));
            }

            ReadEffectivePeriod();
            ReadEffectiveWeeklySchedule();
            ReadExceptionSchedule();
            ReadObjectsPropertiesReferences();

            ToolTip t1 = new ToolTip();

            t1.AutomaticDelay = 0;
            t1.SetToolTip(TxtStartDate, "A wrong value set this to Always");
            ToolTip t2 = new ToolTip();

            t2.AutomaticDelay = 0;
            t2.SetToolTip(TxtEndDate, "A wrong value set this to Always");

            // get the ImageList from MainDialog
            listReferences.SmallImageList = img_List;

            ScheduleDataType.Text = GetNiceName(ScheduleType);
        }
        // PROP_OBJECT_NAME is used, could be PROP_OBJECT_DESCRIPTION maybe
        private string ReadCurveName(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            IList <BacnetValue> value;

            try
            {
                if (!comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_OBJECT_NAME, out value))
                {
                    return("");
                }
                if (value == null || value.Count == 0)
                {
                    return("");
                }
                return(value[0].Value.ToString());
            }
            catch
            {
                return("");
            }
        }
Exemplo n.º 14
0
        public static int ReadFileSize(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            IList <BacnetValue> value;

            try
            {
                if (!comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_FILE_SIZE, out value))
                {
                    return(-1);
                }
                if (value == null || value.Count == 0)
                {
                    return(-1);
                }
                return((int)Convert.ChangeType(value[0].Value, typeof(int)));
            }
            catch
            {
                return(-1);
            }
        }
        // Get the numbers of records in the Log
        private int ReadRangeSize(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            IList <BacnetValue> value;

            try
            {
                if (!comm.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_RECORD_COUNT, out value))
                {
                    return(-1);
                }
                if (value == null || value.Count == 0)
                {
                    return(-1);
                }
                return((int)Convert.ChangeType(value[0].Value, typeof(int)));
            }
            catch
            {
                Trace.TraceError("Couldn't load PROP_RECORD_COUNT from TendLog object");
                return(-1);
            }
        }
Exemplo n.º 16
0
        /*****************************************************************************************************/
        bool ReadScalarValue(int device_id, BacnetObjectId BacnetObjet, BacnetPropertyIds Propriete, out BacnetValue Value)
        {
            BacnetAddress       adr;
            IList <BacnetValue> NoScalarValue;

            Value = new BacnetValue(null);

            // Looking for the device
            adr = DeviceAddr((uint)device_id);
            if (adr == null)
            {
                return(false);              // not found
            }
            // Property Read
            if (bacnet_client.ReadPropertyRequest(adr, BacnetObjet, Propriete, out NoScalarValue) == false)
            {
                return(false);
            }

            Value = NoScalarValue[0];
            return(true);
        }
Exemplo n.º 17
0
        void CheckAllObjects(TreeNodeCollection tncol)
        {
            foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree
            {
                Application.DoEvents();

                BacnetObjectId object_id = (BacnetObjectId)tn.Tag;

                if (Filter.Contains(object_id.type)) // Only for some objects
                {
                    String Identifier = null;

                    lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known
                        yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier);

                    try
                    {
                        IList <BacnetValue> value;
                        // read COV_Increment property on all objects (maybe a test could be done to avoid call without interest)
                        bool   ret       = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_COV_INCREMENT, out value);
                        string Increment = value[0].Value.ToString();

                        if (ret)
                        {
                            string Units = "";
                            try
                            {
                                // read Units property on all objects (maybe a test could be done to avoid call without interest)
                                ret   = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_UNITS, out value);
                                Units = ((BacnetUnitsId)((uint)value[0].Value)).ToString();
                                if (Units.StartsWith("UNITS_"))
                                {
                                    Units = Units.Substring(6);
                                }
                                Units = Units.Replace("_", " ");
                                Units = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Units.ToLower());
                            }
                            catch { };


                            IsEmpty = false;

                            string name = object_id.ToString();
                            if (name.StartsWith("OBJECT_"))
                            {
                                name = name.Substring(7);
                            }

                            TreeNode N;
                            if (Identifier != null)
                            {
                                N = treeView1.Nodes.Add(Identifier + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()) + ")");
                            }
                            else
                            {
                                N = treeView1.Nodes.Add(name);
                            }
                            ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value); // with Description
                            if (ret)
                            {
                                N.Nodes.Add(value[0].Value.ToString());
                            }
                            N.Nodes.Add(("Value = ") + Increment + " " + Units);
                        }
                    }
                    catch
                    {
                    }
                }

                if (tn.Nodes != null)   // go deap into the tree
                {
                    CheckAllObjects(tn.Nodes);
                }
            }
        }
        private void FillTreeNode()
        {
            bool EmptyList = (TAlarmList.Nodes.Count == 0);
            int  icon;

            TAlarmList.BeginUpdate();

            // Only one network read request to get the object name
            int _retries = comm.Retries;

            comm.Retries = 1;

            int Idx = 0;

            // fill the Treenode
            foreach (BacnetGetEventInformationData alarm in Alarms)
            {
                TreeNode currentTn;

                // get or set the Node
                if (EmptyList == true)
                {
                    String nameStr = null;

                    lock (DevicesObjectsName)
                        DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), alarm.objectIdentifier), out nameStr);

                    if (nameStr == null)
                    {
                        // Get the property Name, network activity, time consuming
                        IList <BacnetValue> name;
                        bool retcode = comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_OBJECT_NAME, out name);

                        if (retcode)
                        {
                            nameStr = name[0].Value.ToString();
                            lock (DevicesObjectsName)
                                DevicesObjectsName.Add(new Tuple <String, BacnetObjectId>(adr.FullHashString(), alarm.objectIdentifier), nameStr);
                        }
                    }

                    icon = MainDialog.GetIconNum(alarm.objectIdentifier.type);
                    if (nameStr != null)
                    {
                        currentTn             = new TreeNode(nameStr, icon, icon);
                        currentTn.ToolTipText = alarm.objectIdentifier.ToString();
                    }
                    else
                    {
                        currentTn = new TreeNode(alarm.objectIdentifier.ToString(), icon, icon);
                    }

                    currentTn.Tag = alarm;
                    TAlarmList.Nodes.Add(currentTn);
                }
                else
                {
                    currentTn = TAlarmList.Nodes[Idx++];
                    currentTn.Nodes.Clear();
                }

                if (Properties.Settings.Default.DescriptionInAlarmSummary)
                {
                    String Descr = "";
                    try
                    {
                        // Get the Description, network activity, time consuming
                        IList <BacnetValue> name;
                        bool retcode = comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_DESCRIPTION, out name);

                        if (retcode)
                        {
                            Descr = name[0].Value.ToString();
                        }
                    }
                    catch { }

                    currentTn.Nodes.Add(new TreeNode("Description : " + Descr, Int32.MaxValue, Int32.MaxValue));
                }

                icon = Int32.MaxValue; // out bound
                currentTn.Nodes.Add(new TreeNode("Alarm state : " + GetEventStateNiceName(alarm.eventState.ToString()), icon, icon));

                bool SomeTodo = false;

                TreeNode tn2 = new TreeNode("Ack Required :", icon, icon);
                for (int i = 0; i < 3; i++)
                {
                    if (alarm.acknowledgedTransitions.ToString()[i] == '0')
                    {
                        BacnetEventNotificationData.BacnetEventEnable bee = (BacnetEventNotificationData.BacnetEventEnable)(1 << i);
                        String text = GetEventEnableNiceName(bee.ToString()) + " since " + alarm.eventTimeStamps[i].Time.ToString();
                        tn2.Nodes.Add(new TreeNode(text, icon, icon));
                        SomeTodo = true;
                    }
                }

                if (SomeTodo == false)
                {
                    tn2 = new TreeNode("No Ack Required, already done", icon, icon);
                }
                currentTn.Nodes.Add(tn2);
            }

            // set back the request retries number
            comm.Retries = _retries;

            TAlarmList.EndUpdate();

            TAlarmList.ExpandAll();

            if (Alarms.Count == 0)
            {
                LblInfo.Visible = true;
                LblInfo.Text    = "Empty event list ... all is OK";
            }
        }
Exemplo n.º 19
0
        void CheckAllObjects(TreeNodeCollection tncol)
        {
            foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree
            {
                Application.DoEvents();

                BacnetObjectId object_id = (BacnetObjectId)tn.Tag;

                String Identifier = null;

                lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known
                    yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier);

                try
                {
                    IList <BacnetValue> value;
                    // read OutOfService property on all objects (maybe a test could be done to avoid call without interest)
                    bool ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_OUT_OF_SERVICE, out value);

                    // another solution with ReadPropertyMultipleRequest, but not supported by simple devices
                    // ... can also read these two properties on all objects in one time (with segmentation on huge devices)

                    /*
                     * BacnetReadAccessSpecification[] bras = new BacnetReadAccessSpecification[1];
                     * bras[0].objectIdentifier = object_id;
                     * bras[0].propertyReferences = new BacnetPropertyReference[2];
                     * bras[0].propertyReferences[0] = new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_RELIABILITY, ASN1.BACNET_ARRAY_ALL);
                     * bras[0].propertyReferences[1] = new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_DESCRIPTION, ASN1.BACNET_ARRAY_ALL);
                     * IList<BacnetReadAccessResult> res;
                     * ret=client.ReadPropertyMultipleRequest(adr, bras, out res); // it's a read multiple properties on multiple objects
                     * value = res[0].values[0].value; // for PROP_RELIABILITY
                     * value = res[0].values[1].value; // for PROP_DESCRIPTION
                     */

                    if (ret)
                    {
                        if ((bool)value[0].Value != false) // different than FALSE
                        {
                            IsEmpty = false;

                            string name = object_id.ToString();
                            if (name.StartsWith("OBJECT_"))
                            {
                                name = name.Substring(7);
                            }

                            TreeNode N;
                            if (Identifier != null)
                            {
                                N = treeView1.Nodes.Add(Identifier + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()) + ")");
                            }
                            else
                            {
                                N = treeView1.Nodes.Add(name);
                            }

                            string reliability = ((BacnetReliability)value[0].Value).ToString();
                            reliability = reliability.Replace('_', ' ');
                            reliability = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(reliability.ToLower());

                            N.Nodes.Add(reliability);
                            N.Nodes.Add(name);


                            // PROP_DESCRIPTION
                            //... if ReadPropertyMultipleRequest uses value = res[0].values[1].value

                            /*
                             * ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value); // with Description
                             * if (ret)
                             *  N.Nodes.Add(value[0].Value.ToString());
                             */
                        }
                    }
                }
                catch
                {
                }

                if (tn.Nodes != null)   // go deap into the tree
                {
                    CheckAllObjects(tn.Nodes);
                }
            }
        }
        /// <summary>
        /// Adds bacnet device details.
        /// </summary>
        private static void AddBackNetDeviceDetail()
        {
            if (bacNetDeviceModel != null && bacNetDeviceModel.BACnetDeviceList != null)
            {
                List <BACnetDevice>        bACnetDeviceLst        = new List <BACnetDevice>();
                List <BACnetDeviceMapping> bACnetDeviceMappingLst = new List <BACnetDeviceMapping>();
                foreach (var deviceDetail in bacNetDeviceModel.BACnetDeviceList)
                {
                    IList <BacnetValue> objValueLst;
                    if (bacNetClient == null)
                    {
                        bacNetClient = BackNetClientInit.NewBackNetClient();
                    }
                    bacNetClient.ReadPropertyRequest(deviceDetail.BacNetAddress,
                                                     new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, deviceDetail.DeviceId),
                                                     BacnetPropertyIds.PROP_OBJECT_LIST, out objValueLst);
                    if (objValueLst == null)
                    {
                        continue;
                    }
                    foreach (var objValue in objValueLst)
                    {
                        var isExistNetworkId = CheckIfExistNetworkAddress(deviceDetail.BacNetAddress.ToString(),
                                                                          (int)((BacnetObjectId)objValue.Value).Instance, (int)deviceDetail.DeviceId
                                                                          , ((BacnetObjectId)objValue.Value).Type.ToString());
                        if (isExistNetworkId == true)
                        {
                            continue;
                        }
                        IList <BacnetValue> objNameList;
                        bacNetClient.ReadPropertyRequest(deviceDetail.BacNetAddress,
                                                         new BacnetObjectId((BacnetObjectTypes)((BacnetObjectId)objValue.Value).Type,
                                                                            ((BacnetObjectId)objValue.Value).Instance),
                                                         BacnetPropertyIds.PROP_OBJECT_NAME, out objNameList);
                        if (deviceDetail.BacNetAddress.RoutedSource != null && deviceDetail.BacNetAddress.RoutedSource.net != null)
                        {
                            var bacNetdevice = new BACnetDevice
                            {
                                device_id       = Convert.ToInt32(deviceDetail.DeviceId),
                                network_id      = deviceDetail.BacNetAddress.ToString(),
                                object_type     = ((BacnetObjectId)objValue.Value).type.ToString(),
                                object_instance = Convert.ToInt32(((BacnetObjectId)objValue.Value).Instance.ToString()),
                                object_name     = objNameList != null && objNameList.Count > 0 ? objNameList[0].Value.ToString() : null,
                                routed_source   = deviceDetail.BacNetAddress.RoutedSource.ToString(),
                                routed_net      = deviceDetail.BacNetAddress.RoutedSource.net
                            };
                            bACnetDeviceLst.Add(bacNetdevice);
                        }
                        int?suiteID = null, roomID = null;
                        var objName = Enum.GetName(typeof(LutronFloorObjectType), LutronFloorObjectType.OBJECT_ANALOG_VALUE).ToString();
                        if (((BacnetObjectId)objValue.Value).type.ToString().ToUpper() == objName)
                        {
                            if (Convert.ToInt32(((BacnetObjectId)objValue.Value).Instance.ToString()) < 4)
                            {
                                suiteID = 1;
                            }
                            else
                            {
                                suiteID = 2;
                            }

                            roomID = Convert.ToInt32(((BacnetObjectId)objValue.Value).Instance.ToString());
                        }
                        var bACnetDeviceMapping = new BACnetDeviceMapping
                        {
                            device_id       = Convert.ToInt32(deviceDetail.DeviceId),
                            floor_id        = Convert.ToInt32(deviceDetail.DeviceId),
                            suite_id        = suiteID,
                            room_id         = roomID,
                            object_instance = Convert.ToInt32(((BacnetObjectId)objValue.Value).Instance.ToString())
                        };
                        bACnetDeviceMappingLst.Add(bACnetDeviceMapping);
                    }
                }

                if (bACnetDeviceLst.Count() > 0)
                {
                    AddBacNetDeviceDetail(bACnetDeviceLst);
                }
                if (bACnetDeviceMappingLst.Count() > 0)
                {
                    AddBacNetMappingDetail(bACnetDeviceMappingLst);
                }
            }
        }
Exemplo n.º 21
0
        void CheckAllObjects(TreeNodeCollection tncol)
        {
            foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree
            {
                Application.DoEvents();

                BacnetObjectId object_id = (BacnetObjectId)tn.Tag;

                String Identifier = null;

                lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known
                    yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier);

                try
                {
                    IList <BacnetValue> value;
                    // read PROP_STATUS_FLAGS property on all objects (maybe a test could be done to avoid call without interest)
                    bool ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_STATUS_FLAGS, out value);

                    if (ret)
                    {
                        if (value[0].Value.ToString() != "0000") // some flags are set
                        {
                            IsEmpty = false;

                            string name = object_id.ToString();
                            if (name.StartsWith("OBJECT_"))
                            {
                                name = name.Substring(7);
                            }

                            TreeNode N;
                            if (Identifier != null)
                            {
                                N = treeView1.Nodes.Add(Identifier + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()) + ")");
                            }
                            else
                            {
                                N = treeView1.Nodes.Add(name);
                            }

                            N.SelectedImageIndex = N.ImageIndex = 4;

                            // Get the description
                            IList <BacnetValue> value_descr;
                            ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value_descr);
                            if (ret)
                            {
                                N.Nodes.Add(new TreeNode(value_descr[0].Value.ToString(), 5, 5));
                            }

                            for (int i = 0; i < 4; i++)
                            {
                                if (value[0].Value.ToString()[i] == '1')
                                {
                                    String s   = Enum.GetName(typeof(BacnetStatusFlags), 1 << i).Replace("_", " ");
                                    string alm = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower());
                                    N.Nodes.Add(new TreeNode(alm.Substring(12), i, i));
                                }
                            }
                        }
                    }
                }
                catch
                {
                }

                if (tn.Nodes != null)   // go deap into the tree
                {
                    CheckAllObjects(tn.Nodes);
                }
            }
        }
Exemplo n.º 22
0
        void CheckAllObjects(TreeNodeCollection tncol)
        {
            foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree
            {
                Application.DoEvents();
                BacnetObjectId object_id = (BacnetObjectId)tn.Tag;
                if (Filter.Contains(object_id.type)) // Only for some objects
                {
                    String Identifier = null;
                    lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known
                        yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier);
                    try
                    {
                        IList <BacnetValue> value;
                        bool   ret           = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRESENT_VALUE, out value); // with PRESENT_VALUE
                        string Present_Value = value[0].Value.ToString();
                        float  PresentValue  = float.Parse(Present_Value);
                        ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value);        // with Description
                        string Description = value[0].Value.ToString();
                        ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_RELINQUISH_DEFAULT, out value); // with Relinquish_Default
                        string Relinquish_Default = value[0].Value.ToString();
                        float  RelinquishDefault  = float.Parse(Relinquish_Default);

                        if (ret)
                        {
                            //   IsEmpty = false;
                            string name = object_id.ToString();
                            if (name.StartsWith("OBJECT_"))
                            {
                                name = name.Substring(7);
                            }
                            string[] name1          = name.Split(new Char[] { ':' });
                            int      InstanceNumber = Int32.Parse(name1[1]);


                            {
                                ListAnalogValues.AutoSizeColumnsMode       = DataGridViewAutoSizeColumnsMode.DisplayedCells;
                                ListAnalogValues.EnableHeadersVisualStyles = false;
                                ListAnalogValues.EnableHeadersVisualStyles = false;
                                ListAnalogValues.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue;
                                ListAnalogValues.DefaultCellStyle.BackColor = Color.White;
                                // Create a new row first as it will include the columns you've created at design-time.
                                int rowId = ListAnalogValues.Rows.Add();

                                // Grab the new row!
                                { DataGridViewRow row = ListAnalogValues.Rows[rowId];
                                  if (Identifier != null)
                                  // Add the data
                                  {
                                      row.Cells["Column1"].Value = Identifier;
                                      row.Cells["Column2"].Value = name1[0];
                                      row.Cells["Column3"].Value = InstanceNumber;
                                      row.Cells["Column4"].Value = Description;
                                      row.Cells["Column5"].Value = PresentValue;
                                      row.Cells["Column6"].Value = RelinquishDefault;
                                  }
                                  else
                                  {
                                      row.Cells["Column1"].Value = "";
                                  }
                                  row.Cells["Column2"].Value = name1[0];
                                  row.Cells["Column3"].Value = InstanceNumber;
                                  row.Cells["Column4"].Value = Description;
                                  row.Cells["Column5"].Value = PresentValue;
                                  row.Cells["Column6"].Value = RelinquishDefault; }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                if (tn.Nodes != null)   // go deap into the tree
                {
                    CheckAllObjects(tn.Nodes);
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Get all object & object's instance detail of available devices
        /// Insert network, device, object & object's instance into DB
        /// </summary>
        static void InsertBACnetDeviceDetailInDB()
        {
            if (loBACnetDeviceModel != null && loBACnetDeviceModel.loBACnetDeviceList.Count > 0)
            {
                using (var loESDLutronEntities = new ESDLutronEntities())
                {
                    //// Declare list to instert device in DB
                    List <BACnetDevice>        loInsertBACnetDeviceList    = new List <BACnetDevice>();
                    List <BACnetDeviceMapping> loInsertBACnetDeviceMapping = new List <BACnetDeviceMapping>();

                    //// Remove all exists device on each application run
                    loESDLutronEntities.BACnetDevices.RemoveRange(loESDLutronEntities.BACnetDevices.AsEnumerable());
                    loESDLutronEntities.BACnetDeviceMappings.RemoveRange(loESDLutronEntities.BACnetDeviceMappings.AsEnumerable());

                    foreach (var loBacnetDevice in loBACnetDeviceModel.loBACnetDeviceList)
                    {
                        //// Get all bacnet object available for device
                        IList <BacnetValue> loObjectValueList;
                        moBacnetClient.ReadPropertyRequest(loBacnetDevice.loBACnetAddress, new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, loBacnetDevice.inDeviceID), BacnetPropertyIds.PROP_OBJECT_LIST, out loObjectValueList);

                        foreach (BacnetValue loObjectValue in loObjectValueList)
                        {
                            //// Get each object's instance details and object name to store in DB
                            IList <BacnetValue> loObjectNameList;
                            moBacnetClient.ReadPropertyRequest(loBacnetDevice.loBACnetAddress,
                                                               new BacnetObjectId((BacnetObjectTypes)((BacnetObjectId)loObjectValue.Value).Type, ((BacnetObjectId)loObjectValue.Value).Instance),
                                                               BacnetPropertyIds.PROP_OBJECT_NAME, out loObjectNameList);

                            //string lsObjectType = ((BacnetObjectId)loObjectValue.Value).type.ToString();
                            //string lsObjectInstanceNumber = ((BacnetObjectId)loObjectValue.Value).Instance.ToString();

                            //// add to entity model for DB bulk insert
                            loInsertBACnetDeviceList.Add(
                                new BACnetDevice
                            {
                                network_id      = loBacnetDevice.loBACnetAddress.ToString(),
                                device_id       = Convert.ToInt32(loBacnetDevice.inDeviceID),
                                object_type     = ((BacnetObjectId)loObjectValue.Value).type.ToString(),
                                object_instance = Convert.ToInt32(((BacnetObjectId)loObjectValue.Value).Instance.ToString()),
                                object_name     = loObjectNameList != null && loObjectNameList.Count > 0 ? loObjectNameList[0].Value.ToString() : null,
                                routed_source   = loBacnetDevice.loBACnetAddress.RoutedSource.ToString(),
                                routed_net      = loBacnetDevice.loBACnetAddress.RoutedSource.net
                            });

                            int?liSuiteID = null, liRoomID = null;

                            if (((BacnetObjectId)loObjectValue.Value).type.ToString().ToUpper() == "OBJECT_ANALOG_VALUE")
                            {
                                if (Convert.ToInt32(((BacnetObjectId)loObjectValue.Value).Instance.ToString()) < 4)
                                {
                                    liSuiteID = 1;
                                }
                                else
                                {
                                    liSuiteID = 2;
                                }

                                liRoomID = Convert.ToInt32(((BacnetObjectId)loObjectValue.Value).Instance.ToString());
                            }

                            loInsertBACnetDeviceMapping.Add(
                                new BACnetDeviceMapping
                            {
                                device_id       = Convert.ToInt32(loBacnetDevice.inDeviceID),
                                object_instance = Convert.ToInt32(((BacnetObjectId)loObjectValue.Value).Instance.ToString()),
                                floor_id        = Convert.ToInt32(loBacnetDevice.inDeviceID),
                                suite_id        = liSuiteID,
                                room_id         = liRoomID,
                            });
                        }
                    }

                    //// Insert into DB (table: BACnetDevices)
                    if (loInsertBACnetDeviceList != null && loInsertBACnetDeviceList.Count > 0)
                    {
                        loESDLutronEntities.BACnetDevices.AddRange(loInsertBACnetDeviceList);
                        loESDLutronEntities.BACnetDeviceMappings.AddRange(loInsertBACnetDeviceMapping);
                        loESDLutronEntities.SaveChanges();
                    }
                }
            }
        }