예제 #1
0
        public ReadPropertyAck(byte[] apdu)
        {
            InvokeId = apdu[1];
            int len = 3;
            //Object tag
            BacNetTag objectIdTag = new BacNetTag(apdu, len, ref len);

            if (objectIdTag.Class == false)
            {
                throw new Exception("Reject.Invalid_tag");
            }
            Obj = new BacNetObject(apdu, len, ref len);
            //Property Id
            BacNetTag propertyIdTag = new BacNetTag(apdu, len, ref len);

            if (propertyIdTag.Number != 1)
            {
                throw new Exception("Reject.Invalid_tag");
            }
            BacNetUInt PropertyId = new BacNetUInt(apdu, len, propertyIdTag.Length, ref len);
            BacNetTag  openingTag = new BacNetTag(apdu, len, ref len);
            ArrayList  ValueList  = new ArrayList();

            if (openingTag.Length == 6)
            {
                BacNetTag metaTag = new BacNetTag(apdu, len, ref len);
                while (metaTag.Length != 7)
                {
                    if (metaTag.Class == false)
                    {
                        object value = ByteConverter.GetAppTagValue(apdu, len, metaTag, ref len);
                        ValueList.Add(value);
                    }
                    else
                    {
                        if (metaTag.Length == 6 && PropertyId.Value == (int)BacNetEnums.BACNET_PROPERTY_ID.PROP_WEEKLY_SCHEDULE)
                        {
                            var value = BuildScheduleDay(apdu, ref len);
                            ValueList.Add(value);
                        }
                        if (metaTag.Length == 4 && metaTag.Number == 0 && PropertyId.Value == (int)BacNetEnums.BACNET_PROPERTY_ID.PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES)
                        {
                            var value = BuildObjectPropertyReference(apdu, ref len);
                            ValueList.Add(value);
                        }
                    }
                    metaTag = new BacNetTag(apdu, len, ref len);
                }
            }
            var property = new BacNetProperty {
                PropertyId = PropertyId, Values = ValueList
            };

            Obj.Properties.Add(property);
        }
예제 #2
0
파일: Form1.cs 프로젝트: zenglc/BACsharp
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     listBox2.Items.Clear();
     if (listBox1.SelectedIndex >= 0 && listBox1.SelectedItem is uint)
     {
         ushort         instance = Convert.ToUInt16(listBox1.SelectedItem);
         BacNetProperty property = _device.Services.Confirmed.ReadProperty(instance + ".DEV" + instance, BacNetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST);
         if (property != null)
         {
             foreach (var value in property.Values)
             {
                 BacNetObject obj = value as BacNetObject;
                 if (obj == null)
                 {
                     continue;
                 }
                 listBox2.Items.Add(obj);
             }
         }
         var objList      = new List <BacNetObject>();
         var nameProperty = new BacNetProperty {
             PropertyId = new BacNetUInt {
                 Value = (uint)BacNetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_NAME
             }
         };
         var valueProperty = new BacNetProperty {
             PropertyId = new BacNetUInt {
                 Value = (uint)BacNetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE
             }
         };
         for (int i = 0; i < listBox2.Items.Count && i < 30; i++)
         {
             objList.Add(listBox2.Items[i] as BacNetObject);
             objList[objList.Count - 1].Properties = new List <BacNetProperty> {
                 nameProperty, valueProperty
             };
         }
         List <BacNetObject> objectsWithValues = _device.Services.Confirmed.Rpm(instance, objList);
         listBox3.Items.Clear();
         foreach (var objectWithValues in objectsWithValues)
         {
             if (objectWithValues != null)
             {
                 listBox3.Items.Add(objectWithValues);
             }
         }
     }
 }
