Example #1
0
        private void handler_OnReadPropertyRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetPropertyReference property, BacnetMaxSegments max_segments)
        {
            lock (m_storage)
            {
                _logger.LogInformation($"Read property request for {property.ToString()} of {object_id.ToString()} from {adr.ToString()}.");

                try
                {
                    IList <BacnetValue>      value;
                    DeviceStorage.ErrorCodes code = m_storage.ReadProperty(object_id, (BacnetPropertyIds)property.propertyIdentifier, property.propertyArrayIndex, out value);
                    if (code == DeviceStorage.ErrorCodes.Good)
                    {
                        sender.ReadPropertyResponse(adr, invoke_id, sender.GetSegmentBuffer(max_segments), object_id, property, value);
                    }
                    else
                    {
                        sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                    }
                }
                catch (Exception)
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                }
            }
        }
Example #2
0
        public ErrorCodes ReadPropertyValue(BacnetPropertyReference PropRef, out IList <BacnetValue> propVal)
        {
            propVal = null;

            try
            {
                string PropName = PropRef.ToString();
                if (PropName[0] != 'P')
                {
                    PropName = "PROP_" + PropName;                   // private property, not in the Enum list
                }
                propVal = FindPropValue(PropName);

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

                // number of elements required
                if (PropRef.propertyArrayIndex == 0)
                {
                    propVal = new BacnetValue[] { new BacnetValue(BacnetApplicationTags.BACNET_APPLICATION_TAG_UNSIGNED_INT, (uint)propVal.Count) };
                    return(ErrorCodes.Good);
                }

                // only a particular element
                else if (PropRef.propertyArrayIndex != System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL)
                {
                    if ((int)PropRef.propertyArrayIndex <= (uint)propVal.Count)
                    {
                        propVal = new BacnetValue[] { propVal[(int)PropRef.propertyArrayIndex - 1] }
                    }
                    ;
                    else
                    {
                        return(ErrorCodes.IndexNotExist);
                    }
                }

                return(ErrorCodes.Good);
            }
            catch
            {
                return(ErrorCodes.GenericError);
            }
        }