public bool ReadPropertyAll(BacnetClient sender, BacnetAddress adr, out IList <BacnetPropertyValue> values)
        {
            if (AllMyProperties == null)
            {
                AllMyProperties = new List <BacnetPropertyReference>();

                MethodInfo[] allmethod = this.GetType().GetMethods();   // all the methods in this class

                foreach (MethodInfo m in allmethod)
                {
                    uint PropId = BacnetMethodNametoId(m.Name);         // looking for all with a 'Bacnet name'
                    if (PropId < (uint)BacnetPropertyIds.MAX_BACNET_PROPERTY_ID)
                    {
                        BacnetPropertyReference propref = new BacnetPropertyReference(PropId, System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL);
                        // could be get_ and get2_, only one is required
                        if (!AllMyProperties.Contains(propref))
                        {
                            AllMyProperties.Add(propref);
                        }
                    }
                }
            }

            return(ReadPropertyMultiple(sender, adr, AllMyProperties, out values));
        }
Example #2
0
 public Subscription(BacnetClient reciever, BacnetAddress reciever_address, uint subscriberProcessIdentifier, BacnetObjectId monitoredObjectIdentifier, BacnetPropertyReference property, bool issueConfirmedNotifications, uint lifetime, float covIncrement)
 {
     this.reciever                    = reciever;
     this.reciever_address            = reciever_address;
     this.subscriberProcessIdentifier = subscriberProcessIdentifier;
     this.monitoredObjectIdentifier   = monitoredObjectIdentifier;
     this.monitoredProperty           = property;
     this.issueConfirmedNotifications = issueConfirmedNotifications;
     this.lifetime                    = lifetime;
     this.start        = DateTime.Now;
     this.covIncrement = covIncrement;
 }
Example #3
0
        static void ServiceToBeTested()
        {
            // Try to debug the reception of the first frame from the .pcap file
            // 2nd param is the number of frames (more than 1 in case of segmentation)
            byte invokeId = SetReplyPackets(@"..\..\ReadPropMultiple.pcap", 1, 0x2e);

            BacnetPropertyReference[]      properties = new BacnetPropertyReference[] { new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_ALL, System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL) };
            IList <BacnetReadAccessResult> multi_value_list;

            BacnetObjectId BOid = new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, 16);

            System.Diagnostics.Debugger.Break();
            bacnet_client.ReadPropertyMultipleRequest(nowhere, BOid, properties, out multi_value_list, invokeId);

            // to debug server handle methods, just send any kind of unconfirmed message such as whois
        }