예제 #3
0
파일: Form1.cs 프로젝트: zenglc/BACsharp
        private void readPropertyButton_Click(object sender, EventArgs e)
        {
            /*ArrayList objectList = new ArrayList();
             * ArrayList propertyList = new ArrayList();
             * BacNetObject obj = new BacNetObject { ObjectId = 2, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_ANALOG_VALUE };
             * objectList.Add(obj);
             * BacNetProperty property = new BacNetProperty { PropertyId = new BacNetUInt { Value = (uint)BacNetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE }, Values = new ArrayList() };
             * propertyList.Add(property);
             * _device.Services.Confirmed.Rpm(502, objectList, propertyList);*/
            var property = new BacNetProperty {
                PropertyId = new BacNetUInt {
                    Value = (uint)BacNetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST
                }
            };
            var obj = new BacNetObject {
                ObjectId = 500, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_DEVICE
            };
            var objList = new List <BacNetObject> {
                obj
            };

            _device.Services.Confirmed.ReadProperty("500.DEV500", BacNetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST);
            _device.Services.Confirmed.ReadProperty("500.DEV500", BacNetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_LIST);
            //objList[0].Properties.Add(property);

            /*objList.Add(new BacNetObject { ObjectId = 212, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_ANALOG_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 1212, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_ANALOG_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 1, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_ANALOG_VALUE, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 999, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_ANALOG_VALUE, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 1000, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_ANALOG_VALUE, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 104, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 108, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 109, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 111, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 204, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 208, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_INPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 101, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_OUTPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 103, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_OUTPUT, Properties = new List<BacNetProperty> { property } });
             * objList.Add(new BacNetObject { ObjectId = 104, ObjectType = BacNetEnums.BACNET_OBJECT_TYPE.OBJECT_BINARY_OUTPUT, Properties = new List<BacNetProperty> { property } });*/
            //_device.Services.Confirmed.RpmE(17811, objList, RpmECallBack);
        }
예제 #4
0
        private List <BacNetProperty> ReadProperties(byte[] apdu, int startIndex, uint objectId, ref int len)
        {
            List <BacNetProperty> res = new List <BacNetProperty>();
            var openingTag            = new BacNetTag(apdu, len, ref len);

            if (openingTag.Length == 6 && openingTag.Number == 1)
            {
                BacNetTag metaTag = new BacNetTag(apdu, len, ref len);
                while ((metaTag.Length != 7 || metaTag.LongTag) && metaTag.Number != 1)
                {
                    var            propertyId = new BacNetUInt(apdu, len, metaTag.Length, ref len);
                    BacNetProperty prop       = new BacNetProperty {
                        PropertyId = propertyId
                    };
                    prop.Values = ReadValues(apdu, len, ref len);
                    res.Add(prop);
                    metaTag = new BacNetTag(apdu, len, ref len);
                }
            }
            return(res);
        }
예제 #5
0
        public BacNetProperty ReadProperty(string address, BacNetEnums.BACNET_PROPERTY_ID propId = BacNetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE)
        {
            string[] addrArray = address.Split('.');
            if (addrArray.Length != 2)
            {
                _logger.Warn("Wrong address: " + address);
                return(null);
            }

            BacNetRemoteDevice remote = BacNetDevice.Instance.SearchRemote(BacNetRemoteDevice.Get(addrArray[0]));

            if (remote == null)
            {
                return(null);
            }

            BacNetObject tmpObj;

            try
            {
                tmpObj = new BacNetObject(addrArray[1]);
            }
            catch (Exception ex)
            {
                _logger.Warn(ex.Message);
                return(new BacNetProperty
                {
                    PropertyId = new BacNetUInt {
                        Value = (uint)propId
                    },
                    Values = new ArrayList {
                        new BacNetString("Error")
                    }
                });
                //return null;
            }

            BacNetObject obj = remote.Objects.FirstOrDefault(s => s.ObjectId == tmpObj.ObjectId && s.ObjectType == tmpObj.ObjectType);

            if (obj == null)
            {
                remote.Objects.Add(tmpObj);
                obj = tmpObj;
            }
            var apdu = new ReadProperty(obj, propId);
            var npdu = new BacNetIpNpdu {
                ExpectingReply = true, Destination = remote.BacAddress
            };

            BacNetDevice.Instance.Waiter = apdu.InvokeId;
            BacNetDevice.Instance.Services.Execute(npdu, apdu, remote.EndPoint);
            ArrayList valueList = WaitForResponce(apdu.InvokeId) as ArrayList;

            BacNetProperty property = obj.Properties.FirstOrDefault(s => s.PropertyId.Value == (uint)propId);

            if (property != null)
            {
                property.Values = valueList ?? new ArrayList();
            }
            else
            {
                property = new BacNetProperty {
                    PropertyId = new BacNetUInt {
                        Value = (uint)propId
                    }, Values = valueList ?? new ArrayList()
                };
                obj.Properties.Add(property);
            }
            return(property);
        }