Ejemplo n.º 1
0
        /// <summary>
        /// Update simulated values for the meter instance.
        /// </summary>
        /// <param name="items">Simulated COSEM objects.</param>
        void UpdateValues(GXDLMSObjectCollection items)
        {
            //Update COSEM Logical Device Name
            GXDLMSData d = items.FindByLN(ObjectType.Data, "0.0.42.0.0.255") as GXDLMSData;

            if (d != null && d.Value is string v)
            {
                d.Value = string.Format("{0}{1}", v.Substring(0, 3), serialNumber.ToString("D13"));
            }

            //Update Meter serial number.
            d = items.FindByLN(ObjectType.Data, "0.0.96.1.0.255") as GXDLMSData;
            if (d != null && d.Value is string v2)
            {
                string tmp = "";
                foreach (char it in v2)
                {
                    //Append chars.
                    if (it < 0x30 || it > 0x39)
                    {
                        tmp += it;
                    }
                    else
                    {
                        break;
                    }
                }
                d.Value = tmp + serialNumber.ToString("D" + Convert.ToString(v2.Length - tmp.Length));
            }
        }
Ejemplo n.º 2
0
 public GXDLMSProfileGenericColumnDlg(
     GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> target, GXDLMSObjectCollection list, string title)
 {
     Target     = target;
     AllObjects = new GXDLMSObjectCollection();
     AllObjects.AddRange(list);
     //Remove not needed objects.
     foreach (GXDLMSObject it in list.GetObjects(new ObjectType[] { ObjectType.AssociationLogicalName, ObjectType.AssociationShortName, ObjectType.ProfileGeneric }))
     {
         AllObjects.Remove(it);
     }
     InitializeComponent();
     if (title != null)
     {
         this.Text = title;
     }
     foreach (GXDLMSObject it in AllObjects)
     {
         TargetCb.Items.Add(it);
     }
     if (Target.Key != null)
     {
         TargetCb.SelectedItem = AllObjects.FindByLN(Target.Key.ObjectType, Target.Key.LogicalName);
     }
     if (Target.Value != null)
     {
         IndexTB.Text     = target.Value.AttributeIndex.ToString();
         DataIndexTb.Text = target.Value.DataIndex.ToString();
     }
     else
     {
         IndexTB.Text     = "2";
         DataIndexTb.Text = "0";
     }
 }
Ejemplo n.º 3
0
        private static GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> CreateColumn(GXDLMSObjectCollection objects, GXObisCodeCollection obisCodes, ObjectType ot, string ln, int index, DataType dt)
        {
            GXDLMSObject obj = objects.FindByLN(ot, ln);

            if (obj == null)
            {
                GXObisCode code = obisCodes.FindByLN(ot, ln, null);
                obj             = GXDLMSClient.CreateObject(ot);
                obj.LogicalName = ln;
                if (code != null)
                {
                    GXDLMSAttributeSettings s = code.Attributes.Find(index);
                    if (s != null)
                    {
                        obj.SetDataType(index, s.Type);
                        obj.SetUIDataType(index, s.UIType);
                        obj.SetValues(index, s.Values);
                    }
                }
                else
                {
                    obj.SetUIDataType(index, dt);
                }
            }
            return(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(index, 0)));
        }
