示例#1
0
        void handler_OnDeleteObjectRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetMaxSegments max_segments)
        {
            //check if exists; if doesn't send error Unknown_Object
            if (device.FindBacnetObject(object_id) == null)
            {
                sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_CREATE_OBJECT, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_OBJECT);
                return;
            }

            // check if objecttype is allowed to be deleted, like for example Device switch() for adding more types which cant be deleted
            // Device not removable, no need to check
            switch (object_id.type)
            {
            case BacnetObjectTypes.OBJECT_ACCESS_DOOR:      // just to shows how to do
                sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_CREATE_OBJECT, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_OBJECT_DELETION_NOT_PERMITTED);
                return;

            default:
                break;
            }
            //remove from device and send ACK normally there should be no error!!!!!!!
            if (device.RemoveBacnetObject(object_id) == true)
            {
                sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_DELETE_OBJECT, invoke_id);
            }
            else
            {
                Console.WriteLine("unknown Error while deleting object!");
            }
            return;
        }
        static void handler_OnDeleteObjectRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetMaxSegments max_segments)
        {
            //check if exists; if doesn't send error Unknown_Object
            if (device.FindBacnetObject(object_id) == null)
            {
                sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_DELETE_OBJECT, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_UNKNOWN_OBJECT);
                return;
            }

            //remove from device and send ACK normally there should be no error!!!!!!!
            // Attribut AcceptDeleteObject should be true for deletable objects
            if (device.RemoveBacnetObject(object_id) == true)
            {
                sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_DELETE_OBJECT, invoke_id);
            }
            else
            {
                sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_DELETE_OBJECT, invoke_id, BacnetErrorClasses.ERROR_CLASS_OBJECT, BacnetErrorCodes.ERROR_CODE_OBJECT_DELETION_NOT_PERMITTED);
            }
            return;
        }