Example #4
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);
            }
        }
        /*****************************************************************************************************/
        static void handler_OnCOVManagementNotify(BaCSharpObject sender, BacnetPropertyIds propId)
        {
            System.Threading.ThreadPool.QueueUserWorkItem((o) =>
            {
                lock (device)
                {
                    //remove old leftovers
                    SubscriptionManager.RemoveOldSubscriptions();

                    //find subscription
                    List <Subscription> subs = SubscriptionManager.GetSubscriptionsForObject(sender.PROP_OBJECT_IDENTIFIER);

                    if (subs == null)
                    {
                        return;             // nobody
                    }
                    //Read the property
                    IList <BacnetValue> value;
                    BacnetPropertyReference br = new BacnetPropertyReference((uint)propId, (uint)System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL);
                    ErrorCodes error           = sender.ReadPropertyValue(br, out value);

                    List <BacnetPropertyValue> values = new List <BacnetPropertyValue>();
                    BacnetPropertyValue tmp           = new BacnetPropertyValue();
                    tmp.value    = value;
                    tmp.property = br;
                    values.Add(tmp);

                    //send to all
                    foreach (Subscription sub in subs)
                    {
                        if (sub.monitoredProperty.propertyIdentifier == (uint)BacnetPropertyIds.PROP_ALL || sub.monitoredProperty.propertyIdentifier == (uint)propId)
                        {
                            tmp.property = sub.monitoredProperty;
                            if (!sub.reciever.Notify(sub.reciever_address, sub.subscriberProcessIdentifier, deviceId, sub.monitoredObjectIdentifier, (uint)sub.GetTimeRemaining(), sub.issueConfirmedNotifications, values))
                            {
                                SubscriptionManager.RemoveReceiver(sub.reciever_address);
                            }
                        }
                    }
                }
            }, null);
        }
        private static void OnSubscribeCOVProperty(BacnetClient sender, BacnetAddress adr, byte invoke_id, uint subscriberProcessIdentifier, BacnetObjectId monitoredObjectIdentifier, BacnetPropertyReference monitoredProperty, bool cancellationRequest, bool issueConfirmedNotifications, uint lifetime, float covIncrement, BacnetMaxSegments max_segments)
        {
            lock (m_lockObject)
            {
                try
                {
                    //create
                    Subscription sub = HandleSubscriptionRequest(sender, adr, invoke_id, subscriberProcessIdentifier, monitoredObjectIdentifier, (uint)BacnetPropertyIds.PROP_ALL, cancellationRequest, issueConfirmedNotifications, lifetime, covIncrement);

                    //send confirm
                    sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY, invoke_id);

                    //also send first values
                    if (!cancellationRequest)
                    {
                        System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                        {
                            IList <BacnetValue> _values;
                            m_storage.ReadProperty(sub.monitoredObjectIdentifier, (BacnetPropertyIds)sub.monitoredProperty.propertyIdentifier, sub.monitoredProperty.propertyArrayIndex, out _values);
                            List <BacnetPropertyValue> values = new List <BacnetPropertyValue>();
                            BacnetPropertyValue tmp           = new BacnetPropertyValue();
                            tmp.property = sub.monitoredProperty;
                            tmp.value    = _values;
                            values.Add(tmp);
                            if (!sender.Notify(adr, sub.subscriberProcessIdentifier, m_storage.DeviceId, sub.monitoredObjectIdentifier, (uint)sub.GetTimeRemaining(), sub.issueConfirmedNotifications, values))
                            {
                                Trace.TraceError("Couldn't send notify");
                            }
                        }, null);
                    }
                }
                catch (Exception)
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                }
            }
        }
Example #7
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 ErrorCodes ReadPropertyValue(BacnetClient sender, BacnetAddress adr, BacnetPropertyReference PropRef, out IList <BacnetValue> propVal)
 {
     return(ReadPropertyValue(PropRef, out propVal));
 }
        /*****************************************************************************************************/
        static void handler_OnReadPropertyRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetPropertyReference property, BacnetMaxSegments max_segments)
        {
            lock (device)
            {
                BaCSharpObject bacobj = device.FindBacnetObject(object_id);

                if (bacobj != null)
                {
                    IList <BacnetValue> value;
                    ErrorCodes          error = bacobj.ReadPropertyValue(sender, adr, property, out value);
                    if (error == ErrorCodes.Good)
                    {
                        sender.ReadPropertyResponse(adr, invoke_id, sender.GetSegmentBuffer(max_segments), object_id, property, value);
                    }
                    else
                    if (error == ErrorCodes.IndexNotExist)
                    {
                        sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_PROPERTY, BacnetErrorCodes.ERROR_CODE_INVALID_ARRAY_INDEX);
                    }
                    else
                    {
                        sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_UNKNOWN_PROPERTY);
                    }
                }
                else
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_OBJECT);
                }
            }
        }
Example #10
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);
     });
 }
        /*****************************************************************************************************/
        static void handler_OnSubscribeCOVProperty(BacnetClient sender, BacnetAddress adr, byte invoke_id, uint subscriberProcessIdentifier, BacnetObjectId monitoredObjectIdentifier, BacnetPropertyReference monitoredProperty, bool cancellationRequest, bool issueConfirmedNotifications, uint lifetime, float covIncrement, BacnetMaxSegments max_segments)
        {
            lock (device)
            {
                BaCSharpObject bacobj = device.FindBacnetObject(monitoredObjectIdentifier);
                if (bacobj != null)
                {
                    //create
                    Subscription sub = SubscriptionManager.HandleSubscriptionRequest(sender, adr, invoke_id, subscriberProcessIdentifier, monitoredObjectIdentifier, monitoredProperty.propertyIdentifier, cancellationRequest, issueConfirmedNotifications, lifetime, covIncrement);

                    //send confirm
                    sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY, invoke_id);

                    //also send first values
                    if (!cancellationRequest)
                    {
                        System.Threading.ThreadPool.QueueUserWorkItem((o) =>
                        {
                            IList <BacnetValue> _values;
                            bacobj.ReadPropertyValue(sender, adr, monitoredProperty, out _values);

                            List <BacnetPropertyValue> values = new List <BacnetPropertyValue>();
                            BacnetPropertyValue tmp           = new BacnetPropertyValue();
                            tmp.property = sub.monitoredProperty;
                            tmp.value    = _values;
                            values.Add(tmp);

                            sender.Notify(adr, sub.subscriberProcessIdentifier, deviceId, sub.monitoredObjectIdentifier, (uint)sub.GetTimeRemaining(), sub.issueConfirmedNotifications, values);
                        }, null);
                    }
                }
                else
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                }
            }
        }
