private void FillTreeNode() { bool EmptyList = (TAlarmList.Nodes.Count == 0); int icon; TAlarmList.BeginUpdate(); // Only one network read request to get the object name int _retries = comm.Retries; comm.Retries = 1; int Idx = 0; // fill the Treenode foreach (BacnetGetEventInformationData alarm in Alarms) { TreeNode currentTn; // get or set the Node if (EmptyList == true) { String nameStr = null; lock (DevicesObjectsName) DevicesObjectsName.TryGetValue(new Tuple <String, BacnetObjectId>(adr.FullHashString(), alarm.objectIdentifier), out nameStr); if (nameStr == null) { // Get the property Name, network activity, time consuming IList <BacnetValue> name; bool retcode = comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_OBJECT_NAME, out name); if (retcode) { nameStr = name[0].Value.ToString(); lock (DevicesObjectsName) DevicesObjectsName.Add(new Tuple <String, BacnetObjectId>(adr.FullHashString(), alarm.objectIdentifier), nameStr); } } icon = MainDialog.GetIconNum(alarm.objectIdentifier.type); if (nameStr != null) { currentTn = new TreeNode(nameStr, icon, icon); currentTn.ToolTipText = alarm.objectIdentifier.ToString(); } else { currentTn = new TreeNode(alarm.objectIdentifier.ToString(), icon, icon); } currentTn.Tag = alarm; TAlarmList.Nodes.Add(currentTn); } else { currentTn = TAlarmList.Nodes[Idx++]; currentTn.Nodes.Clear(); } if (Properties.Settings.Default.DescriptionInAlarmSummary) { String Descr = ""; try { // Get the Description, network activity, time consuming IList <BacnetValue> name; bool retcode = comm.ReadPropertyRequest(adr, alarm.objectIdentifier, BacnetPropertyIds.PROP_DESCRIPTION, out name); if (retcode) { Descr = name[0].Value.ToString(); } } catch { } currentTn.Nodes.Add(new TreeNode("Description : " + Descr, Int32.MaxValue, Int32.MaxValue)); } icon = Int32.MaxValue; // out bound currentTn.Nodes.Add(new TreeNode("Alarm state : " + GetEventStateNiceName(alarm.eventState.ToString()), icon, icon)); bool SomeTodo = false; TreeNode tn2 = new TreeNode("Ack Required :", icon, icon); for (int i = 0; i < 3; i++) { if (alarm.acknowledgedTransitions.ToString()[i] == '0') { BacnetEventNotificationData.BacnetEventEnable bee = (BacnetEventNotificationData.BacnetEventEnable)(1 << i); String text = GetEventEnableNiceName(bee.ToString()) + " since " + alarm.eventTimeStamps[i].Time.ToString(); tn2.Nodes.Add(new TreeNode(text, icon, icon)); SomeTodo = true; } } if (SomeTodo == false) { tn2 = new TreeNode("No Ack Required, already done", icon, icon); } currentTn.Nodes.Add(tn2); } // set back the request retries number comm.Retries = _retries; TAlarmList.EndUpdate(); TAlarmList.ExpandAll(); if (Alarms.Count == 0) { LblInfo.Visible = true; LblInfo.Text = "Empty event list ... all is OK"; } }
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); } } }
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; 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; // 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); } } }