Esempio n. 1
0
 public object ReadElementContentAsObject(string name, object defaultValue)
 {
     GetNext();
     if (string.Compare(name, reader.Name, true) == 0)
     {
         object   ret;
         DataType tp = (DataType)Enum.Parse(typeof(DataType), reader.GetAttribute(0));
         if (tp == DataType.Array)
         {
             reader.Read();
             GetNext();
             ret = ReadArray();
             ReadEndElement(name);
             return(ret);
         }
         else
         {
             string str = reader.ReadElementContentAsString();
             if (tp == DataType.OctetString)
             {
                 ret = GXDLMSTranslator.HexToBytes(str);
             }
             else if (tp == DataType.DateTime)
             {
                 ret = new GXDateTime(str, CultureInfo.InvariantCulture);
             }
             else if (tp == DataType.Date)
             {
                 ret = new GXDate(str, CultureInfo.InvariantCulture);
             }
             else if (tp == DataType.Time)
             {
                 ret = new GXTime(str, CultureInfo.InvariantCulture);
             }
             else
             {
                 ret = Convert.ChangeType(str, GXDLMSConverter.GetDataType(tp));
             }
         }
         while (!(reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement))
         {
             reader.Read();
         }
         return(ret);
     }
     return(defaultValue);
 }
Esempio n. 2
0
        private static void SetCaptureObjects(GXDLMSProfileGeneric parent, GXDLMSSettings settings, List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > list, List <object> array)
        {
            GXDLMSConverter c = null;

            try
            {
                foreach (object it in array)
                {
                    List <object> tmp = it as List <object>;
                    if (tmp.Count != 4)
                    {
                        throw new GXDLMSException("Invalid structure format.");
                    }
                    int v = Convert.ToInt16(tmp[0]);
                    if (Enum.GetName(typeof(ObjectType), v) == null)
                    {
                        list.Clear();
                        return;
                    }
                    ObjectType   type           = (ObjectType)v;
                    string       ln             = GXCommon.ToLogicalName((byte[])tmp[1]);
                    int          attributeIndex = Convert.ToInt16(tmp[2]);
                    int          dataIndex      = Convert.ToInt16(tmp[3]);
                    GXDLMSObject obj            = null;
                    if (settings != null && settings.Objects != null)
                    {
                        obj = settings.Objects.FindByLN(type, ln);
                    }
                    //Create a new instance to avoid circular references.
                    if (obj == null || obj == parent)
                    {
                        obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0);
                        if (c == null)
                        {
                            c = new GXDLMSConverter();
                        }
                        c.UpdateOBISCodeInformation(obj);
                    }
                    list.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex)));
                }
            }
            catch (Exception)
            {
                list.Clear();
            }
        }
Esempio n. 3
0
 public object ReadElementContentAsObject(string name, object defaultValue, GXDLMSObject obj, byte index)
 {
     GetNext();
     if (string.Compare(name, reader.Name, true) == 0)
     {
         object   ret;
         DataType uiType;
         DataType dt = (DataType)Enum.Parse(typeof(DataType), reader.GetAttribute(0));
         if (obj != null)
         {
             obj.SetDataType(index, dt);
         }
         if (reader.AttributeCount > 1)
         {
             uiType = (DataType)Enum.Parse(typeof(DataType), reader.GetAttribute(1));
         }
         else
         {
             uiType = dt;
         }
         if (obj != null && obj.GetUIDataType(index) == DataType.None)
         {
             obj.SetUIDataType(index, uiType);
         }
         if (dt == DataType.Array || dt == DataType.Structure)
         {
             reader.Read();
             GetNext();
             ret = ReadArray();
             ReadEndElement(name);
             return(ret);
         }
         else
         {
             string str = reader.ReadElementContentAsString();
             ret = GXDLMSConverter.ChangeType(str, uiType, CultureInfo.InvariantCulture);
         }
         while (!(reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement))
         {
             reader.Read();
         }
         return(ret);
     }
     return(defaultValue);
 }