Example #12
0
        public void FetchProperties()      //if NOT structured view, etc...right?
        {
            lock (this.BacnetProperties)
            {
                //BacnetProperties.Clear();     //yes, just re-fetch required properties.       //don't want to wipe this out if an error occurs though


                var oldProperties = new List <KeyValuePair <BacnetPropertyIds, BACnetProperty> >();
                oldProperties.AddRange(BacnetProperties);



                //TODO: put a lock on this in case another is trying at the same time...
                //but wait, these are kept per-instance, right?

                BacnetProperties.Clear();


                AllPropertiesFetched = false;


                //TODO: if this is a structured view or object group, handle differently
                //A structured view has no Present Value prooperty
                //An object group's present value property is just its list of members, so we really just want to make sub-objects, not properties.


                //Also, in Yabe the properties will actually show up in the address space...this is not what we want for plugin


                var comm      = BacnetDevice.BacnetNetwork.BacnetClient;
                var adr       = BacnetDevice.BacnetAddress;
                var object_id = BacnetObjectId;
                BacnetPropertyReference[] properties = new BacnetPropertyReference[] { new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_ALL, System.IO.BACnet.Serialize.ASN1.BACNET_ARRAY_ALL) };

                //do we want to skip the properties used above?  For structured view, group, etc.?

                IList <BacnetReadAccessResult> multi_value_list = new List <BacnetReadAccessResult>();
                try
                {
                    //fetch properties. This might not be supported (ReadMultiple) or the response might be too long.
                    if (comm.ReadPropertyMultipleRequest(adr, object_id, properties, out multi_value_list))
                    {
                        //update grid
                        //Utilities.DynamicPropertyGridContainer bag = new Utilities.DynamicPropertyGridContainer();
                        foreach (BacnetPropertyValue p_value in multi_value_list[0].values)
                        {
                            AddProperty(p_value);



                            //var id = (BacnetPropertyIds)p_value.property.propertyIdentifier;



                            //var val = p_value.value[0];


                            ////var requiredProps = new List<BacnetPropertyIds>(){BacnetPropertyIds.PROP_OBJECT_IDENTIFIER, BacnetPropertyIds.PROP_OBJECT_TYPE, BacnetPropertyIds.PROP_OBJECT_NAME};

                            ////if (requiredProps.Contains(id))     //already fetched these before.
                            ////    continue;


                            //AddProperty(id, val);   //if required properties, will just overwrite
                        }
                    }
                    else
                    {
                        Trace.TraceWarning("Couldn't perform ReadPropertyMultiple ... Trying ReadProperty instead");
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceWarning("Couldn't perform ReadPropertyMultiple ... Trying ReadProperty instead");

                    if (!ReadAllPropertiesBySingle())   //shouldn't really have to return and process values...just add in place.
                    {
                        Trace.TraceWarning("Couldn't perform ReadProperty ... Trying ReadProperty instead");
                        //MessageBox.Show(this, "Couldn't fetch properties", "Communication Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        BacnetProperties = oldProperties;
                        return;
                    }

                    //return; //?
                }



                AllPropertiesFetched = true;

                SetName();
            }
        }