Ejemplo n.º 4
0
 private void OKBtn_Click(object sender, EventArgs e)
 {
     try
     {
         GXDLMSObject.ValidateLogicalName(Target.LogicalName);
         OriginalTarget.Version     = Target.Version;
         OriginalTarget.Description = Target.Description;
         OriginalTarget.ObjectType  = Target.ObjectType;
         OriginalTarget.LogicalName = Target.LogicalName.Trim();
         OriginalTarget.Append      = Target.Append;
         OriginalTarget.Attributes.Clear();
         OriginalTarget.Attributes.AddRange(Target.Attributes);
         //If user is adding OBIS code to the device.
         if (objects != null)
         {
             if (objects.FindByLN(OriginalTarget.ObjectType, OriginalTarget.LogicalName) != null)
             {
                 throw new Exception("OBIS code already exists.");
             }
         }
         else
         {
             //If user is adding new OBIS code to the template.
             if (ObisCodeCollection.FindByLN(OriginalTarget.ObjectType, OriginalTarget.LogicalName, OriginalTarget) != null)
             {
                 throw new Exception("OBIS code already exists.");
             }
         }
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(this, Ex);
         DialogResult = DialogResult.None;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Get logical names from client request.
        /// </summary>
        /// <param name="nodes">XML nodes.</param>
        /// <returns>Collection of logical names.</returns>
        private static void GetLN(GXDLMSObjectCollection objects, List <ValueEventArgs> targets, XmlNodeList nodes)
        {
            List <ValueEventArgs> list = new List <ValueEventArgs>();

            foreach (XmlNode node in nodes)
            {
                ObjectType ot;
                string     classId, instanceId;
                int        attributeId;
                if (node.Name == "cosem-attribute-descriptor")
                {
                    classId     = node.ChildNodes[0].ChildNodes[0].InnerText;
                    instanceId  = node.ChildNodes[1].ChildNodes[0].InnerText;
                    instanceId  = GXDLMSObject.ToLogicalName(GXCommon.HexToBytes(instanceId));
                    attributeId = int.Parse(node.ChildNodes[2].ChildNodes[0].InnerText);
                    ot          = (ObjectType)int.Parse(classId);
                    GXDLMSObject t = objects.FindByLN(ot, instanceId);
                    if (t == null)
                    {
                        t = GXDLMSClient.CreateDLMSObject((int)ot, 0, 0, instanceId, null);
                    }
                    ValueEventArgs ve = new ValueEventArgs(t, attributeId, 0, null);
                    targets.Add(ve);
                    System.Diagnostics.Debug.WriteLine(ot + " " + instanceId);
                }
                else if ("AttributeDescriptorList".Equals(node.Name))
                {
                    foreach (XmlNode it in node.ChildNodes[1].ChildNodes)
                    {
                        classId     = it.ChildNodes[0].InnerText;
                        instanceId  = it.ChildNodes[1].InnerText;
                        instanceId  = GXDLMSObject.ToLogicalName(GXCommon.HexToBytes(instanceId));
                        attributeId = int.Parse(it.ChildNodes[2].InnerText);
                        ot          = (ObjectType)int.Parse(classId);
                        ValueEventArgs ve = new ValueEventArgs(objects.FindByLN(ot, instanceId), attributeId, 0, null);
                        targets.Add(ve);
                        System.Diagnostics.Debug.WriteLine(ot + " " + instanceId);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Get logical names from client request.
 /// </summary>
 /// <param name="nodes">XML nodes.</param>
 /// <returns>Collection of logical names.</returns>
 private static void GetLN(GXDLMSObjectCollection objects, List<ValueEventArgs> targets, XmlNodeList nodes)
 {
     List<ValueEventArgs> list = new List<ValueEventArgs>();
     foreach (XmlNode node in nodes)
     {
         ObjectType ot;
         string classId, instanceId;
         int attributeId;
         if (node.ChildNodes[1].Name == "x:cosem-attribute-descriptor")
         {
             classId = node.ChildNodes[1].ChildNodes[0].ChildNodes[0].InnerText;
             instanceId = node.ChildNodes[1].ChildNodes[1].ChildNodes[0].InnerText;
             instanceId = GXDLMSObject.ToLogicalName(GXCommon.HexToBytes(instanceId));
             attributeId = int.Parse(node.ChildNodes[1].ChildNodes[2].ChildNodes[0].InnerText);
             ot = (ObjectType)int.Parse(classId);
             GXDLMSObject t = objects.FindByLN(ot, instanceId);
             if (t == null)
             {
                 t = GXDLMSClient.CreateDLMSObject((int)ot, 0, 0, instanceId, null);
             }
             ValueEventArgs ve = new ValueEventArgs(t, attributeId, 0, null);
             targets.Add(ve);
             System.Diagnostics.Debug.WriteLine(ot + " " + instanceId);
         }
         else if ("AttributeDescriptorList".Equals(node.ChildNodes[1].Name))
         {
             foreach (XmlNode it in node.ChildNodes[1].ChildNodes)
             {
                 classId = it.ChildNodes[0].ChildNodes[0].InnerText;
                 instanceId = it.ChildNodes[0].ChildNodes[1].InnerText;
                 instanceId = GXDLMSObject.ToLogicalName(GXCommon.HexToBytes(instanceId));
                 attributeId = int.Parse(it.ChildNodes[0].ChildNodes[2].InnerText);
                 ot = (ObjectType)int.Parse(classId);
                 ValueEventArgs ve = new ValueEventArgs(objects.FindByLN(ot, instanceId), attributeId, 0, null);
                 targets.Add(ve);
                 System.Diagnostics.Debug.WriteLine(ot + " " + instanceId);
             }
         }
     }
 }