Beispiel #1
0
        public OBISCodeForm(GXDLMSConverter c, GXDLMSObjectCollection objs, GXObisCodeCollection collection, GXObisCode item)
        {
            InitializeComponent();
            converter = c;
            objects   = objs;
            if (c == null)
            {
                converter = new GXDLMSConverter();
            }
            OriginalTarget = item;
            //Create clone from original items.
            MemoryStream    ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(ms, item);
            ms.Position = 0;
            Target      = (GXObisCode)bf.Deserialize(ms);
            ms.Close();
            ObisCodeCollection = collection;
            ShowInterfaces();
            if (Target.ObjectType == ObjectType.None)
            {
                InterfaceCB.SelectedIndex = 0;
            }
            else
            {
                InterfaceCB.SelectedItem = Target.ObjectType;
            }
            UpdateTarget();
        }
        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)));
        }
Beispiel #3
0
 /// <summary>
 /// Read Profile Generic Columns by entry.
 /// </summary>
 public object[] ReadRowsByEntry(GXDLMSObject it, int index, int count, GXDLMSObjectCollection columns)
 {
     byte[]   reply = ReadDataBlock(m_Parser.Read(m_Parser.ReadRowsByEntry(it.Name, index, count), 1, 1, ObjectType.None, 0));
     object[] rows  = (object[])m_Parser.GetValue(reply);
     if (columns != null && rows.Length != 0 && m_Parser.ObisCodes.Count != 0)
     {
         Array row = (Array)rows[0];
         if (columns.Count != row.Length)
         {
             throw new Exception("Columns count do not mach.");
         }
         for (int pos = 0; pos != columns.Count; ++pos)
         {
             if (row.GetValue(pos) is byte[])
             {
                 DataType type = DataType.None;
                 //Find Column type
                 GXObisCode code = m_Parser.ObisCodes.FindByLN(columns[pos].ObjectType, columns[pos].LogicalName, null);
                 if (code != null)
                 {
                     GXAttribute att = code.Attributes.Find(columns[pos].AttributeIndex);
                     if (att != null)
                     {
                         type = att.UIType;
                     }
                 }
                 foreach (object[] cell in rows)
                 {
                     cell[pos] = GXDLMS.ChangeType((byte[])cell[pos], type);
                 }
             }
         }
     }
     return(rows);
 }
