//逐个扫点,速度较慢 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; Console.WriteLine(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) { Console.WriteLine("Error: " + index + " , " + exp.Message); } } }
//批量扫点,注意不要太多,超过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 = Bacnet_client.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; Console.WriteLine(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) { } }