Exemplo n.º 1
0
 public BaCSharpObject(BacnetObjectId ObjId, string ObjName, string Description)
 {
     m_PROP_OBJECT_IDENTIFIER = ObjId;
     m_PROP_OBJECT_NAME       = ObjName;
     m_PROP_OBJECT_TYPE       = (uint)ObjId.Type;
     m_PROP_DESCRIPTION       = Description;
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("BBMD Demo Application started on 0xBAC0 Udp port\n\nAll foreign devices accepted (no filtering)\n");

            // start the FD acceptation at least if BBMD list is empty or corrupted
            // and set up the device, see BacnetActivity static constructor
            BacnetActivity.AddPeerBBMD(null, null);

            if (BacnetActivity.OpenError == true)
            {
                Console.WriteLine("\t Error, certainly due to the Udp Port already in use");
                return;
            }

            // Set BBMD peers
            SetBBMDList();

            // Update each 10s the second CHARACTERSTRING OBJECT Present Value
            BacnetObjectId b = new BacnetObjectId(BacnetObjectTypes.OBJECT_CHARACTERSTRING_VALUE, 1);

            for ( ; ;)
            {
                Thread.Sleep(10000);
                BacnetActivity.SetBacObjectPresentValue(b, new BacnetValue(BacnetActivity.GetFDList()));
            }
        }
Exemplo n.º 3
0
        static void SetBBMDList()
        {
            StringBuilder BBMDList = new StringBuilder();

            // Read the BBMD Peer List from the Config.txt file
            try
            {
                StreamReader sr = new StreamReader("Config.txt");
                while (!sr.EndOfStream)
                {
                    String l = sr.ReadLine();

                    if ((l.Length != 0) && (l[0] != '/'))
                    {
                        String[] Param = l.Split(';');

                        BacnetActivity.AddPeerBBMD(new IPEndPoint(IPAddress.Parse(Param[0]), Convert.ToInt32(Param[2])), IPAddress.Parse(Param[1]));

                        BBMDList.Append(Param[0] + ":" + Param[2] + ";");

                        Console.WriteLine("\tWorking with peer BBMD : {0}:{1}", Param[0], Param[2]);
                    }
                }
                sr.Close();
            }
            catch { }

            // Update the first CHARACTERSTRING OBJECT Present Value
            BacnetObjectId b = new BacnetObjectId(BacnetObjectTypes.OBJECT_CHARACTERSTRING_VALUE, 0);

            BacnetActivity.SetBacObjectPresentValue(b, new BacnetValue(BBMDList.ToString()));
        }
