コード例 #1
0
ファイル: BACnetHelper.cs プロジェクト: dgiot/dgiot_dtu
        // 逐个扫点,速度较慢
        public static void ScanPointSingle(BacDevice device, uint count)
        {
            if (device == null)
            {
                return;
            }

            var pid       = BacnetPropertyIds.PROP_OBJECT_LIST;
            var device_id = device.DeviceId;
            var bobj      = new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, device_id);
            var adr       = device.Address;

            if (adr == null)
            {
                return;
            }

            device.Properties = new List <BacProperty>();

            for (uint index = 1; index <= count; index++)
            {
                try
                {
                    var list = ReadScalarValue(adr, bobj, pid, GetCurrentInvokeId(), index);
                    if (list == null)
                    {
                        continue;
                    }

                    foreach (var bValue in list)
                    {
                        var strBValue = "" + bValue.Value;
                        LogHelper.Log(pid + " , " + strBValue + " , " + bValue.Tag);
                        var strs = strBValue.Split(':');
                        if (strs.Length < 2)
                        {
                            continue;
                        }

                        var strType  = strs[0];
                        var strObjId = strs[1];
                        var subNode  = new BacProperty();
                        BacnetObjectTypes otype;
                        Enum.TryParse(strType, out otype);
                        subNode.ObjectId = new BacnetObjectId(otype, Convert.ToUInt32(strObjId));
                        device.Properties.Add(subNode);
                    }
                }
                catch (Exception exp)
                {
                    LogHelper.Log("Error: " + index + " , " + exp.Message);
                }
            }
        }
コード例 #2
0
ファイル: BACnetHelper.cs プロジェクト: dgiot/dgiot_dtu
        // 批量扫点,注意不要太多,超过maxAPDU失败
        public static void ScanPointsBatch(BacDevice device, uint count)
        {
            try
            {
                if (device == null)
                {
                    return;
                }

                var pid       = BacnetPropertyIds.PROP_OBJECT_LIST;
                var device_id = device.DeviceId;
                var bobj      = new BacnetObjectId(BacnetObjectTypes.OBJECT_DEVICE, device_id);
                var adr       = device.Address;
                if (adr == null)
                {
                    return;
                }

                device.Properties = new List <BacProperty>();

                List <BacnetPropertyReference> rList = new List <BacnetPropertyReference>();

                for (uint i = 1; i < count; i++)
                {
                    rList.Add(new BacnetPropertyReference((uint)pid, i));
                    if (i % scanBatchStep == 0 || i == count) // 不要超了 MaxAPDU
                    {
                        IList <BacnetReadAccessResult> lstAccessRst;
                        var bRst = bacnetClient.ReadPropertyMultipleRequest(adr, bobj, rList, out lstAccessRst, GetCurrentInvokeId());
                        if (bRst)
                        {
                            foreach (var aRst in lstAccessRst)
                            {
                                if (aRst.values == null)
                                {
                                    continue;
                                }

                                foreach (var bPValue in aRst.values)
                                {
                                    if (bPValue.value == null)
                                    {
                                        continue;
                                    }

                                    foreach (var bValue in bPValue.value)
                                    {
                                        var strBValue = "" + bValue.Value;

                                        // mainform.Log(pid + " , " + strBValue + " , " + bValue.Tag);
                                        var strs = strBValue.Split(':');
                                        if (strs.Length < 2)
                                        {
                                            continue;
                                        }

                                        var strType  = strs[0];
                                        var strObjId = strs[1];
                                        var subNode  = new BacProperty();
                                        BacnetObjectTypes otype;
                                        Enum.TryParse(strType, out otype);
                                        if (otype == BacnetObjectTypes.OBJECT_NOTIFICATION_CLASS || otype == BacnetObjectTypes.OBJECT_DEVICE)
                                        {
                                            continue;
                                        }

                                        subNode.ObjectId = new BacnetObjectId(otype, Convert.ToUInt32(strObjId));
                                        device.Properties.Add(subNode);
                                    }
                                }
                            }
                        }

                        rList.Clear();
                    }
                }
            }
            catch (Exception)
            {
            }
        }