public GXDLMSScriptActionDlg(
     GXDLMSScriptAction a,
     GXDLMSObjectCollection objects)
 {
     action  = a;
     targets = objects;
     InitializeComponent();
     foreach (DataType it in Enum.GetValues(typeof(DataType)))
     {
         if (it != DataType.None && it != DataType.Array && it != DataType.Structure)
         {
             ParameterTypeTb.Items.Add(it);
         }
     }
     TypeCb.Items.Add(ScriptActionType.Write);
     TypeCb.Items.Add(ScriptActionType.Execute);
     if (a.Type == ScriptActionType.None)
     {
         a.Type = ScriptActionType.Write;
     }
     TypeCb.SelectedItem = a.Type;
     foreach (GXDLMSObject it in objects)
     {
         TargetCb.Items.Add(it);
     }
     TargetCb.SelectedItem        = a.Target;
     IndexTB.Text                 = action.Index.ToString();
     ParameterTb.Text             = Convert.ToString(action.Parameter);
     ParameterTypeTb.SelectedItem = action.ParameterDataType;
 }
 /// <summary>
 /// Edit charge reference.
 /// </summary>
 private void ChargeReferenceEdit_Click(object sender, EventArgs e)
 {
     try
     {
         if (ChargeReferenceView.SelectedItems.Count == 1)
         {
             GXDLMSAccount          target  = Target as GXDLMSAccount;
             GXDLMSObjectCollection objects = target.Parent.GetObjects(ObjectType.Charge);
             if (objects.Count == 0)
             {
                 throw new Exception("There are no Charge objects.");
             }
             ListViewItem          li  = ChargeReferenceView.SelectedItems[0];
             GXDLMSTargetObjectDlg dlg = new GXDLMSTargetObjectDlg("Edit charge reference", target.Parent.FindByLN(ObjectType.None, li.Text) as GXDLMSObject, objects);
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 target.ChargeReferences.Remove(li.Text);
                 string desc = dlg.Target.LogicalName;
                 li.SubItems[0].Text = desc;
                 target.ChargeReferences.Add(desc);
                 errorProvider1.SetError(ChargeReferenceView, Properties.Resources.ValueChangedTxt);
                 Target.UpdateDirty(10, target.ChargeReferences);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 ///<summary>
 ///Constructor.
 ///</summary>
 internal GXDLMSSettings(bool server, InterfaceType interfaceType)
 {
     InterfaceType      = interfaceType;
     UseCustomChallenge = false;
     StartingBlockIndex = BlockIndex = 1;
     DLMSVersion        = 6;
     InvokeID           = 0x1;
     Priority           = Priority.High;
     ServiceClass       = ServiceClass.Confirmed;
     MaxServerPDUSize   = MaxPduSize = DefaultMaxReceivePduSize;
     IsServer           = server;
     Objects            = new GXDLMSObjectCollection();
     //This is removed later.
     Hdlc                = new GXDLMSLimits(this);
     Gateway             = null;
     ProposedConformance = GXDLMSClient.GetInitialConformance(false);
     if (server)
     {
         ProposedConformance |= Conformance.GeneralProtection;
     }
     ResetFrameSequence();
     WindowSize = 1;
     UserId     = -1;
     Standard   = Standard.DLMS;
     Plc        = new GXPlcSettings(this);
     MBus       = new GXMBusSettings();
     Pdu        = new GXPduSettings();
 }
Ejemplo n.º 6
0
        public GXDLMSActivityCalendarActionDlg(GXDLMSDayProfileAction target, GXDLMSObjectCollection scripts)
        {
            InitializeComponent();
            Target = target;
            if (target.StartTime != DateTime.MinValue)
            {
                TimeTb.Text = target.StartTime.ToFormatString();
            }
            int pos, selected = -1;

            foreach (GXDLMSObject it in scripts)
            {
                pos = ScriptCb.Items.Add(it);
                if (it.LogicalName == target.ScriptLogicalName)
                {
                    selected = pos;
                }
            }
            if (selected != -1)
            {
                ScriptCb.SelectedIndex = selected;
            }
            SelectorTb.Text = target.ScriptSelector.ToString();
            OkBtn.Enabled   = scripts.Count != 0;
        }
Ejemplo n.º 7
0
        internal static GXSNInfo FindSNObject(GXDLMSObjectCollection items, int sn)
        {
            GXSNInfo i = new GXSNInfo();
            int      offset, count;

            foreach (GXDLMSObject it in items)
            {
                if (sn >= it.ShortName)
                {
                    //If attribute is accessed.
                    if (sn < it.ShortName + (it as IGXDLMSBase).GetAttributeCount() * 8)
                    {
                        i.IsAction = false;
                        i.Item     = it;
                        i.Index    = ((sn - i.Item.ShortName) / 8) + 1;
                        break;
                    }
                    else
                    {
                        //If method is accessed.
                        GXDLMS.GetActionInfo(it.ObjectType, out offset, out count);
                        if (sn < it.ShortName + offset + (8 * count))
                        {
                            i.Item     = it;
                            i.IsAction = true;
                            i.Index    = (sn - it.ShortName - offset) / 8 + 1;
                            break;
                        }
                    }
                }
            }
            return(i);
        }
 /// <summary>
 /// Add charge reference.
 /// </summary>
 private void ChargeReferenceAdd_Click(object sender, EventArgs e)
 {
     try
     {
         GXDLMSAccount          target  = Target as GXDLMSAccount;
         GXDLMSObjectCollection objects = target.Parent.GetObjects(ObjectType.Charge);
         if (objects.Count == 0)
         {
             throw new Exception("There are no Charge objects.");
         }
         GXDLMSTargetObjectDlg dlg = new GXDLMSTargetObjectDlg("Add new charge reference", null, objects);
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             string desc = dlg.Target.LogicalName;
             target.ChargeReferences.Add(desc);
             ListViewItem li = ChargeReferenceView.Items.Add(desc);
             errorProvider1.SetError(ChargeReferenceView, Properties.Resources.ValueChangedTxt);
             Target.UpdateDirty(10, target.ChargeReferences);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 9
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";
     }
 }
 public GXAccountCreditChargeDlg(GXCreditChargeConfiguration target, GXDLMSObjectCollection objects)
 {
     InitializeComponent();
     Target = target;
     foreach (var it in Enum.GetValues(typeof(CreditCollectionConfiguration)))
     {
         //None is not added.
         if ((int)it != 0)
         {
             ConfigurationLb.Items.Add(it, (Target.CollectionConfiguration & (CreditCollectionConfiguration)it) != 0);
         }
     }
     foreach (GXDLMSObject it in objects.GetObjects(Enums.ObjectType.Credit))
     {
         CreditCb.Items.Add(it);
         if (target.CreditReference == it.LogicalName)
         {
             CreditCb.SelectedItem = it;
         }
     }
     foreach (GXDLMSObject it in objects.GetObjects(Enums.ObjectType.Charge))
     {
         ChargeCb.Items.Add(it);
         if (target.ChargeReference == it.LogicalName)
         {
             ChargeCb.SelectedItem = it;
         }
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Read scalers and units.
        /// </summary>
        public void GetScalersAndUnits()
        {
            GXDLMSObjectCollection objs = Client.Objects.GetObjects(new ObjectType[] { ObjectType.Register, ObjectType.ExtendedRegister, ObjectType.DemandRegister });

            //If trace is info.
            if (Trace > TraceLevel.Warning)
            {
                Console.WriteLine("Read scalers and units from the device.");
            }
            if ((Client.NegotiatedConformance & Gurux.DLMS.Enums.Conformance.MultipleReferences) != 0)
            {
                List <KeyValuePair <GXDLMSObject, int> > list = new List <KeyValuePair <GXDLMSObject, int> >();
                foreach (GXDLMSObject it in objs)
                {
                    if (it is GXDLMSRegister || it is GXDLMSExtendedRegister)
                    {
                        list.Add(new KeyValuePair <GXDLMSObject, int>(it, 3));
                    }
                    if (it is GXDLMSDemandRegister)
                    {
                        list.Add(new KeyValuePair <GXDLMSObject, int>(it, 4));
                    }
                }
                if (list.Count != 0)
                {
                    try
                    {
                        ReadList(list);
                    }
                    catch (Exception)
                    {
                        Client.NegotiatedConformance &= ~Gurux.DLMS.Enums.Conformance.MultipleReferences;
                    }
                }
            }
            if ((Client.NegotiatedConformance & Gurux.DLMS.Enums.Conformance.MultipleReferences) == 0)
            {
                //Read values one by one.
                foreach (GXDLMSObject it in objs)
                {
                    try
                    {
                        if (it is GXDLMSRegister)
                        {
                            Console.WriteLine(it.Name);
                            Read(it, 3);
                        }
                        if (it is GXDLMSDemandRegister)
                        {
                            Console.WriteLine(it.Name);
                            Read(it, 4);
                        }
                    }
                    catch
                    {
                        //Actaric SL7000 can return error here. Continue reading.
                    }
                }
            }
        }
Ejemplo n.º 12
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));
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ln">Logical Name of the object.</param>
 /// <param name="sn">Short Name of the object.</param>
 public GXDLMSAssociationShortName(string ln, ushort sn)
 : base(ObjectType.AssociationShortName, ln, sn)
 {
     ObjectList = new GXDLMSObjectCollection();
     //Default shared secred.
     Secret = System.Text.ASCIIEncoding.ASCII.GetBytes("Gurux");
     HlsSecret = System.Text.ASCIIEncoding.ASCII.GetBytes("Gurux");
 }
 /// <summary> 
 /// Constructor.
 /// </summary> 
 /// <param name="ln">Logical Name of the object.</param>
 public GXDLMSAssociationLogicalName(string ln)
     : base(ObjectType.AssociationLogicalName, ln, 0)
 {
     ObjectList = new GXDLMSObjectCollection();
     ApplicationContextName = new GXApplicationContextName();
     XDLMSContextInfo = new GXxDLMSContextType();
     AuthenticationMechanismMame = new GXAuthenticationMechanismName();
 }
 /// <summary> 
 /// Constructor.
 /// </summary> 
 public GXDLMSAssociationLogicalName()
     : this("0.0.40.0.0.255")
 {
     ObjectList = new GXDLMSObjectCollection();
     ApplicationContextName = new GXApplicationContextName();
     XDLMSContextInfo = new GXxDLMSContextType();
     AuthenticationMechanismMame = new GXAuthenticationMechanismName();
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Our example server accept all connections.
        /// </summary>
        protected override bool IsTarget(int serverAddress, int clientAddress)
        {
            bool ret = false;

            foreach (GXDLMSAssociationLogicalName it in Items.GetObjects(ObjectType.AssociationLogicalName))
            {
                if (it.ClientSAP == clientAddress || it.ClientSAP == 0)
                {
                    this.MaxReceivePDUSize = it.XDLMSContextInfo.MaxSendPduSize;
                    this.Conformance       = it.XDLMSContextInfo.Conformance;
                    ret = true;
                    break;
                }
            }
            if (ret)
            {
                // Check server address using serial number.
                if (!(serverAddress == 0x3FFF || serverAddress == 0x7F ||
                      (serverAddress & 0x3FFF) == serialNumber % 10000 + 1000))
                {
                    // Find address from the SAP table.
                    GXDLMSObjectCollection saps = Items.GetObjects(ObjectType.SapAssignment);
                    if (saps.Count != 0)
                    {
                        ret = false;
                        foreach (GXDLMSObject it in saps)
                        {
                            GXDLMSSapAssignment sap = (GXDLMSSapAssignment)it;
                            foreach (KeyValuePair <UInt16, string> e in sap.SapAssignmentList)
                            {
                                // Check server address with two bytes.
                                if ((serverAddress & 0xFFFF0000) == 0 && (serverAddress & 0x7FFF) == e.Key)
                                {
                                    ret = true;
                                    break;
                                }
                                // Check server address with one byte.
                                if ((serverAddress & 0xFFFFFF00) == 0 && (serverAddress & 0x7F) == e.Key)
                                {
                                    ret = true;
                                    break;
                                }
                            }
                            if (ret)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        //Accept all server addresses if there is no SAP table available.
                        ret = true;
                    }
                }
            }
            return(ret);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ln">Logical Name of the object.</param>
 public GXDLMSAssociationLogicalName(string ln)
 : base(ObjectType.AssociationLogicalName, ln, 0)
 {
     ObjectList = new GXDLMSObjectCollection();
     ApplicationContextName = new GXApplicationContextName();
     XDLMSContextInfo = new GXxDLMSContextType();
     AuthenticationMechanismMame = new GXAuthenticationMechanismName();
     //Default shared secred.
     Secret = ASCIIEncoding.ASCII.GetBytes("Gurux");
     HlsSecret = ASCIIEncoding.ASCII.GetBytes("Gurux");
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 public GXDLMSAssociationLogicalName()
 : this("0.0.40.0.0.255")
 {
     ObjectList = new GXDLMSObjectCollection();
     ApplicationContextName = new GXApplicationContextName();
     XDLMSContextInfo = new GXxDLMSContextType();
     AuthenticationMechanismMame = new GXAuthenticationMechanismName();
     //Default shared secreds.
     Secret = ASCIIEncoding.ASCII.GetBytes("Gurux");
     HlsSecret = ASCIIEncoding.ASCII.GetBytes("Gurux");
 }
Ejemplo n.º 19
0
        ParsePush(Object[] data)
        {
            int          index;
            GXDLMSObject obj;
            object       value;
            DataType     dt;
            List <KeyValuePair <GXDLMSObject, int> > items = new List <KeyValuePair <GXDLMSObject, int> >();

            if (data != null)
            {
                GXDLMSConverter        c       = new GXDLMSConverter();
                GXDLMSObjectCollection objects = new GXDLMSObjectCollection();
                foreach (Object it in (Object[])data[0])
                {
                    Object[] tmp     = (Object[])it;
                    int      classID = ((UInt16)(tmp[0])) & 0xFFFF;
                    if (classID > 0)
                    {
                        GXDLMSObject comp;
                        comp = this.Objects.FindByLN((ObjectType)classID, GXCommon.ToLogicalName(tmp[1] as byte[]));
                        if (comp == null)
                        {
                            comp = GXDLMSClient.CreateDLMSObject(classID, 0, 0, tmp[1], null);
                            c.UpdateOBISCodeInformation(comp);
                            objects.Add(comp);
                        }
                        if ((comp is IGXDLMSBase))
                        {
                            items.Add(new KeyValuePair <GXDLMSObject, int>(comp, (sbyte)tmp[2]));
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}",
                                                                             classID, GXCommon.ToLogicalName((byte[])tmp[1])));
                        }
                    }
                }
                for (int pos = 0; pos < data.Length; ++pos)
                {
                    obj   = items[pos].Key as GXDLMSObject;
                    value = data[pos];
                    index = items[pos].Value;
                    if (value is byte[] && (dt = obj.GetUIDataType(index)) != DataType.None)
                    {
                        value = GXDLMSClient.ChangeType(value as byte[], dt, Settings.UseUtc2NormalTime);
                    }
                    ValueEventArgs e = new ValueEventArgs(Settings, obj, index, 0, null);
                    e.Value = value;
                    (obj as IGXDLMSBase).SetValue(Settings, e);
                }
            }
            return(items);
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Load saved COSEM objects from XML.
 /// </summary>
 /// <param name="path">File path.</param>
 void LoadObjects(string path)
 {
     lock (settingsLock)
     {
         if (File.Exists(path))
         {
             GXDLMSObjectCollection objects = GXDLMSObjectCollection.Load(path);
             Items.Clear();
             Items.AddRange(objects);
         }
     }
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Returns collection of manufacturer Obis codes to implement custom read.
 /// </summary>
 /// <param name="name">Short or Logical Name.</param>
 /// <param name="type">Interface type.</param>        
 /// <returns>True, if data read is handled.</returns>
 public bool Read(object sender, GXDLMSObject item, GXDLMSObjectCollection columns, int attribute, GXDLMSCommunicator comm)
 {
     MainForm = sender as System.Windows.Forms.Form;
     if (!(item is GXDLMSProfileGeneric))
     {
         return false;
     }
     //Actaris do not support other than index 2.
     if (attribute != 0 && attribute != 2)
     {
         return true;
     }
     if (comm.OnBeforeRead != null)
     {
         comm.OnBeforeRead(item, attribute);
     }
     CurrentProfileGeneric = item as GXDLMSProfileGeneric;
     if (item is GXDLMSProfileGeneric)
     {
         GXDLMSProfileGeneric pg = item as GXDLMSProfileGeneric;
         GXReplyData reply = new GXReplyData();
         byte[][] data;
         try
         {
             comm.OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
             //Read profile generic columns.
             if (pg.AccessSelector == AccessRange.Range ||
                 pg.AccessSelector == AccessRange.Last)
             {
                 data = comm.client.ReadRowsByRange(pg, Convert.ToDateTime(pg.From).Date, Convert.ToDateTime(pg.To).Date);
                 comm.ReadDataBlock(data[0], "Reading profile generic data", 1, reply);
             }
             else if (pg.AccessSelector == AccessRange.Entry)
             {
                 data = comm.client.ReadRowsByEntry(pg, Convert.ToInt32(pg.From), Convert.ToInt32(pg.To));
                 comm.ReadDataBlock(data[0], "Reading profile generic data " + pg.Name, 1, reply);
             }
             else //Read All.
             {
                 data = comm.client.Read(pg, 2);
                 comm.ReadDataBlock(data[0], "Reading profile generic data " + pg.Name, 1, reply);
             }
         }
         finally
         {
             CurrentProfileGeneric = null;
             comm.OnDataReceived -= new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Returns collection of manufacturer Obis codes to implement custom read.
 /// </summary>
 /// <param name="name">Short or Logical Name.</param>
 /// <param name="type">Interface type.</param>
 /// <returns>True, if data read is handled.</returns>
 public bool Read(object sender, GXDLMSObject item, GXDLMSObjectCollection columns, int attribute, GXDLMSCommunicator comm)
 {
     MainForm = sender as System.Windows.Forms.Form;
     if (!(item is GXDLMSProfileGeneric))
     {
         return(false);
     }
     //Actaris do not support other than index 2.
     if (attribute != 0 && attribute != 2)
     {
         return(true);
     }
     if (comm.OnBeforeRead != null)
     {
         comm.OnBeforeRead(item, attribute);
     }
     CurrentProfileGeneric = item as GXDLMSProfileGeneric;
     if (item is GXDLMSProfileGeneric)
     {
         GXDLMSProfileGeneric pg    = item as GXDLMSProfileGeneric;
         GXReplyData          reply = new GXReplyData();
         byte[][]             data;
         try
         {
             comm.OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
             //Read profile generic columns.
             if (pg.AccessSelector == AccessRange.Range ||
                 pg.AccessSelector == AccessRange.Last)
             {
                 data = comm.client.ReadRowsByRange(pg, Convert.ToDateTime(pg.From).Date, Convert.ToDateTime(pg.To).Date);
                 comm.ReadDataBlock(data[0], "Reading profile generic data", 1, reply);
             }
             else if (pg.AccessSelector == AccessRange.Entry)
             {
                 data = comm.client.ReadRowsByEntry(pg, Convert.ToInt32(pg.From), Convert.ToInt32(pg.To));
                 comm.ReadDataBlock(data[0], "Reading profile generic data " + pg.Name, 1, reply);
             }
             else //Read All.
             {
                 data = comm.client.Read(pg, 2);
                 comm.ReadDataBlock(data[0], "Reading profile generic data " + pg.Name, 1, reply);
             }
         }
         finally
         {
             CurrentProfileGeneric = null;
             comm.OnDataReceived  -= new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Returns collection of push objects.
        /// </summary>
        /// <param name="data">Received data.</param>
        /// <returns>Array of objects and called indexes.</returns>
        public List <KeyValuePair <GXDLMSObject, int> > ParsePushObjects(GXByteBuffer data)
        {
            int          index;
            GXDLMSObject obj;
            object       value;
            DataType     dt;
            GXReplyData  reply = new GXReplyData();

            reply.Data = data;
            List <KeyValuePair <GXDLMSObject, int> > items = new List <KeyValuePair <GXDLMSObject, int> >();

            GXDLMS.GetValueFromData(Settings, reply);
            Object[] list = (Object[])reply.Value;
            GXDLMSObjectCollection objects = new GXDLMSObjectCollection();

            foreach (Object it in (Object[])list[0])
            {
                Object[] tmp     = (Object[])it;
                int      classID = ((UInt16)(tmp[0])) & 0xFFFF;
                if (classID > 0)
                {
                    GXDLMSObject comp;
                    comp = this.Objects.FindByLN((ObjectType)classID, GXDLMSObject.ToLogicalName(tmp[1] as byte[]));
                    if (comp == null)
                    {
                        comp = GXDLMSClient.CreateDLMSObject(classID, 0, 0, tmp[1], null);
                        objects.Add(comp);
                    }
                    if ((comp is IGXDLMSBase))
                    {
                        items.Add(new KeyValuePair <GXDLMSObject, int>(comp, (sbyte)tmp[2]));
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}",
                                                                         classID, GXDLMSObject.ToLogicalName((byte[])tmp[1])));
                    }
                }
            }
            for (int pos = 0; pos < list.Length; ++pos)
            {
                obj   = items[pos].Key as GXDLMSObject;
                value = list[pos];
                index = items[pos].Value;
                if (value is byte[] && (dt = obj.GetUIDataType(index)) != DataType.None)
                {
                    value = GXDLMSClient.ChangeType(value as byte[], dt);
                }
                (obj as IGXDLMSBase).SetValue(Settings, index, value);
            }
            return(items);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Read association view.
        /// </summary>
        public bool GetAssociationView(string outputFile)
        {
            if (outputFile != null)
            {
                //Save Association view to the cache so it is not needed to retrieve every time.
                if (File.Exists(outputFile))
                {
                    try
                    {
                        Client.Objects.Clear();
                        Client.Objects.AddRange(GXDLMSObjectCollection.Load(outputFile));
                        return(false);
                    }
                    catch (Exception)
                    {
                        if (File.Exists(outputFile))
                        {
                            File.Delete(outputFile);
                        }
                    }
                }
            }
            GXReplyData reply = new GXReplyData();

            ReadDataBlock(Client.GetObjectsRequest(), reply);
            Client.ParseObjects(reply.Data, true);
            //Access rights must read differently when short Name referencing is used.
            if (!Client.UseLogicalNameReferencing)
            {
                GXDLMSAssociationShortName sn = (GXDLMSAssociationShortName)Client.Objects.FindBySN(0xFA00);
                if (sn != null && sn.Version > 0)
                {
                    Read(sn, 3);
                }
            }
            if (outputFile != null)
            {
                try
                {
                    Client.Objects.Save(outputFile, new GXXmlWriterSettings()
                    {
                        Values = false
                    });
                }
                catch (Exception)
                {
                    //It's OK if this fails.
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="useLogicalNameReferencing">Is Logical or short name referencing used.</param>
 /// <param name="clientID">Client ID. Default is 0x21</param>
 /// <param name="ServerID">Server ID. Default is 3.</param>
 /// <param name="authentication">Authentication type. Default is None</param>
 /// <param name="password">Password if authentication is used.</param>
 /// <param name="interfaceType">Interface type. Default is general.</param>
 public GXDLMSClient(bool useLogicalNameReferencing, 
     object clientID, object ServerID, Authentication authentication,
     string password, InterfaceType interfaceType)
 {
     m_Base = new GXDLMS(false);
     Objects = new GXDLMSObjectCollection();
     this.UseLogicalNameReferencing = useLogicalNameReferencing;
     this.InterfaceType = interfaceType;
     this.Authentication = authentication;
     this.ClientID = clientID;
     this.ServerID = ServerID;
     this.Password = ASCIIEncoding.ASCII.GetBytes(password);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Update standard OBIS codes descriptions and type if defined.
 /// </summary>
 /// <param name="targets">Collection of COSEM objects to update.</param>
 public void UpdateOBISCodeInformation(GXDLMSObjectCollection targets)
 {
     lock (codes)
     {
         if (codes.Count == 0)
         {
             ReadStandardObisInfo(Standard, codes);
         }
         foreach (GXDLMSObject it in targets)
         {
             UpdateOBISCodeInfo(codes, it, Standard);
         }
     }
 }
Ejemplo n.º 27
0
 ///<summary>
 ///Constructor.
 ///</summary>
 internal GXDLMSSettings(bool server)
 {
     UseCustomChallenge  = false;
     StartingBlockIndex  = BlockIndex = 1;
     DLMSVersion         = 6;
     InvokeID            = 0x1;
     Priority            = Priority.High;
     ServiceClass        = ServiceClass.Confirmed;
     MaxServerPDUSize    = MaxPduSize = DefaultMaxReceivePduSize;
     IsServer            = server;
     Objects             = new GXDLMSObjectCollection();
     Limits              = new GXDLMSLimits();
     ProposedConformance = GXDLMSClient.GetInitialConformance(false);
     ResetFrameSequence();
 }
Ejemplo n.º 28
0
 public GXValuesDlg(Dictionary <Type, List <IGXDLMSView> > views, string path)
 {
     InitializeComponent();
     Views = views;
     foreach (GXDLMSObject it in GXDLMSObjectCollection.Load(path))
     {
         ListViewItem li = new ListViewItem(it.LogicalName);
         li.Tag = it;
         ObjectList.Items.Add(li);
     }
     if (ObjectList.Items.Count != 0)
     {
         ObjectList.Items[0].Selected = true;
     }
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Load saved COSEM objects from XML.
 /// </summary>
 /// <param name="path">File path.</param>
 bool LoadObjects(string path, GXDLMSObjectCollection items)
 {
     lock (settingsLock)
     {
         if (File.Exists(path))
         {
             GXDLMSObjectCollection objects = GXDLMSObjectCollection.Load(path);
             items.Clear();
             items.AddRange(objects);
             UpdateValues(items);
             return(true);
         }
     }
     return(false);
 }
 public void OnValueChanged(int index, object value, bool user)
 {
     if (index == 2)
     {
         GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName;
         GXDLMSObjectCollection       items  = target.ObjectList;
         CallingWindowLV.Items.Clear();
         if (items != null)
         {
             foreach (GXDLMSObject it in items)
             {
                 ListViewItem li = CallingWindowLV.Items.Add(it.ObjectType.ToString());
                 li.SubItems.Add(it.Version.ToString()); //Version
                 li.SubItems.Add(it.LogicalName);
                 //access_rights: access_right
                 if (it is IGXDLMSBase)
                 {
                     string str = null;
                     //Show attribute access.
                     int cnt = (it as IGXDLMSBase).GetAttributeCount();
                     for (int pos = 1; pos != cnt + 1; ++pos)
                     {
                         if (str != null)
                         {
                             str += ", ";
                         }
                         AccessMode mode = it.GetAccess(pos);
                         str += pos.ToString() + " = " + mode;
                     }
                     li.SubItems.Add(str);
                     //Show method access.
                     str = null;
                     cnt = (it as IGXDLMSBase).GetMethodCount();
                     for (int pos = 1; pos != cnt + 1; ++pos)
                     {
                         if (str != null)
                         {
                             str += ", ";
                         }
                         MethodAccessMode mode = it.GetMethodAccess(pos);
                         str += pos.ToString() + " = " + mode;
                     }
                     li.SubItems.Add(str);
                 }
             }
         }
     }
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="value"></param>
 public GXDLMSScriptDlg(GXDLMSScript value, GXDLMSObjectCollection objects, bool readOnly)
 {
     InitializeComponent();
     target  = value;
     targets = objects;
     removeToolStripMenuItem.Enabled     = addToolStripMenuItem.Enabled =
         deleteToolStripMenuItem.Enabled = addToolStripMenuItem2.Enabled = !readOnly;
     if (target.Id != 0)
     {
         IdTb.Text = target.Id.ToString();
     }
     foreach (GXDLMSScriptAction a in target.Actions)
     {
         ShowAction(a, null);
     }
 }
 public GXDLMSPushTargetDlg(
     KeyValuePair <GXDLMSObject, GXDLMSCaptureObject> target,
     GXDLMSObjectCollection objects)
 {
     Target = target;
     InitializeComponent();
     foreach (GXDLMSObject it in objects)
     {
         TargetCb.Items.Add(it);
     }
     TargetCb.SelectedItem = target.Key;
     if (target.Value != null)
     {
         IndexTB.Text = Convert.ToString(target.Value.AttributeIndex);
     }
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public GXDLMSDevice(Gurux.Common.IGXMedia media)
 {
     StartProtocol              = StartProtocolType.IEC;
     ClientID                   = 0x10; // Public client (lowest security level).
     PhysicalAddress            = 1;
     Password                   = "";
     Authentication             = Authentication.None;
     m_Communicator             = new GXDLMSCommunicator(this, media);
     m_Objects                  = m_Communicator.m_Cosem.Objects;
     m_Objects.Tag              = this;
     m_Communicator.OnProgress += new ProgressEventHandler(this.NotifyProgress);
     this.KeepAlive             = new System.Timers.Timer();
     this.KeepAlive.Interval    = 40000;
     this.KeepAlive.Elapsed    += new System.Timers.ElapsedEventHandler(KeepAlive_Elapsed);
     m_Status                   = DeviceState.Initialized;
     WaitTime                   = 5;
 }
Ejemplo n.º 34
0
        /// <summary>
        /// Read scalers and units.
        /// </summary>
        public void GetScalersAndUnits()
        {
            GXDLMSObjectCollection objs = Client.Objects.GetObjects(new ObjectType[] { ObjectType.Register, ObjectType.ExtendedRegister, ObjectType.DemandRegister });

            Console.WriteLine("Read scalers and units from the device.");
            if ((Client.NegotiatedConformance & Conformance.MultipleReferences) != 0)
            {
                List <KeyValuePair <GXDLMSObject, int> > list = new List <KeyValuePair <GXDLMSObject, int> >();
                foreach (GXDLMSObject it in objs)
                {
                    if (it is GXDLMSRegister)
                    {
                        list.Add(new KeyValuePair <GXDLMSObject, int>(it, 3));
                    }
                    if (it is GXDLMSDemandRegister)
                    {
                        list.Add(new KeyValuePair <GXDLMSObject, int>(it, 4));
                    }
                }
                ReadList(list);
            }
            else
            {
                //Read values one by one.
                foreach (GXDLMSObject it in objs)
                {
                    try
                    {
                        if (it is GXDLMSRegister)
                        {
                            Console.WriteLine(it.Name);
                            Read(it, 3);
                        }
                        if (it is GXDLMSDemandRegister)
                        {
                            Console.WriteLine(it.Name);
                            Read(it, 4);
                        }
                    }
                    catch
                    {
                        //Actaric SL7000 can return error here. Continue reading.
                    }
                }
            }
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Returns collection of manufacturer Obis codes to implement custom read.
 /// </summary>
 /// <param name="name">Short or Logical Name.</param>
 /// <param name="type">Interface type.</param>        
 /// <returns>True, if data read is handled.</returns>
 public bool Read(object sender, GXDLMSObject item, GXDLMSObjectCollection columns, int attribute, GXDLMSCommunicator comm)
 {
     MainForm = sender as System.Windows.Forms.Form;
     if (!(item is GXDLMSProfileGeneric))
     {
         return false;
     }
     //Actaris do not support other than index 2.
     if (attribute != 0 && attribute != 2)
     {
         return true;
     }
     if (comm.OnBeforeRead != null)
     {
         comm.OnBeforeRead(item, attribute);
     }
     CurrentProfileGeneric = item as GXDLMSProfileGeneric;
     if (item is GXDLMSProfileGeneric)
     {
         GXDLMSProfileGeneric pg = item as GXDLMSProfileGeneric;
         byte[] data;
         try
         {
             comm.OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
             //Read profile generic columns.
             if (pg.AccessSelector != AccessRange.Entry)
             {
                 data = comm.m_Cosem.ReadRowsByRange(pg.Name, pg.CaptureObjects[0].Key.LogicalName,
                                 pg.CaptureObjects[0].Key.ObjectType, pg.CaptureObjects[0].Key.Version, Convert.ToDateTime(pg.From).Date, Convert.ToDateTime(pg.To).Date);
                 data = comm.ReadDataBlock(data, "Reading profile generic data", 1);
             }
             else
             {
                 data = comm.m_Cosem.ReadRowsByEntry(pg.Name, Convert.ToInt32(pg.From), Convert.ToInt32(pg.To));
                 data = comm.ReadDataBlock(data, "Reading profile generic data " + pg.Name, 1);
             }
         }
         finally
         {
             CurrentProfileGeneric = null;
             comm.OnDataReceived -= new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Returns collection of manufacturer Obis codes to implement custom read.
 /// </summary>
 /// <param name="name">Short or Logical Name.</param>
 /// <param name="type">Interface type.</param>
 /// <returns>True, if data read is handled.</returns>
 public bool Read(object sender, GXDLMSObject item, GXDLMSObjectCollection columns, int attribute, GXDLMSCommunicator comm)
 {
     MainForm = sender as System.Windows.Forms.Form;
     if (!(item is GXDLMSProfileGeneric))
     {
         return(false);
     }
     //Actaris do not support other than index 2.
     if (attribute != 0 && attribute != 2)
     {
         return(true);
     }
     if (comm.OnBeforeRead != null)
     {
         comm.OnBeforeRead(item, attribute);
     }
     CurrentProfileGeneric = item as GXDLMSProfileGeneric;
     if (item is GXDLMSProfileGeneric)
     {
         GXDLMSProfileGeneric pg = item as GXDLMSProfileGeneric;
         byte[] data;
         try
         {
             comm.OnDataReceived += new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
             //Read profile generic columns.
             if (pg.AccessSelector != AccessRange.Entry)
             {
                 data = comm.m_Cosem.ReadRowsByRange(pg.Name, pg.CaptureObjects[0].Key.LogicalName,
                                                     pg.CaptureObjects[0].Key.ObjectType, pg.CaptureObjects[0].Key.Version, Convert.ToDateTime(pg.From).Date, Convert.ToDateTime(pg.To).Date);
                 data = comm.ReadDataBlock(data, "Reading profile generic data", 1);
             }
             else
             {
                 data = comm.m_Cosem.ReadRowsByEntry(pg.Name, Convert.ToInt32(pg.From), Convert.ToInt32(pg.To));
                 data = comm.ReadDataBlock(data, "Reading profile generic data " + pg.Name, 1);
             }
         }
         finally
         {
             CurrentProfileGeneric = null;
             comm.OnDataReceived  -= new GXDLMSCommunicator.DataReceivedEventHandler(this.OnProfileGenericDataReceived);
         }
         return(true);
     }
     return(false);
 }
Ejemplo n.º 37
0
 public GXDLMSScriptActionDlg(
     GXDLMSScriptAction a,
     GXDLMSObjectCollection objects)
 {
     action  = a;
     targets = objects;
     InitializeComponent();
     TypeCb.Items.Add(ScriptActionType.None);
     TypeCb.Items.Add(ScriptActionType.Write);
     TypeCb.Items.Add(ScriptActionType.Execute);
     TypeCb.SelectedItem = a.Type;
     foreach (GXDLMSObject it in objects)
     {
         TargetCb.Items.Add(it);
     }
     TargetCb.SelectedItem = a.Target;
     IndexTB.Text          = action.Index.ToString();
 }
        public GXDLMSObjectCollection GetObjects()
        {
            GXLogWriter.WriteLog("--- Collecting objects. ---");
            byte[] allData;
            try
            {
                NotifyProgress("Collecting objects", 0, 1);
                allData = ReadDataBlock(m_Cosem.GetObjectsRequest(), "Collecting objects");
            }
            catch (Exception Ex)
            {
                throw new Exception("GetObjects failed. " + Ex.Message);
            }
            GXDLMSObjectCollection objs = m_Cosem.ParseObjects(allData, true);

            NotifyProgress("Collecting objects", objs.Count, objs.Count);
            GXLogWriter.WriteLog("--- Collecting " + objs.Count.ToString() + " objects. ---");
            return(objs);
        }
Ejemplo n.º 39
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);
             }
         }
     }
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Parse data columns.
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public List<GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>> ParseColumns(byte[] data)
 {
     if (data == null)
     {
         throw new GXDLMSException("Invalid parameter.");
     }
     int index = 0;
     byte size = data[index++];
     //Check that data is in the array.
     if (size != 0x01)
     {
         throw new GXDLMSException("Invalid response.");
     }
     //get object count
     int cnt = GXCommon.GetObjectCount(data, ref index);
     int objectCnt = 0;
     GXDLMSObjectCollection items = new GXDLMSObjectCollection();
     int total, count;
     List<GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>> list = new List<GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>>();
     while (index != data.Length && cnt != objectCnt)
     {
         DataType type = DataType.None;
         int cachePosition = 0;
         object[] objects = (object[])GXCommon.GetData(data, ref index, ActionType.None, out total, out count, ref type, ref cachePosition);
         if (index == -1)
         {
             throw new OutOfMemoryException();
         }
         if (objects.Length != 4)
         {
             throw new GXDLMSException("Invalid structure format.");
         }
         ++objectCnt;
         GXDLMSObject comp = CreateDLMSObject(Convert.ToInt16(objects[0]), null, 0, objects[1], 0);
         int attributeIndex = Convert.ToInt16(objects[2]);
         if (comp != null)
         {
             items.Add(comp);
             list.Add(new GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(comp, new GXDLMSCaptureObject(attributeIndex, Convert.ToInt16(objects[3]))));
         }                
         //Update data type and scaler unit if register.
         if (Objects != null)
         {
             GXDLMSObject tmp = Objects.FindByLN(comp.ObjectType, comp.LogicalName);
             if (tmp != null)
             {
                 if (comp is GXDLMSRegister)
                 {
                     //Some meters return zero.
                     if (attributeIndex == 0)
                     {
                         attributeIndex = 2;
                     }
                     comp.SetUIDataType(attributeIndex, tmp.GetUIDataType(attributeIndex));
                     (comp as GXDLMSRegister).Scaler = (tmp as GXDLMSRegister).Scaler;
                     (comp as GXDLMSRegister).Unit = (tmp as GXDLMSRegister).Unit;
                 }
             }
         }
     }            
     UpdateOBISCodes(items);
     return list;
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public GXDLMSClient()
 {
     m_Base = new GXDLMS(false);
     this.Authentication = Authentication.None;
     Objects = new GXDLMSObjectCollection();
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Parses the COSEM objects of the received data.
 /// </summary>
 /// <param name="data">Received data, from the device, as byte array. </param>
 /// <returns>Collection of COSEM objects.</returns>
 public GXDLMSObjectCollection ParseObjects(byte[] data, bool onlyKnownObjects)
 {
     if (data == null || data.Length == 0)
     {
         throw new GXDLMSException("ParseObjects failed. Invalid parameter.");
     }
     GXDLMSObjectCollection objects = null;
     if (UseLogicalNameReferencing)
     {
         objects = ParseLNObjects(data, onlyKnownObjects);
     }
     else
     {
         objects = ParseSNObjects(data, onlyKnownObjects);
     }
     UpdateOBISCodes(objects);
     Objects = objects;
     return objects;
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Reserved for internal use.
 /// </summary>
 GXDLMSObjectCollection ParseLNObjects(byte[] buff, bool onlyKnownObjects)
 {
     int index = 0;
     byte size = buff[index++];
     //Check that data is in the array.
     if (size != 0x01)
     {
         throw new GXDLMSException("Invalid response.");
     }
     //get object count
     int cnt = GXCommon.GetObjectCount(buff, ref index);
     int objectCnt = 0;
     GXDLMSObjectCollection items = new GXDLMSObjectCollection(this);
     int total, count;
     
     //Some meters give wrong item count.
     while (index != buff.Length && cnt != objectCnt)
     {
         DataType dt = DataType.None;
         int cachePosition = 0;
         object[] objects = (object[])GXCommon.GetData(buff, ref index, ActionType.None, out total, out count, ref dt, ref cachePosition);
         if (index == -1)
         {
             throw new OutOfMemoryException();
         }
         if (objects.Length != 4)
         {
             throw new GXDLMSException("Invalid structure format.");
         }
         ++objectCnt;
         int ot = Convert.ToInt16(objects[0]);
         if (!onlyKnownObjects || GXDLMS.AvailableObjectTypes.ContainsKey((ObjectType) ot))
         {
             GXDLMSObject comp = CreateDLMSObject(ot, objects[1], 0, objects[2], objects[3]);
             items.Add(comp);                    
         }
         else
         {
             System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}", ot, GXDLMSObject.toLogicalName((byte[])objects[2])));
         }
     }
     return items;
 }
Ejemplo n.º 44
0
     ParsePush(Object[] data)
 {
     int index;
     GXDLMSObject obj;
     object value;
     DataType dt;
     List<KeyValuePair<GXDLMSObject, int>> items = new List<KeyValuePair<GXDLMSObject, int>>();
     if (data != null)
     {
         GXDLMSConverter c = new GXDLMSConverter();
         GXDLMSObjectCollection objects = new GXDLMSObjectCollection();
         foreach (Object it in (Object[])data[0])
         {
             Object[] tmp = (Object[])it;
             int classID = ((UInt16)(tmp[0])) & 0xFFFF;
             if (classID > 0)
             {
                 GXDLMSObject comp;
                 comp = this.Objects.FindByLN((ObjectType)classID, GXDLMSObject.ToLogicalName(tmp[1] as byte[]));
                 if (comp == null)
                 {
                     comp = GXDLMSClient.CreateDLMSObject(classID, 0, 0, tmp[1], null);
                     c.UpdateOBISCodeInformation(comp);
                     objects.Add(comp);
                 }
                 if ((comp is IGXDLMSBase))
                 {
                     items.Add(new KeyValuePair<GXDLMSObject, int>(comp, (sbyte)tmp[2]));
                 }
                 else
                 {
                     System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}",
                         classID, GXDLMSObject.ToLogicalName((byte[])tmp[1])));
                 }
             }
         }
         for (int pos = 0; pos < data.Length; ++pos)
         {
             obj = items[pos].Key as GXDLMSObject;
             value = data[pos];
             index = items[pos].Value;
             if (value is byte[] && (dt = obj.GetUIDataType(index)) != DataType.None)
             {
                 value = GXDLMSClient.ChangeType(value as byte[], dt);
             }
             ValueEventArgs e = new ValueEventArgs(Settings, obj, index, 0, null);
             e.Value = value;
             (obj as IGXDLMSBase).SetValue(Settings, e);
         }
     }
     return items;
 }
Ejemplo n.º 45
0
 internal static void UpdateOBISCodes(GXDLMSObjectCollection objects)
 {
     GXStandardObisCodeCollection codes = new GXStandardObisCodeCollection();
     string[] rows = Gurux.DLMS.Properties.Resources.OBISCodes.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
     foreach (string it in rows)
     {
         string[] items = it.Split(new char[] { ';' });
         string[] obis = items[0].Split(new char[] { '.' });
         GXStandardObisCode code = new GXStandardObisCode(obis, items[3] + "; " + items[4] + "; " +
             items[5] + "; " + items[6] + "; " + items[7], items[1], items[2]);
         codes.Add(code);
     }
     foreach (GXDLMSObject it in objects)
     {
         if (!string.IsNullOrEmpty(it.Description))
         {
             continue;
         }
         GXStandardObisCode code = codes.Find(it.LogicalName, it.ObjectType);                
         if (code != null)
         {                    
             it.Description = code.Description;
             //If string is used
             if (code.DataType.Contains("10"))
             {
                 code.UIDataType = "10";
             }
             //If date time is used.
             else if (code.DataType.Contains("25") || code.DataType.Contains("26"))
             {
                 code.UIDataType = code.DataType = "25";
             }                    
             //Time stamps of the billing periods objects (first scheme if there are two)
             else if (code.DataType.Contains("9"))
             {
                 if ((GXStandardObisCodeCollection.EqualsMask("0.0-64.96.7.10-14.255", it.LogicalName) ||
                     //Time stamps of the billing periods objects (second scheme)
                 GXStandardObisCodeCollection.EqualsMask("0.0-64.0.1.5.0-99,255", it.LogicalName) ||
                     //Time of power failure
                 GXStandardObisCodeCollection.EqualsMask("0.0-64.0.1.2.0-99,255", it.LogicalName) ||
                     //Time stamps of the billing periods objects (first scheme if there are two)                        
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.1.2.0-99,255", it.LogicalName) ||
                     //Time stamps of the billing periods objects (second scheme)
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.1.5.0-99,255", it.LogicalName) ||
                     //Time expired since last end of billing period
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.0.255", it.LogicalName) ||
                     //Time of last reset
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.6.255", it.LogicalName) ||
                     //Date of last reset
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.7.255", it.LogicalName) ||
                     //Time expired since last end of billing period (Second billing period scheme)
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.13.255", it.LogicalName) ||
                     //Time of last reset (Second billing period scheme)
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.14.255", it.LogicalName) ||
                     //Date of last reset (Second billing period scheme)
                 GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.15.255", it.LogicalName)))
                 {
                     code.UIDataType = "25";
                 }
                 //Local time
                 else if (GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.1.255", it.LogicalName))
                 {
                     code.UIDataType = "27";
                 }
                 //Local date
                 else if (GXStandardObisCodeCollection.EqualsMask("1.0-64.0.9.2.255", it.LogicalName))
                 {
                     code.UIDataType = "26";
                 }
                 //Active firmware identifier
                 else if (GXStandardObisCodeCollection.EqualsMask("1.0.0.2.0.255", it.LogicalName))
                 {
                     code.UIDataType = "10";
                 }
             }
             if (code.DataType != "*" && code.DataType != string.Empty && !code.DataType.Contains(","))
             {
                 DataType type = (DataType)int.Parse(code.DataType);                       
                 switch (it.ObjectType)
                 {                            
                     case ObjectType.Data:
                     case ObjectType.Register:
                     case ObjectType.RegisterActivation:
                     case ObjectType.ExtendedRegister:
                         it.SetDataType(2, type);
                         break;
                     default:
                         break;
                 }                        
             }                    
             if (!string.IsNullOrEmpty(code.UIDataType))
             {
                 DataType uiType = (DataType)int.Parse(code.UIDataType);
                 switch (it.ObjectType)
                 {
                     case ObjectType.Data:
                     case ObjectType.Register:
                     case ObjectType.RegisterActivation:
                     case ObjectType.ExtendedRegister:
                         it.SetUIDataType(2, uiType);
                         break;
                     default:
                         break;
                 }                      
             }                    
         }
         else
         {
             System.Diagnostics.Debug.WriteLine("Unknown OBIS Code: " + it.LogicalName + " Type: " + it.ObjectType);
         }
     }
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Update object tree.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedIndex == 0)
            {
                TransactionWork = new GXAsyncWork(this, OnAsyncStateChange, Refresh, new object[] { ObjectTree.SelectedNode.Tag });
            }
            else
            {
                GXDLMSObjectCollection items = new GXDLMSObjectCollection();
                foreach (ListViewItem it in ObjectList.SelectedItems)
                {
                    items.Add(it.Tag as GXDLMSObject);
                }
                TransactionWork = new GXAsyncWork(this, OnAsyncStateChange, Refresh, new object[] { items });
            }

            TransactionWork.Start();
        }
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (ObjectList == null)
     {
         ObjectList = new GXDLMSObjectCollection();
     }
     if (e.Index == 1)
     {
         return this.LogicalName;
     }
     else if (e.Index == 2)
     {
         return GetObjects(settings, e).Array();
     }
     else if (e.Index == 3)
     {
         bool lnExists = ObjectList.FindBySN(this.ShortName) != null;
         //Add count
         int cnt = ObjectList.Count;
         if (!lnExists)
         {
             ++cnt;
         }
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         GXCommon.SetObjectCount(cnt, data);
         foreach (GXDLMSObject it in ObjectList)
         {
             GetAccessRights(settings, it, data);
         }
         if (!lnExists)
         {
             GetAccessRights(settings, this, data);
         }
         return data.Array();
     }
     else if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         GXCommon.SetData(settings, data, DataType.OctetString, SecuritySetupReference);
         return data.Array();
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return null;
 }
Ejemplo n.º 48
0
        /// <summary>
        /// Delete selected object.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteMnu_Click(object sender, EventArgs e)
        {
            try
            {
                if (ObjectTree.Focused)
                {
                    TreeNode node = ObjectTree.SelectedNode;
                    if (node != null)
                    {
                        object obj = node.Tag;
                        if (obj is GXDLMSDevice)
                        {
                            if (MessageBox.Show(this, GXDLMSDirector.Properties.Resources.RemoveDeviceConfirmation, GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                            {
                                return;
                            }
                            RemoveDevice(obj as GXDLMSDevice);
                        }
                        else if (obj is GXDLMSObject)
                        {
                            if (MessageBox.Show(this, GXDLMSDirector.Properties.Resources.RemoveObjectConfirmation, GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                            {
                                return;
                            }
                            RemoveObject(obj);
                        }
                        else if (obj is GXDLMSObjectCollection)
                        {
                            if (MessageBox.Show(this, GXDLMSDirector.Properties.Resources.RemoveObjectConfirmation, GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                            {
                                return;
                            }
                            RemoveObject(obj);
                        }
                        //Find selected device from the device list.
                        else if (obj is GXDLMSDeviceCollection)
                        {
                            if (MessageBox.Show(this, GXDLMSDirector.Properties.Resources.RemoveDeviceConfirmation, GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                            {
                                return;
                            }
                            foreach (ListViewItem it in DeviceList.SelectedItems)
                            {
                                RemoveDevice(it.Tag as GXDLMSDevice);
                            }
                        }
                    }
                }
                else if (ObjectList.Focused && ObjectList.SelectedItems.Count != 0)
                {
                    if (MessageBox.Show(this, GXDLMSDirector.Properties.Resources.RemoveObjectConfirmation, GXDLMSDirector.Properties.Resources.GXDLMSDirectorTxt, MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                    {
                        return;
                    }

                    GXDLMSObjectCollection items = new GXDLMSObjectCollection();
                    foreach (ListViewItem it in ObjectList.SelectedItems)
                    {
                        items.Add(it.Tag as GXDLMSObject);
                    }
                    foreach (GXDLMSObject it in items)
                    {
                        RemoveObject(it);
                    }
                }
                SetDirty(true);
            }
            catch (Exception Ex)
            {
                GXDLMS.Common.Error.ShowError(this, Ex);
            }
        }
Ejemplo n.º 49
0
 ListViewItem AddNode(GXDLMSObject it, TreeNode deviceNode, ListViewGroup group)
 {
     if (this.InvokeRequired)
     {
         return this.Invoke(new AddNodeEventHandler(AddNode), new object[] { it, deviceNode, group }) as ListViewItem;
     }
     TreeNode node;
     GXDLMSObjectCollection objects = null;
     if (group != null)
     {
         node = ObjectTreeItems[(it.Parent.Tag.GetHashCode() << 16) + it.ObjectType] as TreeNode;
         if (node == null)
         {
             node = deviceNode.Nodes.Add(it.ObjectType.ToString());
             node.SelectedImageIndex = node.ImageIndex = 11;
             ObjectTreeItems[(it.Parent.Tag.GetHashCode() << 16) + it.ObjectType] = node;
             objects = new GXDLMSObjectCollection();
             node.Tag = objects;
         }
         else
         {
             objects = node.Tag as GXDLMSObjectCollection;
         }
         objects.Add(it);
         node = node.Nodes.Add(it.LogicalName + " " + it.Description);
     }
     else
     {
         node = deviceNode.Nodes.Add(it.LogicalName + " " + it.Description);
     }
     node.Tag = it;
     ObjectTreeItems[it] = node;
     ListViewItem item = new ListViewItem(it.LogicalName + " " + it.Description);
     item.Tag = it;
     item.Group = group;
     ObjectListItems.Add(it, item);
     if (it is GXDLMSProfileGeneric)
     {
         node.SelectedImageIndex = node.ImageIndex = 8;
     }
     else
     {
         node.SelectedImageIndex = node.ImageIndex = 7;
     }
     return item;
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Update standard OBIS codes descriptions and type if defined.
 /// </summary>
 /// <param name="targets">Collection of COSEM objects to update.</param>
 public void UpdateOBISCodeInformation(GXDLMSObjectCollection targets)
 {
     lock (codes)
     {
         if (codes.Count == 0)
         {
             ReadStandardObisInfo(codes);
         }
         foreach (GXDLMSObject it in targets)
         {
             UpdateOBISCodeInfo(codes, it);
         }
     }
 }
Ejemplo n.º 51
0
 /// <summary>
 /// Constructor.
 /// </summary>        
 public GXDLMSServerBase(bool logicalNameReferencing)
 {
     m_Base = new GXDLMS(true);
     m_Base.UseLogicalNameReferencing = logicalNameReferencing;
     //TODO: StartProtocol = StartProtocolType.DLMS;
     Reset();
     Items = new GXDLMSObjectCollection(this);
     m_Base.LNSettings = new GXDLMSLNSettings(new byte[] { 0x00, 0x7E, 0x1F });
     m_Base.SNSettings = new GXDLMSSNSettings(new byte[] { 0x1C, 0x03, 0x20 });
     ServerIDs = new List<object>();
     this.InterfaceType = InterfaceType.General;
 }
 /// <summary> 
 /// Constructor.
 /// </summary> 
 /// <param name="ln">Logical Name of the object.</param>
 /// <param name="sn">Short Name of the object.</param>
 public GXDLMSAssociationShortName(string ln, ushort sn)
     : base(ObjectType.AssociationShortName, ln, 0)
 {
     ObjectList = new GXDLMSObjectCollection();
 }
Ejemplo n.º 53
0
 /// <summary>
 /// Reserved for internal use.
 /// </summary>
 GXDLMSObjectCollection ParseSNObjects(byte[] buff, bool onlyKnownObjects)
 {
     int index = 0;
     //Get array tag.
     byte size = buff[index++];
     //Check that data is in the array
     if (size != 0x01)
     {
         throw new GXDLMSException("Invalid response.");
     }
     GXDLMSObjectCollection items = new GXDLMSObjectCollection(this);
     long cnt = GXCommon.GetObjectCount(buff, ref index);
     int total, count;            
     for (long objPos = 0; objPos != cnt; ++objPos)
     {
         DataType dt = DataType.None;
         int cachePosition = 0;
         object[] objects = (object[])GXCommon.GetData(buff, ref index, ActionType.None, out total, out count, ref dt, ref cachePosition);
         if (index == -1)
         {
             throw new OutOfMemoryException();
         }
         if (objects.Length != 4)
         {
             throw new GXDLMSException("Invalid structure format.");
         }
         int ot = Convert.ToInt16(objects[1]);
         int baseName = Convert.ToInt32(objects[0]) & 0xFFFF;
         if (!onlyKnownObjects || GXDLMS.AvailableObjectTypes.ContainsKey((ObjectType)ot))                
         {                    
             if (baseName > 0)
             {
                 GXDLMSObject comp = CreateDLMSObject(ot, objects[2], baseName, objects[3], null);
                 if (comp != null)
                 {
                     items.Add(comp);
                 }
             }
         }
         else
         {
             System.Diagnostics.Debug.WriteLine(string.Format("Unknown object : {0} {1}", ot, baseName));
         }
     }
     return items;
 }
Ejemplo n.º 54
0
 ///<summary>
 ///Constructor.
 ///</summary>
 public GXDLMSSettings(GXDLMSObjectCollection objects) : this(false)
 {
     Objects = objects;
 }
Ejemplo n.º 55
0
 /// <summary>
 /// Read Profile Generic Columns by range.
 /// </summary>
 public object[] ReadRowsByRange(GXDLMSObject it, DateTime start, DateTime end, GXDLMSObjectCollection columns)
 {
     GXDLMSObject col = columns[0];
     byte[] reply = ReadDataBlock(m_Parser.Read(m_Parser.ReadRowsByRange(it.Name, col.LogicalName, col.ObjectType, col.Version, start, end), 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;
 }
Ejemplo n.º 56
0
 private void ObjectList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     try
     {
         this.ObjectTree.AfterSelect -= new System.Windows.Forms.TreeViewEventHandler(this.ObjectTree_AfterSelect);
         if (e.IsSelected)
         {
             SelectedListItems.Add(e.ItemIndex, e.Item.Tag as GXDLMSObject);
             if (SelectedListItems.Count == 1)
             {
                 SelectItem(e.Item.Tag);
             }
             else
             {
                 GXDLMSObjectCollection items = new GXDLMSObjectCollection();
                 items.AddRange(SelectedListItems.Values.ToArray());
                 SelectItem(items);
             }
             TreeNode node = ObjectTreeItems[e.Item.Tag] as TreeNode;
             if (node != null)
             {
                 ObjectTree.SelectedNode = node;
             }
         }
         else
         {
             int pos = SelectedListItems.IndexOfValue(e.Item.Tag as GXDLMSObject);
             if (pos != -1)
             {
                 SelectedListItems.RemoveAt(pos);
             }
             else
             {
                 return;
             }
             if (SelectedListItems.Count == 0)
             {
                 SelectItem(((GXDLMSObject)e.Item.Tag).Parent.Tag);
             }
             else if (SelectedListItems.Count == 1)
             {
                 SelectItem(SelectedListItems.Values[0]);
             }
             else
             {
                 GXDLMSObjectCollection items = new GXDLMSObjectCollection();
                 items.AddRange(SelectedListItems.Values.ToArray());
                 SelectItem(items);
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
     finally
     {
         this.ObjectTree.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.ObjectTree_AfterSelect);
     }
 }
Ejemplo n.º 57
0
 ///<summary>
 ///Constructor.
 ///</summary>
 internal GXDLMSSettings(bool server)
 {
     UseCustomChallenge = false;
     StartingBlockIndex = BlockIndex = 1;
     DLMSVersion = 6;
     InvokeID = 0x1;
     Priority = Priority.High;
     ServiceClass = ServiceClass.Confirmed;
     MaxServerPDUSize = MaxPduSize = DefaultMaxReceivePduSize;
     IsServer = server;
     Objects = new GXDLMSObjectCollection();
     Limits = new GXDLMSLimits();
     LnSettings = new GXDLMSLNSettings(new byte[] { 0x00, 0xFE, 0x1F });
     SnSettings = new GXDLMSSNSettings(new byte[] { 0x1C, 0x03, 0x20 });
     ResetFrameSequence();
 }
Ejemplo n.º 58
0
 /// <summary>
 /// Read selected DLMS object.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ReadMnu_Click(object sender, EventArgs e)
 {
     if (tabControl1.SelectedIndex == 0)
     {
         //Set focus to the tree or Read count do not updated.
         this.ObjectTree.Focus();
         if (this.ObjectTree.SelectedNode != null)
         {
             TransactionWork = new GXAsyncWork(this, OnAsyncStateChange, Read, new object[] { this.ObjectTree.SelectedNode.Tag, SelectedView });
             TransactionWork.Start();
         }
     }
     else
     {
         if (this.ObjectList.SelectedItems.Count != 0)
         {
             GXDLMSObjectCollection items = new GXDLMSObjectCollection();
             foreach (ListViewItem it in this.ObjectList.SelectedItems)
             {
                 items.Add(it.Tag as GXDLMSObject);
             }
             TransactionWork = new GXAsyncWork(this, OnAsyncStateChange, Read, new object[] { items, SelectedView });
             TransactionWork.Start();
         }
     }
 }
Ejemplo n.º 59
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public GXDLMSDevice(Gurux.Common.IGXMedia media)
 {
     StartProtocol = StartProtocolType.IEC;
     ClientID = 0x10; // Public client (lowest security level).
     PhysicalAddress = 1;
     Password = "";
     Authentication = Authentication.None;
     m_Communicator = new GXDLMSCommunicator(this, media);
     m_Objects = m_Communicator.m_Cosem.Objects;
     m_Objects.Tag = this;
     m_Communicator.OnProgress += new ProgressEventHandler(this.NotifyProgress);
     this.KeepAlive = new System.Timers.Timer();
     this.KeepAlive.Interval = 40000;
     this.KeepAlive.Elapsed += new System.Timers.ElapsedEventHandler(KeepAlive_Elapsed);
     m_Status = DeviceState.Initialized;
     WaitTime = 5;
 }
 object IGXDLMSBase.GetValue(int index, int selector, object parameters)
 {
     if (ObjectList == null)
     {
         ObjectList = new GXDLMSObjectCollection();
     }
     if (index == 1)
     {
         return this.LogicalName;
     }
     else if (index == 2)
     {
         int cnt = ObjectList.Count;
         List<byte> data = new List<byte>();
         data.Add((byte)DataType.Array);
         //Add count            
         GXCommon.SetObjectCount(cnt, data);
         if (cnt != 0)
         {
             foreach (GXDLMSObject it in ObjectList)
             {
                 data.Add((byte)DataType.Structure);
                 data.Add((byte)4); //Count
                 GXCommon.SetData(data, DataType.Int16, it.ShortName); //base address.
                 GXCommon.SetData(data, DataType.UInt16, it.ObjectType); //ClassID
                 GXCommon.SetData(data, DataType.UInt8, 0); //Version
                 GXCommon.SetData(data, DataType.OctetString, it.LogicalName); //LN
             }
             if (ObjectList.FindBySN(this.ShortName) == null)
             {
                 data.Add((byte)DataType.Structure);
                 data.Add((byte)4); //Count
                 GXCommon.SetData(data, DataType.Int16, this.ShortName); //base address.
                 GXCommon.SetData(data, DataType.UInt16, this.ObjectType); //ClassID
                 GXCommon.SetData(data, DataType.UInt8, 0); //Version
                 GXCommon.SetData(data, DataType.OctetString, this.LogicalName); //LN
             }
         }
         return data.ToArray();
     }
     else if (index == 3)
     {
         bool lnExists = ObjectList.FindBySN(this.ShortName) != null;
         //Add count        
         int cnt = ObjectList.Count;
         if (!lnExists)
         {
             ++cnt;
         }
         List<byte> data = new List<byte>();
         data.Add((byte)DataType.Array);
         GXCommon.SetObjectCount(cnt, data);
         foreach (GXDLMSObject it in ObjectList)
         {
             GetAccessRights(it, data);
         }
         if (!lnExists)
         {
             GetAccessRights(this, data);
         }
         return data.ToArray();
     }
     else if (index == 4)
     {
         List<byte> data = new List<byte>();
         GXCommon.SetData(data, DataType.OctetString, SecuritySetupReference);
         return data.ToArray();
     }
     throw new ArgumentException("GetValue failed. Invalid attribute index.");
 }