Exemplo n.º 4
0
        private void SetRef_Click(object sender, EventArgs e)
        {
            BacnetObjectId b;
            BacnetValue    bv;

            for (int i = 0; i < 3; i++)
            {
                if (sender != Bts[i])
                {
                    Bts[i].BackColor = SystemColors.Control;
                    Lbs[i].ForeColor = SystemColors.ControlDark;
                }
                else
                {
                    NiveauChoisi     = i;
                    Bts[i].BackColor = Color.Red;
                    Lbs[i].ForeColor = SystemColors.ControlText;
                    if (Remoteconsigne == false)
                    {
                        b  = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, (uint)(NiveauChoisi + 1));
                        bv = BacnetActivity.GetBacObjectPresentValue(b);
                        BacnetActivity.SetBacObjectPresentValue(Bac_ConsigneTemp, bv);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void UpdateIhm()
        {
            BacnetObjectId b;
            BacnetValue    bv;
            float          f;

            // Les labels associés aux Bp pour choisir la temperature
            b              = new BacnetObjectId(BacnetObjectTypes.OBJECT_CHARACTERSTRING_VALUE, 1);
            bv             = BacnetActivity.GetBacObjectPresentValue(b);
            Set1Label.Text = (string)bv.Value;
            b              = new BacnetObjectId(BacnetObjectTypes.OBJECT_CHARACTERSTRING_VALUE, 2);
            bv             = BacnetActivity.GetBacObjectPresentValue(b);
            Set2Label.Text = (string)bv.Value;
            b              = new BacnetObjectId(BacnetObjectTypes.OBJECT_CHARACTERSTRING_VALUE, 3);
            bv             = BacnetActivity.GetBacObjectPresentValue(b);
            Set3Label.Text = (string)bv.Value;

            // Les temperatures

            bv           = BacnetActivity.GetBacObjectPresentValue(Bac_TempInt);
            f            = (float)bv.Value;
            TempInt.Text = TempDegre2Text(f);

            bv           = BacnetActivity.GetBacObjectPresentValue(Bac_ConsigneTemp);
            f            = (float)bv.Value;
            TempSet.Text = "T Set : " + f.ToString() + "°";

            bv           = BacnetActivity.GetBacObjectPresentValue(Bac_TempExterieure);
            f            = (float)bv.Value;
            TempExt.Text = "T Ext : " + f.ToString() + "°";
        }
Exemplo n.º 6
0
        //public Boolean TryGetBacnetObject(BacnetObjectId boi, out BACnetObject bo)
        //{
        //    bo = null;
        //    foreach (var kvp in BacnetObjects)
        //    {
        //        if (kvp.Key.Equals(boi))
        //        {
        //            bo = kvp.Value;
        //            return true;
        //        }
        //    }
        //    return false;
        //}



        public BACnetObject GetBacnetObject(BacnetObjectId boi)
        {
            //foreach (var kvp in BacnetObjects)
            //{
            //    if (kvp.Key.Equals(boi))
            //        return kvp.Value;

            //}
            //return null;

            if (!ObjectsFetched)
            {
                GetObjects();
            }


            foreach (var kvp in BacnetObjects)
            {
                BacnetObjectId thisObjId = kvp.Key;
                if (thisObjId.Equals(boi))
                {
                    return(kvp.Value);
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        public virtual bool RemoveBacnetObject(BacnetObjectId objId)
        {
            BaCSharpObject obj = FindBacnetObject(objId);

            // device object cannot be deleted, even if AcceptDeleteObject is set to true
            if ((obj.AcceptDeleteObject == false) || (obj == this))
            {
                return(false);
            }

            obj.Dispose();
            foreach (var o in m_PROP_OBJECT_LIST)
            {
                if (o.ToString() == objId.ToString())
                {
                    m_PROP_OBJECT_LIST.Remove(o);
                    break;
                }
            }
            foreach (var o in m_PROP_STRUCTURED_OBJECT_LIST)
            {
                if (o.ToString() == objId.ToString())
                {
                    m_PROP_STRUCTURED_OBJECT_LIST.Remove(o);
                    break;
                }
            }

            return(ObjectsList.Remove(obj)); //since we wont remove object device!!!! using LIST Remove!!
        }
Exemplo n.º 8
0
        public bool ReadPropertyAll(BacnetObjectId objectId, out IList <BacnetPropertyValue> values)
        {
            //find
            var obj = FindObject(objectId);

            if (obj == null)
            {
                values = null;
                return(false);
            }

            //build
            var propertyValues = new BacnetPropertyValue[obj.Properties.Length];

            for (var i = 0; i < obj.Properties.Length; i++)
            {
                var newEntry = new BacnetPropertyValue
                {
                    property = new BacnetPropertyReference((uint)obj.Properties[i].Id, Serialize.ASN1.BACNET_ARRAY_ALL)
                };

                if (ReadProperty(objectId, obj.Properties[i].Id, Serialize.ASN1.BACNET_ARRAY_ALL, out newEntry.value) != ErrorCodes.Good)
                {
                    var bacnetError = new BacnetError(BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_PROPERTY);
                    newEntry.value = new[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR, bacnetError) };
                }

                propertyValues[i] = newEntry;
            }

            values = propertyValues;
            return(true);
        }
        private void OK_Click(object sender, EventArgs e)
        {
            try
            {
                BacnetObjectId?device   = null;
                uint           ArrayIdx = ASN1.BACNET_ARRAY_ALL;

                if (Reference_Device.Text != "")
                {
                    device = new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, Convert.ToUInt16(Reference_Device.Text));
                }
                if (Reference_Array.Text != "")
                {
                    ArrayIdx = Convert.ToUInt16(Reference_Array.Text);
                }


                BacnetDeviceObjectPropertyReference newref = new BacnetDeviceObjectPropertyReference(
                    new BacnetObjectId((BacnetObjectTypes)(Reference_ObjType.SelectedItem as Enumcombo).enumValue, Convert.ToUInt32(Reference_ObjId.Text) & 0x3FFFFF),
                    (BacnetPropertyIds)(Reference_Prop.SelectedItem as Enumcombo).enumValue, device, ArrayIdx);

                if (!ObjRef.Equals(newref))
                {
                    ObjRef      = newref;
                    RefModified = true;
                }
                OutOK = true;
                Close();
            }
            catch
            {
                Close();
            }
        }
 public TrendLogDisplay(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
 {
     InitializeComponent();
     this.comm      = comm;
     this.adr       = adr;
     this.object_id = object_id;
 }
Exemplo n.º 11
0
        private Property FindProperty(BacnetObjectId objectId, BacnetPropertyIds propertyId)
        {
            //liniear search
            var obj = FindObject(objectId);

            return(FindProperty(obj, propertyId));
        }
Exemplo n.º 12
0
        public void ReadPropertyMultiple(BacnetObjectId object_id, ICollection <BacnetPropertyReference> properties, out IList <BacnetPropertyValue> values)
        {
            BacnetPropertyValue[] values_ret = new BacnetPropertyValue[properties.Count];

            int count = 0;

            foreach (BacnetPropertyReference entry in properties)
            {
                BacnetPropertyValue new_entry = new BacnetPropertyValue();
                new_entry.property = entry;

                ErrorCodes error = ReadProperty(object_id, (BacnetPropertyIds)entry.propertyIdentifier, entry.propertyArrayIndex, out new_entry.value);
                if (error == ErrorCodes.UnKnownObject)
                {
                    new_entry.value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR, new BacnetError(BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_OBJECT)) }
                }
                ;
                else if (error == ErrorCodes.NotExist)
                {
                    new_entry.value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR, new BacnetError(BacnetErrorClasses.ERROR_CLASS_PROPERTY, BacnetErrorCodes.ERROR_CODE_UNKNOWN_PROPERTY)) }
                }
                ;

                values_ret[count] = new_entry;

                count++;
            }

            values = values_ret;
        }
Exemplo n.º 13
0
        public bool ReadPropertyAll(BacnetObjectId object_id, out IList <BacnetPropertyValue> values)
        {
            values = null;

            //find
            Object obj = FindObject(object_id);

            if (obj == null)
            {
                return(false);
            }

            //build
            ErrorCodes[]          ret     = new ErrorCodes[obj.Properties.Length];
            BacnetPropertyValue[] _values = new BacnetPropertyValue[obj.Properties.Length];
            for (int i = 0; i < obj.Properties.Length; i++)
            {
                BacnetPropertyValue new_entry = new BacnetPropertyValue();
                new_entry.property = new BacnetPropertyReference((uint)obj.Properties[i].Id, System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL);
                if (ReadProperty(object_id, obj.Properties[i].Id, System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL, out new_entry.value) != ErrorCodes.Good)
                {
                    new_entry.value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR, new BacnetError(BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_PROPERTY)) }
                }
                ;
                _values[i] = new_entry;
            }
            values = _values;

            return(true);
        }
