コード例 #1
0
        private void button6_Click(object sender, EventArgs e)
        {
            BACNET_EVENT_NOTIFICATION_DATA      data   = new BACNET_EVENT_NOTIFICATION_DATA();
            UnconfirmedEventNotificationService unconf = new UnconfirmedEventNotificationService();

            data.processIdentifier = 123;
            data.ackRequired       = true;
            BACNET_OBJECT_ID obj_id = new BACNET_OBJECT_ID();

            obj_id.type                = (UInt16)BACNET_OBJECT_TYPE.BACNET_LIFT;
            obj_id.instance            = Form_main.lift_list[0].Object_Identifier.instance;
            data.eventObjectIdentifier = obj_id;
            data.eventType             = BACNET_EVENT_TYPE.EVENT_CHANGE_OF_LIFE_SAFETY;
            data.fromState             = BACNET_EVENT_STATE.EVENT_STATE_NORMAL;
            data.timeStamp             = Form_main.lift_list[0].Time_Stamps;
            data.notifyType            = BACNET_NOTIFY_TYPE.NOTIFY_ALARM;
            data.toState               = BACNET_EVENT_STATE.EVENT_STATE_FAULT;
            data.priority              = 3;


            BACNET_OBJECT_ID obj_temp = new BACNET_OBJECT_ID();

            obj_temp.type     = (UInt16)BACNET_OBJECT_TYPE.OBJECT_DEVICE;
            obj_temp.instance = 9527;
            data.notificationParams.change_of_lifesafety.statusFlags.set_bits_used(1, 5);
            data.notificationParams.change_of_lifesafety.statusFlags.set_octet(0, 4);
            data.notificationParams.change_of_lifesafety.newState          = BACNET_LIFE_SAFETY_STATE.LIFE_SAFETY_STATE_ALARM;
            data.notificationParams.change_of_lifesafety.newMode           = BACNET_LIFE_SAFETY_MODE.LIFE_SAFETY_MODE_DISABLED;
            data.notificationParams.change_of_lifesafety.operationExpected = BACNET_LIFE_SAFETY_OPERATION.LIFE_SAFETY_OP_RESET_ALARM;

            //  data.notificationParams.newState.tag = BACNET_PROPERTY_STATE_TYPE.UNSIGNED_VALUE;
            //    data.notificationParams.newState.value = 100;
            //    data.notificationParams.statusFlags.set_bits_used(1, 5);
            //    data.notificationParams.statusFlags.set_octet(0,4);



            data.initiatingObjectIdentifier = obj_temp;
            data.notificationClass          = 123;



            Byte[] buff = new Byte[1024];


            int Send_len = unconf.Unconfirmed_Event_Notification_Pack(ref buff, ref data);

            IPEndPoint dest    = new IPEndPoint(IPAddress.Parse("10.10.161.153"), 60);//假设60测试?
            UdpSender  sendder = new UdpSender(ref buff, dest);

            sendder.Send(Send_len);
        }
コード例 #2
0
        public void Read_Property_Handler(ref Byte[] request, UInt16 request_len, ref BACNET_ADDRESS src, ref BACNET_CONFIRMED_SERVICE_DATA request_data)
        {
            Byte[] buffer = new Byte[1024];
            BACnet_Read_Property_Data rpdata = new BACnet_Read_Property_Data();
            int len      = 0;
            int pdu_len  = 0;
            int apdu_len = -1;
            int npdu_len = -1;
            BACNET_NPDU_DATA npdu_data = new BACNET_NPDU_DATA();
            bool             error     = true; /* assume that there is an error */
            int            bytes_sent  = 0;
            BACNET_ADDRESS my_address  = new BACNET_ADDRESS();

            BacnetAddresssProcessor.Get_My_Address(ref my_address);
            NpduProcessor n_pro = new NpduProcessor();
            BvlcProcessor b_pro = new BvlcProcessor();

            n_pro.Encode_NpduData(ref npdu_data, false, BACNET_MESSAGE_PRIORITY.MESSAGE_PRIORITY_NORMAL);
            npdu_len = n_pro.Encode(ref buffer, ref src, ref my_address, ref npdu_data);
            //  if (service_data.segmented_message)
            /* we don't support segmentation - send an abort */
            len = Decode_Service_Request(ref request, request_len, ref rpdata);

            len     = Read_Property_ACK_Pack_Int(ref buffer, request_data.invoke_id, ref rpdata, npdu_len);
            pdu_len = npdu_len + len;

            bytes_sent = b_pro.Encode(ref buffer, ref src, ref npdu_data, pdu_len);



            IPEndPoint Ipep = new IPEndPoint(
                IPAddress.Parse("10.10.161.153"), 60);
            UdpSender udpsendr = new UdpSender(ref buffer, Ipep);

            udpsendr.Send(bytes_sent);
        }