Esempio n. 4
0
 public GXRegisterMonitorTargetDlg(GXDLMSRegisterMonitor target, int index, bool remove)
 {
     Target = target;
     Index  = index;
     InitializeComponent();
     foreach (DataType it in Enum.GetValues(typeof(DataType)))
     {
         if (it != DataType.None && it != DataType.Array && it != DataType.Structure)
         {
             ValueTypeTb.Items.Add(it);
         }
     }
     foreach (var it in target.Parent.GetObjects(Enums.ObjectType.ScriptTable))
     {
         UpNameCb.Items.Add(it);
         DownNameCb.Items.Add(it);
     }
     if (remove)
     {
         Text = "Remove Threshold";
         DownNameCb.Enabled      = UpNameCb.Enabled = false;
         DownSelectorTb.ReadOnly = UpSelectorTb.ReadOnly = ValueTb.ReadOnly = true;
     }
     else
     {
         Text = "Add new Threshold";
     }
     if (target.Thresholds != null && index < target.Thresholds.Length)
     {
         ValueTb.Text = Convert.ToString(target.Thresholds[index]);
     }
     if (target.Thresholds != null && target.Thresholds.Length != 0)
     {
         ValueTypeTb.SelectedItem = GXDLMSConverter.GetDLMSDataType(target.Thresholds[0]);
     }
     if (target.Actions != null && index < target.Actions.Length)
     {
         GXDLMSActionSet set1 = target.Actions[index];
         UpNameCb.SelectedItem   = target.Parent.FindByLN(Enums.ObjectType.ScriptTable, set1.ActionUp.LogicalName);
         UpSelectorTb.Text       = Convert.ToString(set1.ActionUp.ScriptSelector);
         DownNameCb.SelectedItem = target.Parent.FindByLN(Enums.ObjectType.ScriptTable, set1.ActionDown.LogicalName);
         DownSelectorTb.Text     = Convert.ToString(set1.ActionDown.ScriptSelector);
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Write object value to file.
        /// </summary>
        /// <param name="name">Object name.</param>
        /// <param name="value">Object value.</param>
        /// <param name="skipDefaultValue">Is default value serialized.</param>
        public void WriteElementObject(string name, object value, bool skipDefaultValue)
        {
            if (value != null)
            {
                if (skipDefaultValue && value is DateTime && ((DateTime)value == DateTime.MinValue || (DateTime)value == DateTime.MaxValue))
                {
                    return;
                }

                writer.WriteStartElement(name);
                DataType dt = GXDLMSConverter.GetDLMSDataType(value);
                writer.WriteAttributeString("Type", ((int)dt).ToString());
                if (dt == DataType.Array)
                {
                    WriteArray(value);
                }
                else
                {
                    if (value is GXDateTime)
                    {
                        writer.WriteString(((GXDateTime)value).ToFormatString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                    else if (value is DateTime)
                    {
                        writer.WriteString(((DateTime)value).ToString(System.Globalization.CultureInfo.InvariantCulture));
                    }
                    else if (value is byte[])
                    {
                        writer.WriteString(GXDLMSTranslator.ToHex((byte[])value));
                    }
                    else
                    {
                        writer.WriteString(Convert.ToString(value));
                    }
                }
                writer.WriteEndElement();
            }
            else if (!skipDefaultValue)
            {
                writer.WriteStartElement(name);
                writer.WriteEndElement();
            }
        }
        /// <summary>
        /// Sends data to the M-Bus slave device.
        /// </summary>
        /// <param name="client">DLMS client settings.</param>
        /// <param name="data">data to send</param>
        /// <returns>Generated DLMS data.</returns>
        public byte[][] SendData(GXDLMSClient client, GXMBusClientData[] data)
        {
            GXByteBuffer bb = new GXByteBuffer();

            bb.SetUInt8(DataType.Array);
            bb.SetUInt8(DataType.Structure);
            GXCommon.SetObjectCount(data.Length, bb);
            foreach (GXMBusClientData it in data)
            {
                bb.SetUInt8(DataType.Structure);
                bb.SetUInt8(3);
                bb.SetUInt8(DataType.OctetString);
                GXCommon.SetObjectCount(it.DataInformation.Length, bb);
                bb.Set(it.DataInformation);
                bb.SetUInt8(DataType.OctetString);
                GXCommon.SetObjectCount(it.ValueInformation.Length, bb);
                bb.Set(it.ValueInformation);
                GXCommon.SetData(client.Settings, bb, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
            }
            return(client.Method(this, 6, bb.Array(), DataType.Array));
        }
 void IGXDLMSBase.Load(GXXmlReader reader)
 {
     Scripts.Clear();
     if (reader.IsStartElement("Scripts", true))
     {
         while (reader.IsStartElement("Script", true))
         {
             GXDLMSScript it = new GXDLMSScript();
             Scripts.Add(it);
             it.Id = reader.ReadElementContentAsInt("ID");
             if (reader.IsStartElement("Actions", true))
             {
                 while (reader.IsStartElement("Action", true))
                 {
                     GXDLMSScriptAction a = new Objects.GXDLMSScriptAction();
                     a.Type = (ScriptActionType)reader.ReadElementContentAsInt("Type");
                     ObjectType ot = (ObjectType)reader.ReadElementContentAsInt("ObjectType");
                     string     ln = reader.ReadElementContentAsString("LN");
                     a.Index  = reader.ReadElementContentAsInt("Index");
                     a.Target = reader.Objects.FindByLN(ot, ln);
                     if (a.Target == null)
                     {
                         a.Target             = GXDLMSClient.CreateObject(ot);
                         a.Target.LogicalName = ln;
                     }
                     a.ParameterDataType = (DataType)reader.ReadElementContentAsInt("ParameterDataType");
                     a.Parameter         = reader.ReadElementContentAsString("Parameter", null);
                     if (a.ParameterDataType != DataType.None)
                     {
                         a.Parameter = GXDLMSConverter.ChangeType(a.Parameter, a.ParameterDataType, CultureInfo.InvariantCulture);
                     }
                     it.Actions.Add(a);
                 }
                 reader.ReadEndElement("Actions");
             }
         }
         reader.ReadEndElement("Scripts");
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Update server system title if Italy standard is used.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ServerSystemTitle_TextChanged(object sender, EventArgs e)
 {
     try
     {
         int len = ServerSystemTitleTb.Text.Replace(" ", "").Length;
         if (len != 0 && len != 16)
         {
             throw new Exception("Invalid system title.");
         }
         toolTip1.SetToolTip(ServerSystemTitleTb, null);
         if (len == 16)
         {
             byte[] tmp = GXDLMSTranslator.HexToBytes(ServerSystemTitleTb.Text);
             toolTip1.SetToolTip(ServerSystemTitleTb, GXDLMSConverter.SystemTitleToString(_standard, tmp, true));
         }
     }
     catch (Exception ex)
     {
         ServerSystemTitleTb.Select();
         MessageBox.Show(Parent, ex.Message);
     }
 }
Esempio n. 9
0
 private void OkBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (DataTypeCb.SelectedItem == null)
         {
             throw new Exception("Data type is not selected.");
         }
         if (DataTb.Text == "")
         {
             throw new Exception("Invalid data.");
         }
         Data.ValueInformation = GXDLMSTranslator.HexToBytes(ValueInformationTb.Text);
         Data.DataInformation  = GXDLMSTranslator.HexToBytes(DataInformationTb.Text);
         Data.Data             = Convert.ChangeType(Data, GXDLMSConverter.GetDataType((DataType)DataTypeCb.SelectedItem));
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         DialogResult = DialogResult.None;
     }
 }
Esempio n. 10
0
 public void WriteElementObject(string name, object value, DataType type, DataType uiType)
 {
     if (type != DataType.None && value is string)
     {
         if (type == DataType.OctetString)
         {
             if (uiType == DataType.String)
             {
                 value = ASCIIEncoding.ASCII.GetBytes((string)value);
             }
             else if (uiType == DataType.OctetString)
             {
                 value = GXDLMSTranslator.HexToBytes((string)value);
             }
         }
         else if (!(value is GXDateTime))
         {
             Type newType = GXDLMSConverter.GetDataType(type);
             value = Convert.ChangeType(value, newType);
         }
     }
     WriteElementObject(name, value, true);
 }
Esempio n. 11
0
 public GXDLMSMBusClientDataDlg(GXMBusClientData data)
 {
     InitializeComponent();
     Data = data;
     foreach (DataType it in Enum.GetValues(typeof(DataType)))
     {
         if (it != DataType.None && it != DataType.Array && it != DataType.Structure)
         {
             DataTypeCb.Items.Add(it);
         }
     }
     ValueInformationTb.Text = GXDLMSTranslator.ToHex(data.ValueInformation);
     DataInformationTb.Text  = GXDLMSTranslator.ToHex(data.DataInformation);
     if (data.Data is byte[])
     {
         DataTb.Text = GXDLMSTranslator.ToHex((byte[])data.Data);
     }
     else
     {
         DataTb.Text = Convert.ToString(data.Data);
     }
     DataTypeCb.SelectedItem = GXDLMSConverter.GetDLMSDataType(data.Data);
 }
Esempio n. 12
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(GXCommon.LogicalNameToBytes(PHYReference));
     }
     if (e.Index == 3)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (LCPOptions == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)LCPOptions.Length);
             foreach (GXDLMSPppSetupLcpOption it in LCPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
             }
         }
         return(data.Array());
     }
     if (e.Index == 4)
     {
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Array);
         if (IPCPOptions == null)
         {
             data.SetUInt8(0);
         }
         else
         {
             data.SetUInt8((byte)IPCPOptions.Length);
             foreach (GXDLMSPppSetupIPCPOption it in IPCPOptions)
             {
                 data.SetUInt8((byte)DataType.Structure);
                 data.SetUInt8((byte)3);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Type);
                 GXCommon.SetData(settings, data, DataType.UInt8, it.Length);
                 GXCommon.SetData(settings, data, GXDLMSConverter.GetDLMSDataType(it.Data), it.Data);
             }
         }
         return(data.Array());
     }
     else if (e.Index == 5)
     {
         if (UserName == null || UserName.Length == 0)
         {
             return(null);
         }
         GXByteBuffer data = new GXByteBuffer();
         data.SetUInt8((byte)DataType.Structure);
         data.SetUInt8(2);
         GXCommon.SetData(settings, data, DataType.OctetString, UserName);
         GXCommon.SetData(settings, data, DataType.OctetString, Password);
         return(data.Array());
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
Esempio n. 13
0
        /// <summary>
        /// Import server settings and COSEM objects from GXDLMSDirector trace.
        /// </summary>
        /// <param name="server">Server where settings are updated.</param>
        /// <param name="data">GXDLMSDirector trace in byte array.</param>
        public static void Import(GXDLMSServer server, byte[] data)
        {
            GXDLMSTranslator translator = new GXDLMSTranslator(TranslatorOutputType.StandardXml);
            translator.CompletePdu = true;
            translator.PduOnly = true;
            XmlDocument doc = new XmlDocument();
            List<ValueEventArgs> targets = new List<ValueEventArgs>();
            GXDLMSSettings settings = new GXDLMSSettings(true);
            GXByteBuffer pdu = new GXByteBuffer();
            GXByteBuffer bb = new GXByteBuffer(data);
            server.InterfaceType = GXDLMSTranslator.GetDlmsFraming(bb);
            bool lastBlock = true;
            GXByteBuffer val = new DLMS.GXByteBuffer();
            while (translator.FindNextFrame(bb, pdu, server.InterfaceType))
            {
                String xml = translator.MessageToXml(bb);
                if (xml != "")
                {
                    doc.LoadXml(xml);
                    foreach (XmlNode node in doc.ChildNodes[doc.ChildNodes.Count - 1].ChildNodes)
                    {
                        if (node.Name == "x:get-request")
                        {
                            server.UseLogicalNameReferencing = true;
                            GetLN(settings.Objects, targets, node.ChildNodes);
                        }
                        else if (node.Name == "x:readRequest")
                        {
                            List<short> items = GetSN(node.ChildNodes);

                            server.UseLogicalNameReferencing = false;
                            foreach (short it in items)
                            {
                                GXSNInfo i = GXDLMSSNCommandHandler.FindSNObject(settings.Objects, Convert.ToUInt16((it) & 0xFFFF));
                                targets.Add(new ValueEventArgs(i.Item, i.Index, 0, null));
                            }
                        }
                        else if (node.Name == "x:readResponse" ||
                                 node.Name == "x:get-response")
                        {
                            if (targets != null)
                            {
                                List<string> items;
                                if (server.UseLogicalNameReferencing)
                                {
                                    items = GetLNValues(node.ChildNodes);
                                }
                                else
                                {
                                    items = GetSNValues(node.ChildNodes);
                                }

                                int pos = 0;
                                foreach (string it in items)
                                {
                                    if ("read-write-denied".Equals(it) ||
                                            "scope-of-access-violated".Equals(it) ||
                                            "object-unavailable".Equals(it))
                                    {
                                        ValueEventArgs ve = targets[pos];
                                        ve.Target.SetAccess(ve.Index, AccessMode.NoAccess);
                                        continue;
                                    }
                                    try
                                    {
                                        if (server.UseLogicalNameReferencing)
                                        {
                                            lastBlock = IsLastBlock(node.ChildNodes);
                                        }
                                        val.Set(translator.XmlToData(it));
                                        if (lastBlock)
                                        {
                                            if (settings.Objects.Count == 0)
                                            {
                                                GXDLMSClient c = new GXDLMSClient();
                                                c.UseLogicalNameReferencing = server.UseLogicalNameReferencing;
                                                settings.Objects = c.ParseObjects(val, true);
                                                //Update OBIS code description.
                                                GXDLMSConverter converter = new GXDLMSConverter();
                                                converter.UpdateOBISCodeInformation(settings.Objects);
                                            }
                                            else
                                            {
                                                ValueEventArgs ve = targets[pos];
                                                GXDataInfo info = new GXDataInfo();
                                                ve.Value = GXCommon.GetData(server.Settings, val, info);
                                                if (ve.Value is byte[])
                                                {
                                                    DataType tp = ve.Target.GetUIDataType(ve.Index);
                                                    if (tp != DataType.None)
                                                    {
                                                        ve.Value = GXDLMSClient.ChangeType((byte[])ve.Value, tp);
                                                    }
                                                }
                                                ((IGXDLMSBase)ve.Target).SetValue(settings, ve);
                                            }
                                            val.Clear();
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        ValueEventArgs ve = targets[pos];
                                        ve.Target.SetAccess(ve.Index, AccessMode.NoAccess);

                                    }
                                    ++pos;
                                }
                                if (lastBlock)
                                {
                                    targets.Clear();
                                }
                            }

                        }
                    }
                }
            }
            server.Items.Clear();
            server.Items.AddRange(settings.Objects);
        }
Esempio n. 14
0
        static int Main(string[] args)
        {
            SetAddRemoveProgramsIcon();
            GXOutput   ouput    = new Test.GXOutput();
            GXSettings settings = new GXSettings();
            List <KeyValuePair <GXDLMSXmlPdu, List <string> > > differences = new List <KeyValuePair <GXDLMSXmlPdu, List <string> > >();
            GXDLMSConverter c = new GXDLMSConverter();

            try
            {
                if (args.Length == 0)
                {
                    GXProperties dlg = new GXProperties(settings);
                    if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    {
                        return(0);
                    }
                }
                else
                {
                    //Handle command line parameters.
                    int ret = GXSettings.GetParameters(args, settings);
                    if (ret != 0)
                    {
                        return(ret);
                    }
                }
                ////////////////////////////////////////
                //Check media connection settings.
                if (!(settings.media is GXSerial ||
                      settings.media is GXNet))
                {
                    throw new Exception("Unknown media type.");
                }

                //Read basic tests to pass DLMS Conformance tests.
                //Breen Book: 4.1.8.4 Mandatory contents of a COSEM logical device
                //1. Read Association view.
                //2. Check Logical Device Name
                //3. Check SAP.
                if ((settings.tests & ConformanceTest.Cosem) != 0)
                {
                    ouput.writer.Write("<h2>Cosem tests:</h2>");
                    GXTests.Basic(settings, ouput);
                }
            }
            catch (Exception e)
            {
                if (settings.trace > TraceLevel.Off)
                {
                    Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                    Console.WriteLine("Gurux Conformance Test ended.");
                    Console.WriteLine(e.Message);
                }
                return(1);
            }
            try
            {
                if ((settings.tests & ConformanceTest.Init) != 0)
                {
                    ouput.writer.Write("<h2>Initialization tests:</h2>");
                    GXTests.Init(settings, ouput);
                }
            }
            catch (Exception ex)
            {
                if (settings.trace > TraceLevel.Off)
                {
                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine(ex.Message);
                }
                return(1);
            }
            try
            {
                if (settings.path != null)
                {
                    ouput.writer.Write("<h2>Extra tests:</h2>");
                    GXTests.Extra(settings, ouput);
                }
            }
            catch (Exception ex)
            {
                if (settings.trace > TraceLevel.Off)
                {
                    Console.WriteLine("------------------------------------------------------------");
                    Console.WriteLine(ex.Message);
                }
                return(1);
            }
            Console.WriteLine("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            Console.WriteLine("Gurux Conformance Test ended.");
            ouput.writer.Flush();
            Process.Start(ouput.GetName());
            return(0);
        }
Esempio n. 15
0
 object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         return(GXCommon.LogicalNameToBytes(LogicalName));
     }
     if (e.Index == 2)
     {
         return(MaxHops);
     }
     if (e.Index == 3)
     {
         return(WeakLqiValue);
     }
     if (e.Index == 4)
     {
         return(SecurityLevel);
     }
     if (e.Index == 5)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (PrefixTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(PrefixTable.Length, bb);
             foreach (var it in PrefixTable)
             {
                 GXCommon.SetData(settings, bb, GXDLMSConverter.GetDLMSDataType(it), it);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 6)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (RoutingConfiguration == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(RoutingConfiguration.Count, bb);
             foreach (GXDLMSRoutingConfiguration it in RoutingConfiguration)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(14);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.NetTraversalTime);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.RoutingTableEntryTtl);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kr);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Km);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kc);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kq);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Kh);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.Krt);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.RreqRetries);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.RreqRerrWait);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.BlacklistTableEntryTtl);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.UnicastRreqGenEnable);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.RlcEnabled);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.AddRevLinkCost);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 7)
     {
         return(BroadcastLogTableEntryTtl);
     }
     if (e.Index == 8)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (RoutingTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(RoutingTable.Count, bb);
             foreach (GXDLMSRoutingTable it in RoutingTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(6);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.DestinationAddress);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.NextHopAddress);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.RouteCost);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.HopCount);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.WeakLinkCount);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ValidTime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 9)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (ContextInformationTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(ContextInformationTable.Count, bb);
             foreach (GXDLMSContextInformationTable it in ContextInformationTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(5);
                 GXCommon.SetData(settings, bb, DataType.BitString, it.CID);
                 if (it.Context == null)
                 {
                     GXCommon.SetData(settings, bb, DataType.UInt8, 0);
                 }
                 else
                 {
                     GXCommon.SetData(settings, bb, DataType.UInt8, it.Context.Length);
                 }
                 GXCommon.SetData(settings, bb, DataType.OctetString, it.Context);
                 GXCommon.SetData(settings, bb, DataType.Boolean, it.Compression);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ValidLifetime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 10)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (BlacklistTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(BlacklistTable.Count, bb);
             foreach (var it in BlacklistTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(2);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.Key);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.Value);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 11)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (BroadcastLogTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(BroadcastLogTable.Count, bb);
             foreach (GXDLMSBroadcastLogTable it in BroadcastLogTable)
             {
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(3);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.SourceAddress);
                 GXCommon.SetData(settings, bb, DataType.UInt8, it.SequenceNumber);
                 GXCommon.SetData(settings, bb, DataType.UInt16, it.ValidTime);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 12)
     {
         GXByteBuffer bb = new GXByteBuffer();
         bb.SetUInt8((byte)DataType.Array);
         if (GroupTable == null)
         {
             bb.SetUInt8(0);
         }
         else
         {
             GXCommon.SetObjectCount(GroupTable.Length, bb);
             foreach (UInt16 it in GroupTable)
             {
                 GXCommon.SetData(settings, bb, DataType.UInt16, it);
             }
         }
         return(bb.Array());
     }
     if (e.Index == 13)
     {
         return(MaxJoinWaitTime);
     }
     if (e.Index == 14)
     {
         return(PathDiscoveryTime);
     }
     if (e.Index == 15)
     {
         return(ActiveKeyIndex);
     }
     if (e.Index == 16)
     {
         return(MetricType);
     }
     if (e.Index == 17)
     {
         return(CoordShortAddress);
     }
     if (e.Index == 18)
     {
         return(DisableDefaultRouting);
     }
     if (e.Index == 19)
     {
         return(DeviceType);
     }
     e.Error = ErrorCode.ReadWriteDenied;
     return(null);
 }
        /// <summary>
        /// Returns buffer data.
        /// </summary>
        /// <param name="settings">DLMS settings.</param>
        /// <param name="e"></param>
        /// <param name="table"></param>
        /// <param name="columns">Columns to get. NULL if not used.</param>
        /// <returns></returns>
        byte[] GetData(GXDLMSSettings settings, ValueEventArgs e, List <object[]> table,
                       List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns)
        {
            int pos = 0;
            List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = columns;

            if (columns == null)
            {
                cols = CaptureObjects;
            }
            DataType[] types = new DataType[cols.Count];
            foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in cols)
            {
                types[pos] = it.Key.GetDataType(it.Value.AttributeIndex);
                ++pos;
            }
            UInt16 columnStart = 1, columnEnd = 0;

            if (e.Selector == 2)
            {
                columnStart = (UInt16)((object[])e.Parameters)[2];
                columnEnd   = (UInt16)((object[])e.Parameters)[3];
            }

            if (columnStart > 1 || columnEnd != 0)
            {
                pos  = 1;
                cols = new List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> >();
                foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in CaptureObjects)
                {
                    if (!(pos < columnStart || pos > columnEnd))
                    {
                        cols.Add(it);
                    }
                    ++pos;
                }
                pos = 0;
            }
            GXByteBuffer data = new GXByteBuffer();

            if (settings.Index == 0)
            {
                data.SetUInt8((byte)DataType.Array);
                if (e.RowEndIndex != 0)
                {
                    GXCommon.SetObjectCount((int)(e.RowEndIndex - e.RowBeginIndex), data);
                }
                else
                {
                    GXCommon.SetObjectCount(table.Count, data);
                }
            }

            foreach (object[] items in table)
            {
                data.SetUInt8((byte)DataType.Structure);
                GXCommon.SetObjectCount(cols.Count, data);
                pos = 0;
                DataType tp;
                foreach (object value in items)
                {
                    if (cols == null || cols.Contains(CaptureObjects[pos]))
                    {
                        tp = types[pos];
                        if (tp == DataType.None)
                        {
                            tp         = GXDLMSConverter.GetDLMSDataType(value);
                            types[pos] = tp;
                        }
                        if (value == null)
                        {
                            tp = DataType.None;
                        }
                        GXCommon.SetData(settings, data, tp, value);
                    }
                    ++pos;
                }
                ++settings.Index;
            }
            if (e.RowEndIndex != 0)
            {
                e.RowBeginIndex += (UInt32)table.Count;
            }
            else
            {
                settings.Index = 0;
            }
            return(data.Array());
        }