Example #13
0
 /*****************************************************************************************************/
 static void handler_OnReadPropertyRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetPropertyReference property, BacnetMaxSegments max_segments)
 {
     lock (m_storage)
     {
         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);
         }
     }
 }
        // Give a way to display/modify some specifics values in a ListBox
        public override object GetEditor(Type editorBaseType = null)            //shouldn't need to specify the type...
        {
            if (editorBaseType == null)
            {
                editorBaseType = typeof(System.String);
            }

            // All Bacnet Time as this
            if (m_Property.bacnetApplicationTags == BacnetApplicationTags.BACNET_APPLICATION_TAG_TIME)
            {
                return(new BacnetTimePickerEditor());
            }

            BacnetPropertyReference bpr = (BacnetPropertyReference)m_Property.Tag;

            // A lot of classic Bacnet Enum & BitString
            switch ((BacnetPropertyIds)bpr.propertyIdentifier)
            {
            case BacnetPropertyIds.PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED:
                return(new BacnetBitStringToEnumListDisplay(new BacnetObjectTypes(), true));

            case BacnetPropertyIds.PROP_PROTOCOL_SERVICES_SUPPORTED:
                return(new BacnetBitStringToEnumListDisplay(new BacnetServicesSupported(), true));

            case BacnetPropertyIds.PROP_STATUS_FLAGS:
                return(new BacnetBitStringToEnumListDisplay(new BacnetStatusFlags(), false, true));

            case BacnetPropertyIds.PROP_LIMIT_ENABLE:
                return(new BacnetBitStringToEnumListDisplay(new BacnetEventNotificationData.BacnetLimitEnable(), false, true));

            case BacnetPropertyIds.PROP_EVENT_ENABLE:
            case BacnetPropertyIds.PROP_ACK_REQUIRED:
            case BacnetPropertyIds.PROP_ACKED_TRANSITIONS:
                return(new BacnetBitStringToEnumListDisplay(new BacnetEventNotificationData.BacnetEventEnable(), false, true));

            case BacnetPropertyIds.PROP_OBJECT_TYPE:
                return(new BacnetEnumValueDisplay(new BacnetObjectTypes()));

            case BacnetPropertyIds.PROP_NOTIFY_TYPE:
                return(new BacnetEnumValueDisplay(new BacnetEventNotificationData.BacnetNotifyTypes()));

            case BacnetPropertyIds.PROP_EVENT_TYPE:
                return(new BacnetEnumValueDisplay(new BacnetEventNotificationData.BacnetEventTypes()));

            case BacnetPropertyIds.PROP_EVENT_STATE:
                return(new BacnetEnumValueDisplay(new BacnetEventNotificationData.BacnetEventStates()));

            case BacnetPropertyIds.PROP_POLARITY:
                return(new BacnetEnumValueDisplay(new BacnetPolarity()));

            case BacnetPropertyIds.PROP_UNITS:
                return(new BacnetEnumValueDisplay(new BacnetUnitsId()));

            case BacnetPropertyIds.PROP_RELIABILITY:
                return(new BacnetEnumValueDisplay(new BacnetReliability()));

            case BacnetPropertyIds.PROP_SEGMENTATION_SUPPORTED:
                return(new BacnetEnumValueDisplay(new BacnetSegmentations()));

            case BacnetPropertyIds.PROP_SYSTEM_STATUS:
                return(new BacnetEnumValueDisplay(new BacnetDeviceStatus()));

            case BacnetPropertyIds.PROP_LAST_RESTART_REASON:
                return(new BacnetEnumValueDisplay(new BacnetRestartReason()));

            case BacnetPropertyIds.PROP_PRIORITY_FOR_WRITING:
                return(new BacnetEnumValueDisplay(new BacnetWritePriority()));

            case BacnetPropertyIds.PROP_PROGRAM_CHANGE:
                return(new BacnetEnumValueDisplay(new BacnetProgramChange()));

            case BacnetPropertyIds.PROP_PRIORITY_ARRAY:
                return(new BacnetEditPriorityArray());

            case BacnetPropertyIds.PROP_BACKUP_AND_RESTORE_STATE:
                return(new BacnetEnumValueDisplay(new BACnetBackupState()));

            case BacnetPropertyIds.PROP_PRESENT_VALUE:          //will only get here for enumerated binary value pres. value property
                return(new BacnetEnumValueDisplay(new BacnetBinaryValues()));


            default:
                return(base.GetEditor(editorBaseType));
            }
        }
Example #15
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;
        }
Example #16
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;
        }
Example #17
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;
        }
Example #18
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;
 }