Beispiel #4
0
        /// <summary>
        /// Add item to OBIS list.
        /// </summary>
        /// <param name="item"></param>
        ListViewItem AddItem(GXObisCode item)
        {
            ListViewItem it = OBISCodesList.Items.Add(item.LogicalName + " " + item.Description);

            it.Tag      = item;
            Items[item] = it;
            return(it);
        }
        /// <summary>
        /// Get country spesific OBIS codes.
        /// </summary>
        /// <param name="standard">Used standard.</param>
        /// <returns>Collection for special OBIC codes.</returns>
        public static GXObisCode[] GetObjects(Standard standard)
        {
            List <GXObisCode> codes = new List <GXObisCode>();

#if !WINDOWS_UWP
            string[] rows;
#if __MOBILE__
            if (standard == Standard.Italy)
            {
                rows = Resources.Italy.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.India)
            {
                rows = Resources.India.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.SaudiArabia)
            {
                rows = Resources.SaudiArabia.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                return(new GXObisCode[0]);
            }
#else
            if (standard == Standard.Italy)
            {
                rows = Gurux.DLMS.Properties.Resources.Italy.Split(new string[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.India)
            {
                rows = Gurux.DLMS.Properties.Resources.India.Split(new string[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            else if (standard == Standard.SaudiArabia)
            {
                rows = Gurux.DLMS.Properties.Resources.SaudiArabia.Split(new string[] { Environment.NewLine, "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                return(new GXObisCode[0]);
            }
#endif //!__MOBILE__
            foreach (string it in rows)
            {
                if (!it.StartsWith("#"))
                {
                    string[]   items   = it.Split(new char[] { ';' });
                    ObjectType ot      = (ObjectType)int.Parse(items[0]);
                    string     ln      = GXCommon.ToLogicalName(GXCommon.LogicalNameToBytes(items[1]));
                    int        version = int.Parse(items[2]);
                    string     desc    = items[3];
                    GXObisCode code    = new GXObisCode(ln, ot, desc);
                    code.Version = version;
                    codes.Add(code);
                }
            }
#endif
            return(codes.ToArray());
        }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
        /// <summary>
        /// Find correct DLMS class by Interface Type from the assembly.
        /// </summary>
        /// <param name="device"></param>
        /// <param name="it"></param>
        /// <returns></returns>
        public static GXDLMSObject ConvertObject2Class(GXDLMSDevice device, Gurux.DLMS.ObjectType objectType, string logicalName)
        {
            GXDLMSObject obj = Gurux.DLMS.GXDLMSClient.CreateObject(objectType);

            if (obj != null)
            {
                GXManufacturer m    = device.Manufacturers.FindByIdentification(device.Manufacturer);
                GXObisCode     item = m.ObisCodes.FindByLN(obj.ObjectType, logicalName, null);
                obj.LogicalName = logicalName;
                if (item != null)
                {
                    obj.Description = item.Description;
                }
            }
            return(obj);
        }
Beispiel #8
0
 private void EditBtn_Click(object sender, EventArgs e)
 {
     try
     {
         GXObisCode   item = (GXObisCode)OBISCodesList.SelectedItems[0].Tag;
         OBISCodeForm dlg  = new OBISCodeForm(((GXManufacturer)ManufacturersList.SelectedItems[0].Tag).ObisCodes, item);
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             OBISCodesList.SelectedItems[0].Text = item.LogicalName + " " + item.Description;
         }
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(this, Ex);
     }
 }
Beispiel #9
0
 private void NewBtn_Click(object sender, EventArgs e)
 {
     try
     {
         GXObisCode   item = new GXObisCode();
         OBISCodeForm dlg  = new OBISCodeForm(((GXManufacturer)ManufacturersList.SelectedItems[0].Tag).ObisCodes, item);
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             AddItem(item);
             ((GXManufacturer)ManufacturersList.SelectedItems[0].Tag).ObisCodes.Add(item);
         }
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(this, Ex);
     }
 }
Beispiel #10
0
 private void RemoveBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show(this, GXDLMSDirector.Properties.Resources.RemoveObjectConfirmation, GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
         {
             return;
         }
         foreach (ListViewItem it in OBISCodesList.SelectedItems)
         {
             GXObisCode item = (GXObisCode)it.Tag;
             ((GXManufacturer)ManufacturersList.SelectedItems[0].Tag).ObisCodes.Remove(item);
             Items.Remove(item);
             it.Remove();
         }
     }
     catch (Exception Ex)
     {
         GXDLMS.Common.Error.ShowError(this, Ex);
     }
 }
Beispiel #11
0
        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;
        }
Beispiel #12
0
        /// <summary>
        /// Get country spesific OBIS codes.
        /// </summary>
        /// <param name="standard">Used standard.</param>
        /// <returns>Collection for special OBIC codes.</returns>
        public static GXObisCode[] GetObjects(Standard standard)
        {
            List <GXObisCode> codes = new List <GXObisCode>();

            if (standard == Standard.Italian)
            {
#if !WINDOWS_UWP
                string[] rows = Gurux.DLMS.Properties.Resources.Italian.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string it in rows)
                {
                    string[]   items   = it.Split(new char[] { ';' });
                    ObjectType ot      = (ObjectType)int.Parse(items[0]);
                    string     ln      = GXCommon.ToLogicalName(GXCommon.LogicalNameToBytes(items[1]));
                    int        version = int.Parse(items[2]);
                    string     desc    = items[3];
                    GXObisCode code    = new GXObisCode(ln, ot, desc);
                    code.Version = version;
                    codes.Add(code);
                }
#endif
            }
            return(codes.ToArray());
        }
Beispiel #13
0
        public GXGraphItemForm(GXGraphItemCollection items, List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns, GXDLMSDevice device)
        {
            InitializeComponent();
            GraphItemEditor_SizeChanged(null, null);
            GraphItemList.OwnerDraw = true;
            Items = items;
            int            pos    = 0;
            List <string>  colors = GetColors();
            GXManufacturer man    = device.Manufacturers.FindByIdentification(device.Manufacturer);

            foreach (var it in columns)
            {
                GXDLMSObject obj   = it.Key;
                int          index = it.Value.AttributeIndex;
                if (!GXHelpers.IsNumeric(obj.GetDataType(index)) || (index > 0 && ((index & 0x8) != 0 || (index & 0x10) != 0)))
                {
                    continue;
                }
                GXGraphItem item = items.Find(obj.LogicalName, index);
                if (item == null)
                {
                    item                = new GXGraphItem();
                    item.LogicalName    = obj.LogicalName;
                    item.Color          = Color.FromName(colors[pos++]);
                    item.AttributeIndex = index;
                    items.Add(item);
                }
                string     desc = obj.Description;
                GXObisCode code = man.ObisCodes.FindByLN(obj.ObjectType, obj.LogicalName, null);
                if (code != null)
                {
                    desc = code.Description;
                }
                ListViewItem tmp = GraphItemList.Items.Add(obj.LogicalName + " " + desc);
                tmp.Tag = item;
            }
        }