Esempio n. 17
0
 /// <summary>
 /// Accept changes.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OkBtn_Click(object sender, EventArgs e)
 {
     try
     {
         if (ValueTypeTb.SelectedItem == null || (DataType)ValueTypeTb.SelectedItem == DataType.None)
         {
             throw new Exception("Invalid value type.");
         }
         if (ValueTb.Text.Length == 0)
         {
             throw new Exception("Invalid value.");
         }
         byte up, down;
         if (!byte.TryParse(UpSelectorTb.Text, out up))
         {
             throw new Exception("Invalid action up selector.");
         }
         if (!byte.TryParse(DownSelectorTb.Text, out down))
         {
             throw new Exception("Invalid action down selector.");
         }
         if (UpNameCb.SelectedItem == null)
         {
             throw new Exception("Invalid action up script.");
         }
         if (DownNameCb.SelectedItem == null)
         {
             throw new Exception("Invalid action down script.");
         }
         if (Target.Thresholds != null && Index < Target.Thresholds.Length)
         {
             Target.Thresholds[Index] = GXDLMSConverter.ChangeType(ValueTb.Text, (DataType)ValueTypeTb.SelectedItem, null);
         }
         else
         {
             //We are adding new item.
             List <object> thresholds = new List <object>();
             if (Target.Thresholds != null)
             {
                 thresholds.AddRange(Target.Thresholds);
             }
             thresholds.Add(GXDLMSConverter.ChangeType(ValueTb.Text, (DataType)ValueTypeTb.SelectedItem, null));
             Target.Thresholds = thresholds.ToArray();
         }
         GXDLMSActionSet set1;
         if (Target.Actions != null && Index < Target.Actions.Length)
         {
             set1 = Target.Actions[Index];
         }
         else
         {
             //We are adding new item.
             List <GXDLMSActionSet> actions = new List <GXDLMSActionSet>();
             if (Target.Actions != null)
             {
                 actions.AddRange(Target.Actions);
             }
             set1 = new GXDLMSActionSet();
             actions.Add(set1);
             Target.Actions = actions.ToArray();
         }
         set1.ActionUp.LogicalName      = ((GXDLMSObject)UpNameCb.SelectedItem).LogicalName;
         set1.ActionUp.ScriptSelector   = up;
         set1.ActionDown.LogicalName    = ((GXDLMSObject)DownNameCb.SelectedItem).LogicalName;
         set1.ActionDown.ScriptSelector = down;
     }
     catch (Exception ex)
     {
         DialogResult = DialogResult.None;
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 18
0
 public void UpdateColumns(GXDLMSProfileGeneric item, GXManufacturer man)
 {
     if (Comm.parentForm.InvokeRequired)
     {
         try
         {
             Comm.parentForm.Invoke(new UpdateColumnsEventHandler(UpdateColumns), item, man);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         return;
     }
     try
     {
         item.Buffer.Clear();
         item.CaptureObjects.Clear();
         List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = null;
         List <DataColumn> columns = new List <DataColumn>();
         try
         {
             Comm.GetProfileGenericColumns(item);
             if (Standard == Standard.Italy && item.CaptureObjects.Count == 0)
             {
                 cols = GetColumns(Comm.client.Objects, Comm.client.CustomObisCodes, item.LogicalName, 0);
                 GXDLMSConverter c = new GXDLMSConverter(Standard);
                 foreach (var it in cols)
                 {
                     c.UpdateOBISCodeInformation(it.Key);
                 }
                 item.CaptureObjects.AddRange(cols);
             }
         }
         catch (GXDLMSException ex)
         {
             if (Standard == Standard.Italy)
             {
                 GXDLMSData obj  = Comm.client.Objects.FindByLN(ObjectType.Data, "0.0.96.1.3.255") as GXDLMSData;
                 int        type = 0;
                 if (obj != null)
                 {
                     if (obj.Value == null)
                     {
                         try
                         {
                             Comm.ReadValue(obj, 2);
                             type = Convert.ToInt16(obj.Value);
                         }
                         catch (Exception)
                         {
                             type = 0;
                         }
                     }
                     else
                     {
                         type = Convert.ToInt16(obj.Value);
                     }
                 }
                 cols = GetColumns(Comm.client.Objects, Comm.client.CustomObisCodes, item.LogicalName, type);
                 item.CaptureObjects.Clear();
                 GXDLMSConverter c = new GXDLMSConverter(Standard);
                 foreach (var it in cols)
                 {
                     c.UpdateOBISCodeInformation(it.Key);
                 }
                 item.CaptureObjects.AddRange(cols);
             }
             if (cols == null || cols.Count == 0)
             {
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        /// <summary>
        /// Import server settings and COSEM objects from GXDLMSDirector trace.
        /// </summary>
        /// <param name="server">Server where settings are updated.</param>
        /// <param name="data">GXDLMSDirector trace in byte array.</param>
        public static void Import(GXDLMSServer server, byte[] data, Standard standard)
        {
            GXDLMSTranslator translator = new GXDLMSTranslator(TranslatorOutputType.StandardXml);

            translator.CompletePdu      = true;
            translator.PduOnly          = true;
            translator.OmitXmlNameSpace = translator.OmitXmlDeclaration = true;
            XmlDocument           doc      = new XmlDocument();
            List <ValueEventArgs> targets  = new List <ValueEventArgs>();
            GXDLMSSettings        settings = new GXDLMSSettings(true, InterfaceType.HDLC);
            GXByteBuffer          pdu      = new GXByteBuffer();
            GXByteBuffer          bb       = new GXByteBuffer(data);

            server.InterfaceType = GXDLMSTranslator.GetDlmsFraming(bb);
            bool            lastBlock = true;
            GXByteBuffer    val       = new DLMS.GXByteBuffer();
            GXDLMSConverter converter = new GXDLMSConverter(standard);

            while (translator.FindNextFrame(bb, pdu, server.InterfaceType))
            {
                String xml = translator.MessageToXml(bb);
                if (xml != "")
                {
                    doc.LoadXml(xml.Replace("&", "&amp;"));
                    foreach (XmlNode node in doc.ChildNodes[doc.ChildNodes.Count - 1].ChildNodes)
                    {
                        string name = doc.ChildNodes[doc.ChildNodes.Count - 1].Name;
                        if (name == "Ua" || name == "aarq" || name == "aare")
                        {
                            break;
                        }
                        else if (name == "get-request")
                        {
                            server.UseLogicalNameReferencing = true;
                            GetLN(settings.Objects, targets, node.ChildNodes);
                        }
                        else if (name == "readRequest")
                        {
                            List <short> items = GetSN(node.ChildNodes);

                            server.UseLogicalNameReferencing = false;
                            foreach (short it in items)
                            {
                                GXSNInfo i = GXDLMSSNCommandHandler.FindSNObject(settings.Objects, Convert.ToUInt16((it) & 0xFFFF));
                                targets.Add(new ValueEventArgs(i.Item, i.Index, 0, null));
                            }
                        }
                        else if (name == "readResponse" ||
                                 name == "get-response")
                        {
                            if (targets != null)
                            {
                                List <string> items;
                                if (server.UseLogicalNameReferencing)
                                {
                                    items = GetLNValues(doc.ChildNodes[doc.ChildNodes.Count - 1].ChildNodes);
                                }
                                else
                                {
                                    items = GetSNValues(doc.ChildNodes[doc.ChildNodes.Count - 1].ChildNodes);
                                }

                                int pos = 0;
                                foreach (string it in items)
                                {
                                    if ("other-reason".Equals(it) ||
                                        "read-write-denied".Equals(it) ||
                                        "scope-of-access-violated".Equals(it) ||
                                        "object-unavailable".Equals(it) ||
                                        "object-class-inconsistent".Equals(it))
                                    {
                                        ValueEventArgs ve = targets[pos];
                                        ve.Target.SetAccess(ve.Index, AccessMode.NoAccess);
                                        continue;
                                    }
                                    try
                                    {
                                        if (server.UseLogicalNameReferencing)
                                        {
                                            lastBlock = IsLastBlock(doc.ChildNodes[doc.ChildNodes.Count - 1].ChildNodes);
                                        }
                                        val.Set(translator.XmlToData(it));
                                        if (lastBlock)
                                        {
                                            if (settings.Objects.Count == 0)
                                            {
                                                GXDLMSClient c = new GXDLMSClient();
                                                c.UseLogicalNameReferencing = server.UseLogicalNameReferencing;
                                                settings.Objects            = c.ParseObjects(val, true);
                                                //Update OBIS code description.
                                                converter.UpdateOBISCodeInformation(settings.Objects);
                                            }
                                            else if (targets.Count != 0)
                                            {
                                                ValueEventArgs ve   = targets[pos];
                                                GXDataInfo     info = new GXDataInfo();
                                                ve.Value = GXCommon.GetData(server.Settings, val, info);
                                                if (ve.Value is byte[] && ve.Target != null)
                                                {
                                                    DataType tp = ve.Target.GetUIDataType(ve.Index);
                                                    if (tp != DataType.None)
                                                    {
                                                        ve.Value = GXDLMSClient.ChangeType((byte[])ve.Value, tp, false);
                                                        ve.Target.SetDataType(ve.Index, DataType.OctetString);
                                                    }
                                                }
                                                if (ve.Target is IGXDLMSBase)
                                                {
                                                    ((IGXDLMSBase)ve.Target).SetValue(settings, ve);
                                                }
                                            }
                                            val.Clear();
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        ValueEventArgs ve = targets[pos];
                                        ve.Target.SetAccess(ve.Index, AccessMode.NoAccess);
                                    }
                                    ++pos;
                                }
                                if (lastBlock)
                                {
                                    targets.Clear();
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            server.Items.Clear();
            server.Items.AddRange(settings.Objects);
        }
Esempio n. 20
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                LogicalName = GXCommon.ToLogicalName(e.Value);
            }
            else if (e.Index == 2)
            {
                Scripts.Clear();
                //Fix Xemex bug here.
                //Xemex meters do not return array as they shoul be according standard.
                if (e.Value is object[] && ((object[])e.Value).Length != 0)
                {
                    if (((object[])e.Value)[0] is object[])
                    {
                        foreach (object[] item in (object[])e.Value)
                        {
                            GXDLMSScript script = new GXDLMSScript();
                            script.Id = Convert.ToInt32(item[0]);
                            Scripts.Add(script);
                            foreach (object[] arr in (object[])item[1])
                            {
                                GXDLMSScriptAction it = new GXDLMSScriptAction();
                                it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                                ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                                string     ln = GXCommon.ToLogicalName(arr[2]);
                                it.Target = settings.Objects.FindByLN(ot, ln);
                                if (it.Target == null)
                                {
#pragma warning disable CS0618
                                    it.ObjectType  = ot;
                                    it.LogicalName = ln;
#pragma warning restore CS0618
                                }

                                it.Index     = Convert.ToInt32(arr[3]);
                                it.Parameter = arr[4];
                                if (it.Parameter != null)
                                {
                                    it.ParameterDataType = GXDLMSConverter.GetDLMSDataType(it.Parameter.GetType());
                                }
                                script.Actions.Add(it);
                            }
                        }
                    }
                    else //Read Xemex meter here.
                    {
                        GXDLMSScript script = new GXDLMSScript();
                        script.Id = Convert.ToInt32(((object[])e.Value)[0]);
                        Scripts.Add(script);
                        object[]           arr = (object[])((object[])e.Value)[1];
                        GXDLMSScriptAction it  = new GXDLMSScriptAction();
                        it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                        ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                        string     ln = GXCommon.ToLogicalName(arr[2]);
                        it.Target = settings.Objects.FindByLN(ot, ln);
                        if (it.Target == null)
                        {
#pragma warning disable CS0618
                            it.ObjectType  = ot;
                            it.LogicalName = ln;
#pragma warning restore CS0618
                        }

                        it.Index     = Convert.ToInt32(arr[3]);
                        it.Parameter = arr[4];
                        script.Actions.Add(it);
                    }
                }
            }
            else
            {
                e.Error = ErrorCode.ReadWriteDenied;
            }
        }
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                return(GXCommon.LogicalNameToBytes(LogicalName));

            case 2:
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Structure);
                data.SetUInt8(4);
                if (ChangedParameter == null)
                {
                    GXCommon.SetData(settings, data, DataType.UInt16, 0);
                    GXCommon.SetData(settings, data, DataType.OctetString, new byte[] { 0, 0, 0, 0, 0, 0 });
                    GXCommon.SetData(settings, data, DataType.Int8, 1);
                    GXCommon.SetData(settings, data, DataType.None, null);
                }
                else
                {
                    GXCommon.SetData(settings, data, DataType.UInt16, ChangedParameter.Target.ObjectType);
                    GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(ChangedParameter.Target.LogicalName));
                    GXCommon.SetData(settings, data, DataType.Int8, ChangedParameter.AttributeIndex);
                    GXCommon.SetData(settings, data, GXDLMSConverter.GetDLMSDataType(ChangedParameter.Value), ChangedParameter.Value);
                }
                return(data.Array());
            }

            case 3:
                return(CaptureTime);

            case 4:
            {
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                if (Parameters == null)
                {
                    data.SetUInt8(0);
                }
                else
                {
                    data.SetUInt8((byte)Parameters.Count);
                    foreach (GXDLMSTarget it in Parameters)
                    {
                        data.SetUInt8((byte)DataType.Structure);
                        data.SetUInt8((byte)3);
                        GXCommon.SetData(settings, data, DataType.UInt16, it.Target.ObjectType);
                        GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(it.Target.LogicalName));
                        GXCommon.SetData(settings, data, DataType.Int8, it.AttributeIndex);
                    }
                }
                return(data.Array());
            }

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                break;
            }
            return(null);
        }
        /// <summary>
        /// Returns buffer data.
        /// </summary>
        /// <param name="settings">DLMS settings.</param>
        /// <param name="e"></param>
        /// <param name="table"></param>
        /// <param name="columns">Columns to get. NULL if not used.</param>
        /// <returns></returns>
        byte[] GetData(GXDLMSSettings settings, ValueEventArgs e, List <object[]> table,
                       List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > columns)
        {
            int pos = 0;
            List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > cols = columns;

            if (columns == null)
            {
            }
            GXByteBuffer data = new GXByteBuffer();

            if (settings.Index == 0)
            {
                data.SetUInt8((byte)DataType.Array);
                if (e.RowEndIndex != 0)
                {
                    GXCommon.SetObjectCount((int)(e.RowEndIndex - e.RowBeginIndex), data);
                }
                else
                {
                    GXCommon.SetObjectCount(table.Count, data);
                }
            }
            DataType[] types = new DataType[CaptureObjects.Count];
            foreach (GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> it in CaptureObjects)
            {
                types[pos] = it.Key.GetDataType(it.Value.AttributeIndex);
                ++pos;
            }

            foreach (object[] items in table)
            {
                data.SetUInt8((byte)DataType.Structure);
                if (columns == null || columns.Count == 0)
                {
                    GXCommon.SetObjectCount(items.Length, data);
                }
                else
                {
                    GXCommon.SetObjectCount(columns.Count, data);
                }
                pos = 0;
                DataType tp;
                foreach (object value in items)
                {
                    if (columns == null || columns.Contains(CaptureObjects[pos]))
                    {
                        tp = types[pos];
                        if (tp == DataType.None)
                        {
                            tp         = GXDLMSConverter.GetDLMSDataType(value);
                            types[pos] = tp;
                        }
                        if (value == null)
                        {
                            tp = DataType.None;
                        }
                        GXCommon.SetData(settings, data, tp, value);
                    }
                    ++pos;
                }
                ++settings.Index;
            }
            if (e.RowEndIndex != 0)
            {
                e.RowBeginIndex += (UInt32)table.Count;
            }
            else
            {
                settings.Index = 0;
            }
            return(data.Array());
        }
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                LogicalName = GXCommon.ToLogicalName(e.Value);
            }
            else if (e.Index == 2)
            {
                Scripts.Clear();
                //Fix Xemex bug here.
                //Xemex meters do not return array as they shoul be according standard.
                if (e.Value is IEnumerable <object> )
                {
                    List <object> arr, arr1, arr2;
                    if (e.Value is List <object> )
                    {
                        arr1 = (List <object>)e.Value;
                    }
                    else
                    {
                        arr1 = new List <object>((object[])e.Value);
                    }
                    if (arr1[0] is IEnumerable <object> )
                    {
                        foreach (object tmp in (IEnumerable <object>)e.Value)
                        {
                            List <object> item;
                            if (tmp is List <object> )
                            {
                                item = (List <object>)tmp;
                            }
                            else
                            {
                                item = new List <object>((object[])tmp);
                            }
                            GXDLMSScript script = new GXDLMSScript();
                            script.Id = Convert.ToInt32(item[0]);
                            Scripts.Add(script);
                            if (item[1] is List <object> )
                            {
                                arr2 = (List <object>)item[1];
                            }
                            else
                            {
                                arr2 = new List <object>((object[])item[1]);
                            }
                            foreach (object tmp2 in arr2)
                            {
                                if (tmp2 is List <object> )
                                {
                                    arr = (List <object>)tmp2;
                                }
                                else
                                {
                                    arr = new List <object>((object[])tmp2);
                                }
                                GXDLMSScriptAction it = new GXDLMSScriptAction();
                                it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                                ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                                String     ln = GXCommon.ToLogicalName(arr[2]);
                                it.Target = settings.Objects.FindByLN(ot, ln);
                                if (it.Target == null)
                                {
#pragma warning disable CS0618
                                    it.ObjectType  = ot;
                                    it.LogicalName = ln;
#pragma warning restore CS0618
                                }

                                it.Index     = Convert.ToInt32(arr[3]);
                                it.Parameter = arr[4];
                                if (it.Parameter != null)
                                {
                                    it.ParameterDataType = GXDLMSConverter.GetDLMSDataType(it.Parameter);
                                }
                                script.Actions.Add(it);
                            }
                        }
                    }
                    else //Read Xemex meter here.
                    {
                        GXDLMSScript script = new GXDLMSScript();
                        if (e.Value is List <object> )
                        {
                            arr1 = (List <object>)e.Value;
                        }
                        else
                        {
                            arr1 = new List <object>((object[])e.Value);
                        }

                        script.Id = Convert.ToInt32(arr1[0]);
                        Scripts.Add(script);
                        if (arr1[1] is List <object> )
                        {
                            arr = (List <object>)arr1[1];
                        }
                        else
                        {
                            arr = new List <object>((object[])arr1[1]);
                        }
                        GXDLMSScriptAction it = new GXDLMSScriptAction();
                        it.Type = (ScriptActionType)Convert.ToInt32(arr[0]);
                        ObjectType ot = (ObjectType)Convert.ToInt32(arr[1]);
                        String     ln = GXCommon.ToLogicalName(arr[2]);
                        it.Target = settings.Objects.FindByLN(ot, ln);
                        if (it.Target == null)
                        {
#pragma warning disable CS0618
                            it.ObjectType  = ot;
                            it.LogicalName = ln;
#pragma warning restore CS0618
                        }

                        it.Index     = Convert.ToInt32(arr[3]);
                        it.Parameter = arr[4];
                        script.Actions.Add(it);
                    }
                }
            }
            else
            {
                e.Error = ErrorCode.ReadWriteDenied;
            }
        }
        private static void SetCaptureObjects(GXDLMSSettings settings, List <GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject> > list, IEnumerable <object> array)
        {
            GXDLMSConverter c = null;

            list.Clear();
            try
            {
                if (array != null)
                {
                    foreach (object tmp in array)
                    {
                        List <object> it;
                        if (tmp is List <object> )
                        {
                            it = (List <object>)tmp;
                        }
                        else
                        {
                            it = new List <object>((object[])tmp);
                        }
                        if (it.Count != 4)
                        {
                            throw new GXDLMSException("Invalid structure format.");
                        }
                        int v = Convert.ToInt16(it[0]);
                        if (Enum.GetName(typeof(ObjectType), v) == null)
                        {
                            list.Clear();
                            return;
                        }
                        ObjectType type           = (ObjectType)v;
                        string     ln             = GXCommon.ToLogicalName((byte[])it[1]);
                        int        attributeIndex = Convert.ToInt16(it[2]);
                        //If profile generic selective access is used.
                        if (attributeIndex < 0)
                        {
                            attributeIndex = 2;
                        }
                        int          dataIndex = Convert.ToInt16(it[3]);
                        GXDLMSObject obj       = null;
                        if (settings != null && settings.Objects != null)
                        {
                            obj = settings.Objects.FindByLN(type, ln);
                        }
                        if (obj == null)
                        {
                            obj = GXDLMSClient.CreateDLMSObject((int)type, null, 0, ln, 0);
                            if (c == null)
                            {
                                c = new GXDLMSConverter();
                            }
                            c.UpdateOBISCodeInformation(obj);
                        }
                        list.Add(new GXKeyValuePair <GXDLMSObject, GXDLMSCaptureObject>(obj, new GXDLMSCaptureObject(attributeIndex, dataIndex)));
                    }
                }
            }
            catch (Exception ex)
            {
                list.Clear();
                throw ex;
            }
        }