Exemplo n.º 14
0
        public Property FindProperty(BacnetObjectId object_id, BacnetPropertyIds property_id)
        {
            //liniear search
            Object obj = FindObject(object_id);

            return(FindProperty(obj, property_id));
        }
Exemplo n.º 15
0
        public void ReadPropertyMultiple(BacnetObjectId objectId, ICollection <BacnetPropertyReference> properties, out IList <BacnetPropertyValue> values)
        {
            var valuesRet = new List <BacnetPropertyValue>();

            foreach (var entry in properties)
            {
                var newEntry = new BacnetPropertyValue {
                    property = entry
                };

                switch (ReadProperty(objectId, (BacnetPropertyIds)entry.propertyIdentifier, entry.propertyArrayIndex, out newEntry.value))
                {
                case ErrorCodes.UnknownObject:
                    newEntry.value = new[]
                    {
                        new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR,
                                        new BacnetError(BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_OBJECT))
                    };
                    break;

                case ErrorCodes.NotExist:
                    newEntry.value = new[]
                    {
                        new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_ERROR,
                                        new BacnetError(BacnetErrorClasses.ERROR_CLASS_PROPERTY, BacnetErrorCodes.ERROR_CODE_UNKNOWN_PROPERTY))
                    };
                    break;
                }

                valuesRet.Add(newEntry);
            }

            values = valuesRet;
        }
Exemplo n.º 16
0
        private void CreateSubscription(uint l_objectInstance, BacnetObjectTypes objectType, uint l_device)
        {
            var l_objectId = new BacnetObjectId(objectType, l_objectInstance);

            var l_address = this.GetBacnetAddress(l_device);

            if (l_address == null)
            {
                Debug.WriteLine($"Failed. Client {l_device} not found");
                return;
            }

            this.m_next_subscription_id++;

            m_bacnetClient.SubscribeCOVRequest(l_address, l_objectId, this.m_next_subscription_id, false, false, 160);

            var l_subscriptionKey = l_address + ":" + l_device + ":" + this.m_next_subscription_id;

            var l_subscription = new Subscription(
                m_bacnetClient,
                l_address,
                new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, l_device),
                l_objectId,
                l_subscriptionKey,
                this.m_next_subscription_id);

            this.m_subscription_list.Add(l_subscriptionKey, l_subscription);
        }
Exemplo n.º 17
0
        private void InitSubscription_Click(object sender, RoutedEventArgs e)
        {
            uint l_device_id = 127001;

            // uint l_device_id = 20205;

            UiLogItem("Start subscription");

            BacnetAddress adr;

            adr = DeviceAddr(l_device_id);
            if (adr == null)
            {
                UiLogItem("Failed. Client not found");
                return;
            }

            // advise to OBJECT_ANALOG_INPUT:1 provided by the device 1026
            var l_objectId = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, 10240);

            //var l_objectId = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, 3);

            bacnet_client.SubscribeCOVRequest(adr, l_objectId, 0, false, false, 160);

            m_next_subscription_id++;
            string sub_key = adr.ToString() + ":" + l_device_id + ":" + m_next_subscription_id;

            var subScriptionObj = new Subscription(bacnet_client, adr, new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, l_device_id), l_objectId, sub_key, m_next_subscription_id);

            m_subscription_list.Add(sub_key, subScriptionObj);
        }
