コード例 #1
0
        public override void Execute()
        {
            try
            {
                _apm.MessageLog("Executing " + diagnosticName);

                ClearIncomingPacketQueue();

                // find a non-existing network number in the whole attached BACnet internetwork by examining our internal router table that
                // has been built up during device discovery phase
                int useThisNetworkNumber = 9;
                for (int i = 0xfffe; i > 1; i--)
                {
                    if (_apm.internalRouterInfo.FindRoutingTableEntry(i) == null)
                    {
                        // we have not seen or used this network number yet
                        useThisNetworkNumber = i;
                        break;
                    }
                }

                //                BACnetUtil.SendReadProperty(_apm, _bnm, deviceNode.device, deviceNode.device.deviceObjectID, BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE);

                BACnetPacket pkt = new BACnetPacket(_apm);
                // pkt.EncodeBVLL(new DADR(deviceNode.device.adr), BACnetEnums.BACNET_BVLC_FUNCTION.BVLC_ORIGINAL_UNICAST_NPDU);
                pkt.EncodeNPCI(new DADR(devicTreeNode.device.adr), new ADR((ushort)useThisNetworkNumber, (uint)3), BACnetLibrary.BACnetPacket.MESSAGE_TYPE.APPLICATION);
                // todonow, put these next steps into functions
                // build confirmed request header
                // http://www.bacnetwiki.com/wiki/index.php?title=BACnet-Confirmed-Request-PDU
                pkt.buffer[pkt.optr++] = (Byte)BACnetEnums.BACNET_PDU_TYPE.PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
                pkt.buffer[pkt.optr++] = 0x05;  // max segs, max resp. todo
                pkt.buffer[pkt.optr++] = _apm.invokeID++;
                // sequence number may come next, dep on flags. todo
                pkt.buffer[pkt.optr++] = (byte)BACnetEnums.BACNET_CONFIRMED_SERVICE.SERVICE_CONFIRMED_READ_PROPERTY;
                // context encoding
                // http://www.bacnetwiki.com/wiki/index.php?title=Read_Property
                devicTreeNode.device.deviceObjectID.Encode(pkt.buffer, ref pkt.optr);
                BACnetUtil.EncodeContextTag(pkt.buffer, ref pkt.optr, 1, (int)BACnetEnums.BACNET_PROPERTY_ID.PROP_OBJECT_TYPE);
                BACnetUtil.SendOffPacket(_apm, _bnm, pkt, pkt.buffer, pkt.optr);

                BACnetPacket respPkt = waitForPacket(5000);
            }
            catch (TimeoutException)
            {
                // todo-put a wrapper around execute and catch all executions in a common area..
                MarkDiagnosticFailed("Timeout");
                return;
            }
            catch (Exception ex)
            {
                // other types of exception...
                throw ex;
            }

            MarkDiagnosticSuccess();
        }