private void OkBtn_Click(object sender, EventArgs e) { try { string str = converter.GetDescription(LogicalNameTb.Text, (ObjectType)ObjectTypeCb.SelectedItem)[0]; if (!ShortNameTb.ReadOnly && str.CompareTo("Invalid") == 0) { throw new Exception(Properties.Resources.InvalidObisCode); } if (ObjectTypeCb.SelectedItem == null) { throw new Exception(Properties.Resources.InvalidTarget); } if (string.IsNullOrEmpty(LogicalNameTb.Text)) { throw new Exception(Properties.Resources.InvalidObisCode); } if (Target == null || Target.ObjectType != (ObjectType)ObjectTypeCb.SelectedItem) { Target = GXDLMSClient.CreateObject((ObjectType)ObjectTypeCb.SelectedItem); } Target.Version = (int)VersionCb.SelectedItem; Target.LogicalName = LogicalNameTb.Text; if (ShortNameTb.Visible) { Target.ShortName = UInt16.Parse(ShortNameTb.Text); } //Update access rights. } catch (Exception ex) { DialogResult = DialogResult.None; MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void ReadCMnu_Click(object sender, EventArgs e) { try { if (Devices.SelectedNode != null) { GXDLMSMeter dev = Devices.SelectedNode.Tag as GXDLMSMeter; List <KeyValuePair <GXDLMSObject, byte> > objects = new List <KeyValuePair <GXDLMSObject, byte> >(); //Read association view if there are no objects on the meter. if (dev.Objects.Count == 0) { objects.Add(new KeyValuePair <GXDLMSObject, byte>(new GXDLMSAssociationLogicalName(), 2)); } target.ReadObjects(new GXDLMSMeter[] { dev }, objects); if (dev.Objects.Count == 0) { //Add all objects. TreeNode n = nodes[dev]; List <TreeNode> list = new List <TreeNode>(); foreach (GXDLMSObject it in (objects[0].Key as GXDLMSAssociationLogicalName).ObjectList) { GXManufacturer m = Manufacturers.FindByIdentification(dev.Manufacturer); if (m.ObisCodes != null) { GXDLMSConverter c = new GXDLMSConverter(); GXObisCode oc = m.ObisCodes.FindByLN(it.ObjectType, it.LogicalName, null); if (string.IsNullOrEmpty(it.Description)) { it.Description = c.GetDescription(it.LogicalName, it.ObjectType)[0]; } if (oc != null) { MainForm.UpdateAttributes(it, oc); } } TreeNode t = new TreeNode(it.LogicalName + " " + it.Description); t.Tag = it; list.Add(t); } n.Nodes.AddRange(list.ToArray()); } } } catch (Exception ex) { MessageBox.Show(this, ex.Message); } }
void UpdateTarget() { //If logical name is not given set default value. if (string.IsNullOrEmpty(Target.LogicalName)) { Target.LogicalName = "0.0.0.0.0.255"; } Target.Attributes.Clear(); GXObisCode code = ObisCodeCollection.FindByLN(Target.ObjectType, Target.LogicalName, null); if (code != null && code.Attributes != null) { Target.Attributes.AddRange(code.Attributes); Target.Description = code.Description; } else { Target.Description = converter.GetDescription(Target.LogicalName, Target.ObjectType)[0]; } ObisPropertyGrid.SelectedObject = Target; InterfaceCB.SelectedItem = Target; }