Exemplo n.º 18
0
        private void AdaptationFarenheit()
        {
            BacnetObjectId b;
            BacnetValue    bv;

            if (Application.CurrentCulture.ToString() != "en-US")
            {
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                b  = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, (uint)(i));
                bv = BacnetActivity.GetBacObjectPresentValue(b);

                BacnetActivity.SetBacObjectPresentValue(b, new BacnetValue((float)Math.Round(TempDegre2Value((float)bv.Value))));

                IList <BacnetValue> val = new BacnetValue[1] {
                    new BacnetValue(64)
                };
                BacnetActivity.m_storage.WriteProperty(b, BacnetPropertyIds.PROP_UNITS, 1, val, true);
            }

            for (int i = 0; i < 3; i++)
            {
                b = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_INPUT, (uint)(i));
                IList <BacnetValue> val = new BacnetValue[1] {
                    new BacnetValue(64)
                };
                BacnetActivity.m_storage.WriteProperty(b, BacnetPropertyIds.PROP_UNITS, 1, val, true);
            }
        }
 public MultiStateValueAndOutput(BacnetObjectId ObjId, String ObjName, String Description, uint InitialValue, uint StatesNumber, bool WithPriorityArray)
     : base(ObjId, ObjName, Description, InitialValue, BacnetUnitsId.UNITS_DEGREES_PHASE, true)
 {
     // InitialValue must be within 1 and m_PROP_NUMBER_OF_STATES
     m_PROP_NUMBER_OF_STATES = StatesNumber;
     m_PROP_STATE_TEXT       = new BacnetValue[StatesNumber];
 }
Exemplo n.º 20
0
        public BACnetObject(BACnetDevice bnd, BacnetObjectId boi)
        {
            this.BacnetDevice   = bnd;      //need this for communication - i.e. get sub-objects.
            this.BacnetObjectId = boi;

            this.Name = "";

            //GetName();  //or just get all properties....


            FetchRequiredProperties();    //obj type, obj instance (already known), name


            //may already know this from device...



            //Changed this.  Now treating structured views and groups just like any other type........
            //if (boi.type == BacnetObjectTypes.OBJECT_GROUP)
            //    FetchGroupProperties();     //should obj_id be a param?  Isn't it just this?
            //else if ((boi.type == BacnetObjectTypes.OBJECT_STRUCTURED_VIEW)) // && Yabe.Properties.Settings.Default.DefaultPreferStructuredView)
            //    FetchViewObjects();
            //else


            //FetchProperties();  //yes, even if device, I guess...
        }
Exemplo n.º 21
0
        public void SetPointTapped(object value)
        {
            SetTemp += 1;

            var b  = new BacnetObjectId(BacnetObjectTypes.OBJECT_ANALOG_VALUE, SetTemp);
            var bv = BacnetActivity.GetBacObjectPresentValue(b);

            BacnetActivity.SetBacObjectPresentValue(Bac_SetTemp, bv);
        }
Exemplo n.º 22
0
        public bool is_active_subscription = true; // false if subscription is refused

        public Subscription(BacnetClient comm, BacnetAddress adr, BacnetObjectId device_id, BacnetObjectId object_id, string sub_key, uint subscribe_id)
        {
            this.m_commClient = comm;
            this.m_address    = adr;
            this.device_id    = device_id;
            this.object_id    = object_id;
            this.sub_key      = sub_key;
            this.subscribe_id = subscribe_id;
        }
Exemplo n.º 23
0
        public CalendarEditor(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id)
        {
            InitializeComponent();

            this.comm      = comm;
            this.adr       = adr;
            this.object_id = object_id;

            LoadCalendar();
        }
Exemplo n.º 24
0
        public BinaryObject(BacnetObjectId ObjId, string ObjName, string Description, bool InitialValue)
            : base(ObjId, ObjName, Description)
        {
            m_PROP_STATUS_FLAGS = m_PROP_STATUS_FLAGS.SetBit((byte)0, false);
            m_PROP_STATUS_FLAGS = m_PROP_STATUS_FLAGS.SetBit((byte)1, false);
            m_PROP_STATUS_FLAGS = m_PROP_STATUS_FLAGS.SetBit((byte)2, false);
            m_PROP_STATUS_FLAGS = m_PROP_STATUS_FLAGS.SetBit((byte)3, false);

            m_PROP_PRESENT_VALUE = InitialValue == true ? (uint)1 : 0;
        }
Exemplo n.º 25
0
 public static List <Subscription> GetSubscriptionsForObject(BacnetObjectId objectId)
 {
     try
     {
         List <Subscription> subs = m_subscriptions[objectId];
         return(subs);
     }
     catch
     { return(null); }
 }
Exemplo n.º 26
0
        public static BacnetValue GetBacObjectPresentValue(BacnetObjectId id)
        {
            // L'index 0 c'est le nombre de valeurs associées à la propriété
            // L'index 1 pour la première valeur
            // L'index System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL pour tout le tableau
            IList <BacnetValue> val = null;

            m_storage.ReadProperty(id, BacnetPropertyIds.PROP_PRESENT_VALUE, 1, out val);
            return(val[0]);
        }