Example #19
0
        // Give a way to display/modify some specifics values in a ListBox
        public override object GetEditor(Type editorBaseType)
        {
            // All Bacnet Time as this
            if (m_Property.bacnetApplicationTags == BacnetApplicationTags.BACNET_APPLICATION_TAG_TIME)
            {
                return(new BacnetTimePickerEditor());
            }

            BacnetPropertyReference bpr = (BacnetPropertyReference)m_Property.Tag;

            // A lot of classic Bacnet Enum & BitString
            switch ((BacnetPropertyIds)bpr.propertyIdentifier)
            {
            case BacnetPropertyIds.PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED:
                return(new BacnetBitStringToEnumListDisplay(new BacnetObjectTypes(), true));

            case BacnetPropertyIds.PROP_PROTOCOL_SERVICES_SUPPORTED:
                return(new BacnetBitStringToEnumListDisplay(new BacnetServicesSupported(), true));

            case BacnetPropertyIds.PROP_STATUS_FLAGS:
                return(new BacnetBitStringToEnumListDisplay(new BacnetStatusFlags(), false, true));

            case BacnetPropertyIds.PROP_LIMIT_ENABLE:
                return(new BacnetBitStringToEnumListDisplay(new BacnetEventNotificationData.BacnetLimitEnable(), false, true));

            case BacnetPropertyIds.PROP_EVENT_ENABLE:
            case BacnetPropertyIds.PROP_ACK_REQUIRED:
            case BacnetPropertyIds.PROP_ACKED_TRANSITIONS:
                return(new BacnetBitStringToEnumListDisplay(new BacnetEventNotificationData.BacnetEventEnable(), false, true));

            case BacnetPropertyIds.PROP_OBJECT_TYPE:
                return(new BacnetEnumValueDisplay(new BacnetObjectTypes()));

            case BacnetPropertyIds.PROP_NOTIFY_TYPE:
                return(new BacnetEnumValueDisplay(new BacnetEventNotificationData.BacnetNotifyTypes()));

            case BacnetPropertyIds.PROP_EVENT_TYPE:
                return(new BacnetEnumValueDisplay(new BacnetEventNotificationData.BacnetEventTypes()));

            case BacnetPropertyIds.PROP_EVENT_STATE:
                return(new BacnetEnumValueDisplay(new BacnetEventNotificationData.BacnetEventStates()));

            case BacnetPropertyIds.PROP_POLARITY:
                return(new BacnetEnumValueDisplay(new BacnetPolarity()));

            case BacnetPropertyIds.PROP_UNITS:
                return(new BacnetEnumValueDisplay(new BacnetUnitsId()));

            case BacnetPropertyIds.PROP_RELIABILITY:
                return(new BacnetEnumValueDisplay(new BacnetReliability()));

            case BacnetPropertyIds.PROP_SEGMENTATION_SUPPORTED:
                return(new BacnetEnumValueDisplay(new BacnetSegmentations()));

            case BacnetPropertyIds.PROP_SYSTEM_STATUS:
                return(new BacnetEnumValueDisplay(new BacnetDeviceStatus()));

            case BacnetPropertyIds.PROP_LAST_RESTART_REASON:
                return(new BacnetEnumValueDisplay(new BacnetRestartReason()));

            case BacnetPropertyIds.PROP_PRIORITY_FOR_WRITING:
                return(new BacnetEnumValueDisplay(new BacnetWritePriority()));

            default:
                return(base.GetEditor(editorBaseType));
            }
        }
        /*****************************************************************************************************/
        static void handler_OnReadRange(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId objectId, BacnetPropertyReference property, System.IO.BACnet.Serialize.BacnetReadRangeRequestTypes requestType, uint position, DateTime time, int count, BacnetMaxSegments max_segments)
        {
            lock (device)
            {
                BaCSharpObject trend = device.FindBacnetObject(objectId);

                if (trend is TrendLog)
                {
                    BacnetResultFlags status;
                    byte[]            application_data = (trend as TrendLog).GetEncodedTrends(position, count, out status);

                    if (application_data != null)
                    {
                        //send
                        sender.ReadRangeResponse(adr, invoke_id, sender.GetSegmentBuffer(max_segments), objectId, property, status, (uint)count, application_data, requestType, position);
                    }
                }
                else
                {
                    sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_RANGE, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER);
                }
            }
        }