public virtual bool RemoveBacnetObject(BacnetObjectId objId) { BaCSharpObject obj = FindBacnetObject(objId); // device object cannot be deleted, even if AcceptDeleteObject is set to true if ((obj.AcceptDeleteObject == false) || (obj == this)) { return(false); } obj.Dispose(); foreach (var o in m_PROP_OBJECT_LIST) { if (o.ToString() == objId.ToString()) { m_PROP_OBJECT_LIST.Remove(o); break; } } foreach (var o in m_PROP_STRUCTURED_OBJECT_LIST) { if (o.ToString() == objId.ToString()) { m_PROP_STRUCTURED_OBJECT_LIST.Remove(o); break; } } return(ObjectsList.Remove(obj)); //since we wont remove object device!!!! using LIST Remove!! }
public NotificationEditor(BacnetClient comm, BacnetAddress adr, BacnetObjectId object_id) { this.comm = comm; this.adr = adr; this.object_id = object_id; InitializeComponent(); LoadProperties(); labelRecipient.Text = "Recipient List : " + object_id.ToString().Substring(7); }
/*****************************************************************************************************/ static void handler_OnCOVNotification(BacnetClient sender, BacnetAddress adr, byte invoke_id, uint subscriberProcessIdentifier, BacnetObjectId initiatingDeviceIdentifier, BacnetObjectId monitoredObjectIdentifier, uint timeRemaining, bool need_confirm, ICollection <BacnetPropertyValue> values, BacnetMaxSegments max_segments) { Console.Write(monitoredObjectIdentifier.ToString() + " COV : "); foreach (BacnetPropertyValue value in values) { switch ((BacnetPropertyIds)value.property.propertyIdentifier) { case BacnetPropertyIds.PROP_PRESENT_VALUE: Console.WriteLine(value.value[0].ToString()); break; case BacnetPropertyIds.PROP_STATUS_FLAGS: string status_text = ""; if (value.value != null && value.value.Count > 0) { BacnetStatusFlags status = (BacnetStatusFlags)((BacnetBitString)value.value[0].Value).ConvertToInt(); if ((status & BacnetStatusFlags.STATUS_FLAG_FAULT) == BacnetStatusFlags.STATUS_FLAG_FAULT) { status_text += "FAULT,"; } else if ((status & BacnetStatusFlags.STATUS_FLAG_IN_ALARM) == BacnetStatusFlags.STATUS_FLAG_IN_ALARM) { status_text += "ALARM,"; } else if ((status & BacnetStatusFlags.STATUS_FLAG_OUT_OF_SERVICE) == BacnetStatusFlags.STATUS_FLAG_OUT_OF_SERVICE) { status_text += "OOS,"; } else if ((status & BacnetStatusFlags.STATUS_FLAG_OVERRIDDEN) == BacnetStatusFlags.STATUS_FLAG_OVERRIDDEN) { status_text += "OR,"; } } if (status_text != "") { Console.WriteLine(status_text); } break; default: //got something else? ignore it break; } } if (need_confirm) { sender.SimpleAckResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_COV_NOTIFICATION, invoke_id); } }
void CheckAllObjects(TreeNodeCollection tncol) { foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree { Application.DoEvents(); BacnetObjectId object_id = (BacnetObjectId)tn.Tag; String Identifier = null; lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier); try { IList <BacnetValue> value; // read OutOfService property on all objects (maybe a test could be done to avoid call without interest) bool ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_OUT_OF_SERVICE, out value); // another solution with ReadPropertyMultipleRequest, but not supported by simple devices // ... can also read these two properties on all objects in one time (with segmentation on huge devices) /* * BacnetReadAccessSpecification[] bras = new BacnetReadAccessSpecification[1]; * bras[0].objectIdentifier = object_id; * bras[0].propertyReferences = new BacnetPropertyReference[2]; * bras[0].propertyReferences[0] = new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_RELIABILITY, ASN1.BACNET_ARRAY_ALL); * bras[0].propertyReferences[1] = new BacnetPropertyReference((uint)BacnetPropertyIds.PROP_DESCRIPTION, ASN1.BACNET_ARRAY_ALL); * IList<BacnetReadAccessResult> res; * ret=client.ReadPropertyMultipleRequest(adr, bras, out res); // it's a read multiple properties on multiple objects * value = res[0].values[0].value; // for PROP_RELIABILITY * value = res[0].values[1].value; // for PROP_DESCRIPTION */ if (ret) { if ((bool)value[0].Value != false) // different than FALSE { IsEmpty = false; string name = object_id.ToString(); if (name.StartsWith("OBJECT_")) { name = name.Substring(7); } TreeNode N; if (Identifier != null) { N = treeView1.Nodes.Add(Identifier + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()) + ")"); } else { N = treeView1.Nodes.Add(name); } string reliability = ((BacnetReliability)value[0].Value).ToString(); reliability = reliability.Replace('_', ' '); reliability = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(reliability.ToLower()); N.Nodes.Add(reliability); N.Nodes.Add(name); // PROP_DESCRIPTION //... if ReadPropertyMultipleRequest uses value = res[0].values[1].value /* * ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value); // with Description * if (ret) * N.Nodes.Add(value[0].Value.ToString()); */ } } } catch { } if (tn.Nodes != null) // go deap into the tree { CheckAllObjects(tn.Nodes); } } }
private void handler_OnReadPropertyRequest(BacnetClient sender, BacnetAddress adr, byte invoke_id, BacnetObjectId object_id, BacnetPropertyReference property, BacnetMaxSegments max_segments) { lock (m_storage) { _logger.LogInformation($"Read property request for {property.ToString()} of {object_id.ToString()} from {adr.ToString()}."); try { IList <BacnetValue> value; DeviceStorage.ErrorCodes code = m_storage.ReadProperty(object_id, (BacnetPropertyIds)property.propertyIdentifier, property.propertyArrayIndex, out value); if (code == DeviceStorage.ErrorCodes.Good) { sender.ReadPropertyResponse(adr, invoke_id, sender.GetSegmentBuffer(max_segments), object_id, property, value); } else { sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER); } } catch (Exception) { sender.ErrorResponse(adr, BacnetConfirmedServices.SERVICE_CONFIRMED_READ_PROPERTY, invoke_id, BacnetErrorClasses.ERROR_CLASS_DEVICE, BacnetErrorCodes.ERROR_CODE_OTHER); } } }
public override string ToString() { return(m_PROP_OBJECT_IDENTIFIER.ToString()); }
void CheckAllObjects(TreeNodeCollection tncol) { foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree { Application.DoEvents(); BacnetObjectId object_id = (BacnetObjectId)tn.Tag; String Identifier = null; lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier); try { IList <BacnetValue> value; // read PROP_STATUS_FLAGS property on all objects (maybe a test could be done to avoid call without interest) bool ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_STATUS_FLAGS, out value); if (ret) { if (value[0].Value.ToString() != "0000") // some flags are set { IsEmpty = false; string name = object_id.ToString(); if (name.StartsWith("OBJECT_")) { name = name.Substring(7); } TreeNode N; if (Identifier != null) { N = treeView1.Nodes.Add(Identifier + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()) + ")"); } else { N = treeView1.Nodes.Add(name); } N.SelectedImageIndex = N.ImageIndex = 4; // Get the description IList <BacnetValue> value_descr; ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value_descr); if (ret) { N.Nodes.Add(new TreeNode(value_descr[0].Value.ToString(), 5, 5)); } for (int i = 0; i < 4; i++) { if (value[0].Value.ToString()[i] == '1') { String s = Enum.GetName(typeof(BacnetStatusFlags), 1 << i).Replace("_", " "); string alm = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s.ToLower()); N.Nodes.Add(new TreeNode(alm.Substring(12), i, i)); } } } } } catch { } if (tn.Nodes != null) // go deap into the tree { CheckAllObjects(tn.Nodes); } } }
void CheckAllObjects(TreeNodeCollection tncol) { foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree { Application.DoEvents(); BacnetObjectId object_id = (BacnetObjectId)tn.Tag; if (Filter.Contains(object_id.type)) // Only for some objects { String Identifier = null; lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier); try { IList <BacnetValue> value; bool ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_PRESENT_VALUE, out value); // with PRESENT_VALUE string Present_Value = value[0].Value.ToString(); float PresentValue = float.Parse(Present_Value); ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value); // with Description string Description = value[0].Value.ToString(); ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_RELINQUISH_DEFAULT, out value); // with Relinquish_Default string Relinquish_Default = value[0].Value.ToString(); float RelinquishDefault = float.Parse(Relinquish_Default); if (ret) { // IsEmpty = false; string name = object_id.ToString(); if (name.StartsWith("OBJECT_")) { name = name.Substring(7); } string[] name1 = name.Split(new Char[] { ':' }); int InstanceNumber = Int32.Parse(name1[1]); { ListAnalogValues.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; ListAnalogValues.EnableHeadersVisualStyles = false; ListAnalogValues.EnableHeadersVisualStyles = false; ListAnalogValues.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue; ListAnalogValues.DefaultCellStyle.BackColor = Color.White; // Create a new row first as it will include the columns you've created at design-time. int rowId = ListAnalogValues.Rows.Add(); // Grab the new row! { DataGridViewRow row = ListAnalogValues.Rows[rowId]; if (Identifier != null) // Add the data { row.Cells["Column1"].Value = Identifier; row.Cells["Column2"].Value = name1[0]; row.Cells["Column3"].Value = InstanceNumber; row.Cells["Column4"].Value = Description; row.Cells["Column5"].Value = PresentValue; row.Cells["Column6"].Value = RelinquishDefault; } else { row.Cells["Column1"].Value = ""; } row.Cells["Column2"].Value = name1[0]; row.Cells["Column3"].Value = InstanceNumber; row.Cells["Column4"].Value = Description; row.Cells["Column5"].Value = PresentValue; row.Cells["Column6"].Value = RelinquishDefault; } } } } catch { } } if (tn.Nodes != null) // go deap into the tree { CheckAllObjects(tn.Nodes); } } }
void CheckAllObjects(TreeNodeCollection tncol) { foreach (TreeNode tn in tncol) // gets all nodes into the AddressSpaceTree { Application.DoEvents(); BacnetObjectId object_id = (BacnetObjectId)tn.Tag; if (Filter.Contains(object_id.type)) // Only for some objects { String Identifier = null; lock (yabeFrm.DevicesObjectsName) // translate to it's name if already known yabeFrm.DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), object_id), out Identifier); try { IList <BacnetValue> value; // read COV_Increment property on all objects (maybe a test could be done to avoid call without interest) bool ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_COV_INCREMENT, out value); string Increment = value[0].Value.ToString(); if (ret) { string Units = ""; try { // read Units property on all objects (maybe a test could be done to avoid call without interest) ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_UNITS, out value); Units = ((BacnetUnitsId)((uint)value[0].Value)).ToString(); if (Units.StartsWith("UNITS_")) { Units = Units.Substring(6); } Units = Units.Replace("_", " "); Units = System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(Units.ToLower()); } catch { }; IsEmpty = false; string name = object_id.ToString(); if (name.StartsWith("OBJECT_")) { name = name.Substring(7); } TreeNode N; if (Identifier != null) { N = treeView1.Nodes.Add(Identifier + " (" + System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(name.ToLower()) + ")"); } else { N = treeView1.Nodes.Add(name); } ret = client.ReadPropertyRequest(adr, object_id, BacnetPropertyIds.PROP_DESCRIPTION, out value); // with Description if (ret) { N.Nodes.Add(value[0].Value.ToString()); } N.Nodes.Add(("Value = ") + Increment + " " + Units); } } catch { } } if (tn.Nodes != null) // go deap into the tree { CheckAllObjects(tn.Nodes); } } }