Exemplo n.º 27
0
        public void UploadFileByBlocking(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id, string filename, Action <int> progress_action)
        {
            Cancel = false;

            //open file
            System.IO.FileStream fs = null;
            try
            {
                fs = System.IO.File.OpenRead(filename);
            }
            catch (Exception ex)
            {
                throw new System.IO.IOException("Couldn't open file", ex);
            }

            try
            {
                int    position = 0;
                int    count    = comm.GetFileBufferMaxSize();
                byte[] buffer   = new byte[count];
                while (count > 0 && !Cancel)
                {
                    //read from disk
                    count = fs.Read(buffer, 0, count);
                    if (count < 0)
                    {
                        throw new System.IO.IOException("Couldn't read file");
                    }
                    else if (count == 0)
                    {
                        continue;
                    }

                    //write to device
                    if (!comm.WriteFileRequest(adr, object_id, ref position, count, buffer))
                    {
                        throw new System.IO.IOException("Couldn't write file");
                    }

                    //progress
                    if (count > 0)
                    {
                        position += count;
                        if (progress_action != null)
                        {
                            progress_action(position);
                        }
                    }
                }
            }
            finally
            {
                fs.Close();
            }
        }
Exemplo n.º 28
0
        public void DownloadFileBySegmentation(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id, string filename, Action <int> progress_action)
        {
            Cancel = false;

            //open file
            System.IO.FileStream fs = null;
            try
            {
                fs = System.IO.File.OpenWrite(filename);
            }
            catch (Exception ex)
            {
                throw new System.IO.IOException("Couldn't open file", ex);
            }

            BacnetMaxSegments old_segments = comm.MaxSegments;

            comm.MaxSegments        = BacnetMaxSegments.MAX_SEG65;                             //send as many segments as needed
            comm.ProposedWindowSize = Properties.Settings.Default.Segments_ProposedWindowSize; //set by options
            comm.ForceWindowSize    = true;
            try
            {
                int position = 0;
                //uint count = (uint)comm.GetFileBufferMaxSize() * 20;     //this is more realistic
                uint   count       = 50000;                                //this is more difficult
                bool   end_of_file = false;
                byte[] buffer;
                int    buffer_offset;
                while (!end_of_file && !Cancel)
                {
                    //read from device
                    if (!comm.ReadFileRequest(adr, object_id, ref position, ref count, out end_of_file, out buffer, out buffer_offset))
                    {
                        throw new System.IO.IOException("Couldn't read file");
                    }
                    position += (int)count;

                    //write to file
                    if (count > 0)
                    {
                        fs.Write(buffer, buffer_offset, (int)count);
                        if (progress_action != null)
                        {
                            progress_action(position);
                        }
                    }
                }
            }
            finally
            {
                fs.Close();
                comm.MaxSegments     = old_segments;
                comm.ForceWindowSize = false;
            }
        }
Exemplo n.º 29
0
        public ErrorCodes ReadProperty(BacnetObjectId object_id, BacnetPropertyIds property_id, uint array_index, out IList <BacnetValue> value)
        {
            value = new BacnetValue[0];

            //wildcard device_id
            if (object_id.type == BacnetObjectTypes.OBJECT_DEVICE && object_id.instance >= System.IO.BACnet.Serialize.ASN1.BACNET_MAX_INSTANCE)
            {
                object_id.instance = DeviceId;
            }

            //overrides
            bool       handled;
            ErrorCodes status;

            if (ReadOverride != null)
            {
                ReadOverride(object_id, property_id, array_index, out value, out status, out handled);
                if (handled)
                {
                    return(status);
                }
            }

            //By thamersalek : find Object in storage
            Object Obj1 = FindObject(object_id);

            if (Obj1 == null)
            {
                return(ErrorCodes.UnKnownObject);
            }
            //Object found now find property
            Property p = FindProperty(object_id, property_id);

            if (p == null)
            {
                return(ErrorCodes.NotExist);
            }

            //get value ... check for array index
            if (array_index == 0)
            {
                value = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, (uint)p.BacnetValue.Count) };
            }
            else if (array_index != System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL)
            {
                value = new BacnetValue[] { p.BacnetValue[(int)array_index - 1] };
            }
            else
            {
                value = p.BacnetValue;
            }

            return(ErrorCodes.Good);
        }
        public AnalogValueAndOutput(BacnetObjectId ObjId, String ObjName, String Description, T InitialValue, BacnetUnitsId Unit, bool WithPriorityArray)
            : base(ObjId, ObjName, Description, InitialValue, Unit)
        {
            if (WithPriorityArray == true)
            {
                UsePriorityArray          = true;
                m_PROP_RELINQUISH_DEFAULT = InitialValue;
            }

            this.m_PRESENT_VALUE_ReadOnly = false;
        }
Exemplo n.º 31
0
        public bool ReadScalarValue(int deviceId, BacnetObjectId bacnetObjet, BacnetPropertyIds property,
            out BacnetValue value)
        {
            lock (this)
            {
                IList<BacnetValue> noScalarValue;

                value = new BacnetValue(null);

                // Looking for the device
                var adr = DeviceAddr((uint) deviceId);
                if (adr == null) return false; // not found

                // Property Read
                if (_bacnetClient.ReadPropertyRequest(adr, bacnetObjet, property, out noScalarValue) == false)
                    return false;

                value = noScalarValue[0];
                return true;
            }
        }
