public BACnetObject GetBacnetObjectOrDeviceObject(NameValueCollection bacnetNodeData)
        {
            try
            {
                BACnetObject bno = null;
                if (bacnetNodeData["node_type"] == "device")
                {
                    var d = GetBacnetDevice(bacnetNodeData);//, true);  //still bug in this, somehow...
                    if (d != null)
                    {
                        bno = d.DeviceObject;
                    }


                    //for now, just have to refresh when getting anything device or above...since network, globalnetwork may be null
                }
                else
                {
                    bno = GetBacnetObject(bacnetNodeData);//, true);
                }

                return(bno);
            }

            catch (Exception ex)
            {
                Instance.hspi.Log("BACnetDevice Exception in GetBacnetObjectOrDeviceObject " + ex.Message, 2);

                Console.WriteLine("Exception in GetBacnetObject: " + ex.StackTrace);
                return(null);

                //ModbusConfHtml.add("Error: ", "Could not connect to device to retrieve object properties.  Please make sure that the BACnet device is present on the network.");
            }
        }
Пример #2
0
        private void Initialize(BACnetObject bno, BacnetPropertyIds property_id)
        {
            this.BacnetObject     = bno;
            this.BacnetPropertyId = property_id;        //this is how these are indexed within the object

            this.Id = (Int32)property_id;
            SetName();
        }
Пример #3
0
        public BACnetProperty(BACnetObject bno, BacnetPropertyIds property_id)
        {
            Initialize(bno, property_id);
            ReadValue();
            ParseValue();

            //if (property_value = null)
            //    ReadProperty();
        }
Пример #4
0
        public void AddObject(BacnetObjectId boi, BACnetObject bo)
        {
            if (!BACnetDevice.SupportedObjectTypes.Contains(boi.Type))
            {
                return;
            }

            if (boi.Type == BacnetObjectTypes.OBJECT_DEVICE)
            {
                this.DeviceObject = bo;
            }

            var kvp = new KeyValuePair <BacnetObjectId, BACnetObject>(boi, bo);

            BacnetObjects.Add(kvp);
        }
 public void AddObject(BACnetObject bo)
 {
     this.bacnetObjects.Add(bo);
 }
Пример #6
0
        //public Boolean TryGetProperty(BacnetObjectId boi, out BACnetObject bo)
        //{
        //    bo = null;
        //    foreach (var kvp in BacnetObjects)
        //    {
        //        if (kvp.Key.Equals(boi))
        //        {
        //            bo = kvp.Value;
        //            return true;
        //        }
        //    }
        //    return false;
        //}



        //TODO: shouldn't be adding objects to objects anymore, with current structure.

        public void AddObject(BacnetObjectId boi, BACnetObject bo)
        {
            var kvp = new KeyValuePair <BacnetObjectId, BACnetObject>(boi, bo);

            Objects.Add(kvp);
        }
Пример #7
0
 public BACnetProperty(BACnetObject bno, BacnetPropertyIds property_id, BacnetPropertyValue property_value) //, uint array_index = System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL) //this(bno, property_id, array_index)
 {
     Initialize(bno, property_id);
     this.BacnetPropertyValue = property_value;
     ParseValue();
 }
Пример #8
0
        //for this device, get its properties, and all object names

        public void GetObjects()
        {
            DeviceObject = null;
            BacnetObjects.Clear();
            ObjectsFetched = false;

            //AsynchRequestId++; // disabled a possible thread pool work (update) on the AddressSpaceTree

            //TODO: not sure if this should be kept at a device level or network level?

            var comm = BacnetNetwork.BacnetClient;
            var adr  = BacnetAddress;

            //BacnetAddress adr = entry.Value.Key;
            //uint device_id = entry.Value.Value;

            //unconfigured MSTP?
            if (comm.Transport is BacnetMstpProtocolTransport && ((BacnetMstpProtocolTransport)comm.Transport).SourceAddress == -1)
            {
                //if (MessageBox.Show("The MSTP transport is not yet configured. Would you like to set source_address now?", "Set Source Address", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) return;

                ////find suggested address
                //byte address = 0xFF;
                //BacnetDeviceLine line = m_devices[comm];
                //lock (line.mstp_sources_seen)
                //{
                //    foreach (byte s in line.mstp_pfm_destinations_seen)
                //    {
                //        if (s < address && !line.mstp_sources_seen.Contains(s))
                //            address = s;
                //    }
                //}

                ////display choice
                //SourceAddressDialog dlg = new SourceAddressDialog();
                //dlg.SourceAddress = address;
                //if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel) return;
                //((BacnetMstpProtocolTransport)comm.Transport).SourceAddress = dlg.SourceAddress;
                //Application.DoEvents();     //let the interface relax
            }

            //update "address space"?
            //this.Cursor = Cursors.WaitCursor;
            //Application.DoEvents();
            //int old_timeout = comm.Timeout;


            IList <BacnetValue> value_list = null;

            try
            {
                //fetch structured view if possible
                //if (Yabe.Properties.Settings.Default.DefaultPreferStructuredView)
                //value_list = FetchStructuredObjects();

                //fetch normal list
                if (value_list == null)
                {
                    value_list = FetchObjects() ?? FetchObjectsOneByOne();          //TODO: if this is the case, then we need to handle it once the value list returns populated...
                }
                if (value_list == null)
                {
                    return;
                }

                List <BacnetObjectId> objectList = BACnetObject.SortBacnetObjects(value_list);
                //add to tree
                foreach (BacnetObjectId bobj_id in objectList)      //this will include sub-objects (analog_value, etc.) as well as object representing device itself.
                {
                    var bacnetObject = new BACnetObject(this, bobj_id);



                    AddObject(bobj_id, bacnetObject);


                    //AddObjectEntry(comm, adr, null, bobj_id, m_AddressSpaceTree.Nodes);//AddObjectEntry(comm, adr, null, bobj_id, e.Node.Nodes);
                }
            }
            finally
            {
                //this.Cursor = Cursors.Default;
                //m_DataGrid.SelectedObject = null;
            }

            ObjectsFetched = true;
        }