public WriteProperty(BacNetObject bacNetObject, BacNetEnums.BACNET_PROPERTY_ID propertyId, ArrayList valueList) { ObjectId = bacNetObject; PropertyId = new BacNetUInt(); PropertyId.Value = (uint) propertyId; ValueList = valueList; InvokeId = BacNetDevice.Instance.InvokeId; }
public ArrayList ReadProperty(UInt16 destinationAddress, BacNetObject bacNetObject, BacNetEnums.BACNET_PROPERTY_ID propertyId) { var apdu = new ReadProperty(bacNetObject, propertyId); var npdu = new BacNetIpNpdu(); npdu.ExpectingReply = true; BacNetRemoteDevice remote = null; foreach (BacNetRemoteDevice remoteDevice in BacNetDevice.Instance.Remote) if (remoteDevice.InstanceNumber == destinationAddress) remote = remoteDevice; if (remote != null) { npdu.Destination = remote.BacAddress; BacNetDevice.Instance.Services.Execute(npdu, apdu, remote.EndPoint); BacNetDevice.Instance.Waiter = apdu.InvokeId; return WaitForResponce(apdu.InvokeId) as ArrayList; } return null; }
public void WriteProperty(uint instanceId, BacNetObject bacNetObject, BacNetEnums.BACNET_PROPERTY_ID propertyId, ArrayList valueList, WritePropertyDelegate callBack = null) { var apdu = new WriteProperty(bacNetObject, propertyId, valueList); apdu.InstanceId = instanceId; apdu.CallBack = callBack; var npdu = new BacNetIpNpdu(); npdu.ExpectingReply = true; IPEndPoint endPoint = null; foreach (BacNetRemoteDevice remoteDevice in BacNetDevice.Instance.Remote) { if (remoteDevice.InstanceNumber == instanceId) { npdu.Destination = remoteDevice.BacAddress; endPoint = remoteDevice.EndPoint; } } lock (_writePropertyPool) { if (_writePropertyPool.ContainsKey(apdu.InvokeId)) { _writePropertyPool[apdu.InvokeId].CallBack(_writePropertyPool[apdu.InvokeId].InstanceId, null, null); _writePropertyPool.Remove(apdu.InvokeId); } _writePropertyPool.Add(apdu.InvokeId, apdu); } BacNetDevice.Instance.Services.Execute(npdu, apdu, endPoint); }
public bool? SubscribeCOV(string address, BacNetEnums.BACNET_PROPERTY_ID propId = BacNetEnums.BACNET_PROPERTY_ID.PROP_PRESENT_VALUE) { string[] addrArray = address.Split('.'); if (addrArray.Length != 2) { _logger.Warn("Wrong address: " + address); return null; } BacNetRemoteDevice remote = BacNetDevice.Instance.SearchRemote(BacNetRemoteDevice.Get(addrArray[0])); if (remote == null) { _logger.Warn("No such device in network. Device number: " + addrArray[0]); return null; } BacNetObject tmpObj; try { tmpObj = new BacNetObject(addrArray[1]); } catch (Exception ex) { _logger.Warn(ex.Message); return null; } BacNetObject obj = remote.Objects.FirstOrDefault(s => s.ObjectId == tmpObj.ObjectId && s.ObjectType == tmpObj.ObjectType); if (obj == null) { remote.Objects.Add(tmpObj); obj = tmpObj; } var apdu = new SubscribeCOV(obj) { ProccessId = new BacNetUInt(5556) }; var npdu = new BacNetIpNpdu { ExpectingReply = true, Destination = remote.BacAddress }; BacNetDevice.Instance.Waiter = apdu.InvokeId; BacNetDevice.Instance.Services.Execute(npdu, apdu, remote.EndPoint); ArrayList valueList = WaitForResponce(apdu.InvokeId) as ArrayList; /*BacNetProperty property = obj.Properties.FirstOrDefault(s => s.PropertyId.Value == (uint)propId); if (property != null) property.Values = valueList ?? new ArrayList(); else { property = new BacNetProperty { PropertyId = new BacNetUInt { Value = (uint)propId }, Values = valueList ?? new ArrayList() }; obj.Properties.Add(property); } return property;*/ return true; }
public void ReceivedErrorAck(BacNetRawMessage msg) { ErrorAck apdu = new ErrorAck(msg.Apdu); if (apdu.ServiceChoise == 12) { ArrayList res = new ArrayList(); res.Add(apdu.ErrorCode); if (BacNetDevice.Instance.Waiter is int && Convert.ToInt32(BacNetDevice.Instance.Waiter) == apdu.InvokeId) { BacNetDevice.Instance.Waiter = res; } } if (apdu.ServiceChoise == 15) { BacNetDevice.Instance.Services.Confirmed.WritePropertyCallBack(apdu.InvokeId, BacNetEnums.GetErrorMessage((byte)apdu.ErrorCode)); } }