Exemplo n.º 32
0
        //***************************************************************************************************
        public bool DeleteObjectRequest(BacnetAddress adr, BacnetObjectId object_id, byte invoke_id = 0)
        {
            using (BacnetAsyncResult result = (BacnetAsyncResult)BeginDeleteObjectRequest(adr, object_id, true, invoke_id))
            {
                for (int r = 0; r < m_retries; r++)
                {
                    if (result.WaitForDone(m_timeout))
                    {
                        Exception ex;
                        EndDeleteObjectRequest(result, out ex);
                        if (ex != null) throw ex;
                        else return true;
                    }
                    result.Resend();
                }
            }

            return false;
        }
Exemplo n.º 33
0
        public IAsyncResult BeginSubscribePropertyRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyReference monitored_property, uint subscribe_id, bool cancel, bool issue_confirmed_notifications, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending SubscribePropertyRequest ... ", 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_SUBSCRIBE_COV_PROPERTY, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeSubscribeProperty(b, subscribe_id, object_id, cancel, issue_confirmed_notifications, 0, monitored_property, false, 0f);

            //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;
        }
Exemplo n.º 34
0
 public bool ReadPropertyMultipleRequest(BacnetAddress adr, BacnetObjectId object_id, IList<BacnetPropertyReference> property_id_and_array_index, out IList<BacnetReadAccessResult> values, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginReadPropertyMultipleRequest(adr, object_id, property_id_and_array_index, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndReadPropertyMultipleRequest(result, out values, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     values = null;
     return false;
 }
Exemplo n.º 35
0
        //*************************************************************
        public bool AddListElementRequest(BacnetAddress adr, BacnetObjectId object_id,BacnetPropertyReference reference, IList<BacnetValue> value_list, byte invoke_id = 0)
        {
            using (BacnetAsyncResult result = (BacnetAsyncResult)BeginAddListElementRequest(adr, object_id,reference,value_list, true, invoke_id))
            {
                for (int r = 0; r < m_retries; r++)
                {

                    if (result.WaitForDone(m_timeout))
                    {
                        Exception ex;
                        EndAddListElementRequest(result, out ex);
                        if (ex != null) throw ex;
                        else return true;
                    }
                    result.Resend();
                }
            }
            //values = null;
            return false;
        }
Exemplo n.º 36
0
 //*********************************************************************************
 // By Christopher Günter
 public bool CreateObjectRequest(BacnetAddress adr, BacnetObjectId object_id, ICollection<BacnetPropertyValue> value_list, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginCreateObjectRequest(adr, object_id, value_list, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndCreateObjectRequest(result, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     value_list = null;
     return false;
 }
Exemplo n.º 37
0
        public bool Notify(BacnetAddress adr, uint subscriberProcessIdentifier, uint initiatingDeviceIdentifier, BacnetObjectId monitoredObjectIdentifier, uint timeRemaining, bool issueConfirmedNotifications, IList<BacnetPropertyValue> values)
        {
            if (!issueConfirmedNotifications)
            {
                Trace.WriteLine("Sending Notify (unconfirmed) ... ", null);
                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.EncodeUnconfirmedServiceRequest(b, BacnetPduTypes.PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST, BacnetUnconfirmedServices.SERVICE_UNCONFIRMED_COV_NOTIFICATION);
                Services.EncodeCOVNotifyUnconfirmed(b, subscriberProcessIdentifier, initiatingDeviceIdentifier, monitoredObjectIdentifier, timeRemaining, values);
               // Modif F. Chaxel

                int sendbytes=m_client.Send(b.buffer, m_client.HeaderLength, b.offset - m_client.HeaderLength, adr, false, 0);

                if (sendbytes == b.offset)
                    return true;
                else
                    return false;
            }
            else
            {
                using (BacnetAsyncResult result = (BacnetAsyncResult)BeginConfirmedNotify(adr, subscriberProcessIdentifier, initiatingDeviceIdentifier, monitoredObjectIdentifier, timeRemaining, values, true))
                {
                    for (int r = 0; r < m_retries; r++)
                    {
                        if (result.WaitForDone(m_timeout))
                        {
                            Exception ex;
                            EndConfirmedNotify(result, out ex);
                            if (ex != null) throw ex;
                            else return true;
                        }
                        result.Resend();
                    }
                }
                return false;
            }
        }
        /*****************************************************************************************************/
        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 (bacnet_client.ReadPropertyRequest(adr, BacnetObjet, Propriete, out NoScalarValue) == false)
                return false;

            Value = NoScalarValue[0];
            return true;
        }
Exemplo n.º 39
0
 public bool SubscribePropertyRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyReference monitored_property, uint subscribe_id, bool cancel, bool issue_confirmed_notifications, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginSubscribePropertyRequest(adr, object_id, monitored_property, subscribe_id, cancel, issue_confirmed_notifications, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndSubscribePropertyRequest(result, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     return false;
 }
Exemplo n.º 40
0
 public bool ReadFileRequest(BacnetAddress adr, BacnetObjectId object_id, ref int position, ref uint count, out bool end_of_file, out byte[] file_buffer, out int file_buffer_offset, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginReadFileRequest(adr, object_id, position, count, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndReadFileRequest(result, out count, out position, out end_of_file, out file_buffer, out file_buffer_offset, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             if (r < (m_retries - 1))
                 result.Resend();
         }
     }
     position = -1;
     count = 0;
     file_buffer = null;
     end_of_file = true;
     file_buffer_offset = -1;
     return false;
 }
Exemplo n.º 41
0
 public bool WriteFileRequest(BacnetAddress adr, BacnetObjectId object_id, ref int position, int count, byte[] file_buffer, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginWriteFileRequest(adr, object_id, position, count, file_buffer, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndWriteFileRequest(result, out position, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     return false;
 }
Exemplo n.º 42
0
        // Fc
        public IAsyncResult BeginReadRangeRequest(BacnetAddress adr, BacnetObjectId object_id,  uint idxBegin, uint Quantity, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending ReadRangeRequest ... ", null);
            if (invoke_id == 0) invoke_id = unchecked(m_invoke_id++);

            //encode
            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_READ_RANGE, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeReadRange(b, object_id, (uint)BacnetPropertyIds.PROP_LOG_BUFFER, ASN1.BACNET_ARRAY_ALL, BacnetReadRangeRequestTypes.RR_BY_POSITION, idxBegin, DateTime.Now, (int)Quantity);
            //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;
        }
Exemplo n.º 43
0
        // Fc
        public IAsyncResult BeginRawEncodedDecodedPropertyConfirmedRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyIds property_id, BacnetConfirmedServices service_id, byte[] InOutBuffer, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending RawEncodedRequest ... ", null);
            if (invoke_id == 0) invoke_id = unchecked(m_invoke_id++);

            EncodeBuffer b = GetEncodeBuffer(m_client.HeaderLength);
            NPDU.Encode(b, BacnetNpduControls.PriorityNormalMessage | BacnetNpduControls.ExpectingReply, 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), service_id , m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);

            ASN1.encode_context_object_id(b, 0, object_id.type, object_id.instance);
            ASN1.encode_context_enumerated(b, 1, (byte)property_id);

            // No content encoding to do
            if (InOutBuffer!=null)
                b.Add(InOutBuffer, InOutBuffer.Length);

            //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;
        }
Exemplo n.º 44
0
        public bool WriteScalarValue(int deviceId, BacnetObjectId bacnetObjet, BacnetPropertyIds property,
            BacnetValue value)
        {
            lock (this)
            {
                if (!WriteProtectionEnabled || CurrentNumberOfWrites < Settings.Default.MaxNumberOfWritesPer24h)
                {

                    // Looking for the device
                    var adr = DeviceAddr((uint) deviceId);
                    if (adr == null) return false; // not found

                    Logger.Debug($"WriteScalarValue(): {bacnetObjet.Instance} = {value}");

                    bool retValue = _bacnetClient.WritePropertyRequest(adr, bacnetObjet, property, new[] {value});
                    CurrentNumberOfWrites++;
                    ValuesChanged?.Invoke();
                    return retValue;
                }
                Logger.Error(
                    $"WriteScalarValue(): Number of Writes per 24h exceeded. Change the number MaxNumberOfWritesPer24h if requried.");
                return false;
            }
        }
        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;
        }
Exemplo n.º 46
0
        public IAsyncResult BeginWriteFileRequest(BacnetAddress adr, BacnetObjectId object_id, int position, int count, byte[] file_buffer, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending AtomicWriteFileRequest ... ", 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_ATOMIC_WRITE_FILE, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeAtomicWriteFile(b, true, object_id, position, 1, new byte[][] { file_buffer }, new int[] { count });

            //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;
        }
Exemplo n.º 47
0
        public IAsyncResult BeginConfirmedNotify(BacnetAddress adr, uint subscriberProcessIdentifier, uint initiatingDeviceIdentifier, BacnetObjectId monitoredObjectIdentifier, uint timeRemaining, IList<BacnetPropertyValue> values, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending Notify (confirmed) ... ", 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_COV_NOTIFICATION, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeCOVNotifyConfirmed(b, subscriberProcessIdentifier, initiatingDeviceIdentifier, monitoredObjectIdentifier, timeRemaining, values);

            //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;
        }
Exemplo n.º 48
0
 // Fc
 // Read or Write without APDU Data encoding nor Decoding (just Request type, Object id and Property id)
 // Data is given by the caller starting with the Tag 3 (or maybe another one), and ending with it
 // return buffer start also with the Tag 3
 public bool RawEncodedDecodedPropertyConfirmedRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyIds property_id, BacnetConfirmedServices service_id, ref byte[] InOutBuffer, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginRawEncodedDecodedPropertyConfirmedRequest(adr, object_id, property_id, service_id, InOutBuffer, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndRawEncodedDecodedPropertyConfirmedRequest(result, service_id, out InOutBuffer, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     InOutBuffer = null;
     return false;
 }
Exemplo n.º 49
0
 public void ReadRangeResponse(BacnetAddress adr, byte invoke_id, Segmentation segmentation, BacnetObjectId object_id, BacnetPropertyReference property, BacnetResultFlags status, uint item_count, byte[] application_data, BacnetReadRangeRequestTypes request_type, uint first_sequence_no)
 {
     SendComplexAck(adr, invoke_id, segmentation, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_RANGE, (b) =>
     {
         Services.EncodeReadRangeAcknowledge(b, object_id, property.propertyIdentifier, property.propertyArrayIndex, BacnetBitString.ConvertFromInt((uint)status), item_count, application_data, request_type, first_sequence_no);
     });
 }
 public void CreateObjectResponse(BacnetAddress adr, byte invoke_id, Segmentation segmentation, BacnetObjectId object_id)
 {
     SendComplexAck(adr, invoke_id, segmentation, BacnetConfirmedServices.SERVICE_CONFIRMED_CREATE_OBJECT, (b) =>
     {
         Services.EncodeCreateObjectAcknowledge(b, object_id);
     });
 }
Exemplo n.º 51
0
 // Fc
 public bool ReadRangeRequest(BacnetAddress adr, BacnetObjectId object_id, uint idxBegin, ref uint Quantity, out byte[] Range, byte invoke_id = 0)
 {
     Range = null;
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginReadRangeRequest(adr, object_id, idxBegin, Quantity, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndReadRangeRequest(result, out Range, out Quantity, out ex); // quantity read could be less than demanded
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     return false;
 }
        /*****************************************************************************************************/
        static bool WriteScalarValue(int device_id, BacnetObjectId BacnetObjet, BacnetPropertyIds Propriete, BacnetValue Value)
        {
            BacnetAddress adr;

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

            // Property Write
            BacnetValue[] NoScalarValue = { Value };
            if (bacnet_client.WritePropertyRequest(adr, BacnetObjet, Propriete, NoScalarValue) == false)
                return false;

            return true;
        }
 // 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;
 }
 public bool WritePropertyMultipleRequest(BacnetAddress adr, BacnetObjectId object_id, ICollection<BacnetPropertyValue> value_list, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginWritePropertyMultipleRequest(adr, object_id, value_list, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndWritePropertyRequest(result, out ex); // Share the same with single write
                 if (ex != null) throw ex;
                 else return true;
             }
             if (r < (m_retries - 1))
                 result.Resend();
         }
     }
     value_list = null;
     return false;
 }
Exemplo n.º 55
0
        public IAsyncResult BeginWritePropertyRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyIds property_id, IEnumerable<BacnetValue> value_list, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending WritePropertyRequest ... ", 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_WRITE_PROPERTY, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeWriteProperty(b, object_id, (uint)property_id, ASN1.BACNET_ARRAY_ALL, m_writepriority, value_list);

            //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;
        }
 public bool WritePropertyRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyIds property_id, IEnumerable<BacnetValue> value_list, byte invoke_id = 0)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginWritePropertyRequest(adr, object_id, property_id, value_list, true, invoke_id))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndWritePropertyRequest(result, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             if (r < (m_retries - 1))
                 result.Resend();
         }
     }
     value_list = null;
     return false;
 }
Exemplo n.º 57
0
 public void ReadPropertyResponse(BacnetAddress adr, byte invoke_id, Segmentation segmentation, BacnetObjectId object_id, BacnetPropertyReference property, IEnumerable<BacnetValue> value)
 {
     SendComplexAck(adr, invoke_id, segmentation, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, (b) =>
     {
         Services.EncodeReadPropertyAcknowledge(b, object_id, property.propertyIdentifier, property.propertyArrayIndex, value);
     });
 }
Exemplo n.º 58
0
 public bool ReadPropertyRequest(BacnetAddress adr, BacnetObjectId object_id, BacnetPropertyIds property_id, out IList<BacnetValue> value_list, byte invoke_id = 0, uint array_index = ASN1.BACNET_ARRAY_ALL)
 {
     using (BacnetAsyncResult result = (BacnetAsyncResult)BeginReadPropertyRequest(adr, object_id, property_id, true, invoke_id, array_index))
     {
         for (int r = 0; r < m_retries; r++)
         {
             if (result.WaitForDone(m_timeout))
             {
                 Exception ex;
                 EndReadPropertyRequest(result, out value_list, out ex);
                 if (ex != null) throw ex;
                 else return true;
             }
             result.Resend();
         }
     }
     value_list = null;
     return false;
 }
Exemplo n.º 59
0
        //***********************************************************************
        public IAsyncResult BeginRemoveListElementRequest(BacnetAddress adr, BacnetObjectId object_id,BacnetPropertyReference reference, IList<BacnetValue> value_list, bool wait_for_transmit, byte invoke_id = 0)
        {
            Trace.WriteLine("Sending RemoveListElementRequest ... ", 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_REMOVE_LIST_ELEMENT, m_max_segments, m_client.MaxAdpuLength, invoke_id, 0, 0);
            Services.EncodeAddListElement(b, object_id,(uint) reference.propertyIdentifier,(uint) reference.propertyArrayIndex,value_list);

            //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;
        }