コード例 #1
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());
                    }
                    else if (value is byte[])
                    {
                        writer.WriteString(GXDLMSTranslator.ToHex((byte[])value));
                    }
                    else
                    {
                        writer.WriteString(Convert.ToString(value));
                    }
                }
                writer.WriteEndElement();
            }
        }
コード例 #2
0
        public void MethodRequest(GXDLMSObject target, int methodIndex, object data, string text, GXReplyData reply)
        {
            byte[][] tmp;
            if (data is byte[])
            {
                tmp = client.Method(target, methodIndex, data, DataType.Array);
            }
            else
            {
                tmp = client.Method(target, methodIndex, data, GXDLMSConverter.GetDLMSDataType(data));
            }
            int    pos = 0;
            string str = string.Format("Method object {0}, interface {1}", target.LogicalName, target.ObjectType);

            foreach (byte[] it in tmp)
            {
                reply.Clear();
                if (tmp.Length != 1)
                {
                    ++pos;
                    NotifyProgress(text, pos, tmp.Length);
                }
                ReadDataBlock(it, str, reply);
            }
            NotifyProgress(text, 1, 1);
        }
コード例 #3
0
        object IGXDLMSBase.GetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            if (e.Index == 1)
            {
                return(GXCommon.LogicalNameToBytes(LogicalName));
            }
            if (e.Index == 2)
            {
                int          cnt  = Scripts.Count;
                GXByteBuffer data = new GXByteBuffer();
                data.SetUInt8((byte)DataType.Array);
                //Add count
                GXCommon.SetObjectCount(cnt, data);
                foreach (GXDLMSScript it in Scripts)
                {
                    data.SetUInt8((byte)DataType.Structure);
                    data.SetUInt8(2);                                         //Count
                    GXCommon.SetData(settings, data, DataType.UInt16, it.Id); //Script_identifier:
                    data.SetUInt8((byte)DataType.Array);
                    data.SetUInt8((byte)it.Actions.Count);                    //Count
                    foreach (GXDLMSScriptAction a in it.Actions)
                    {
                        data.SetUInt8((byte)DataType.Structure);
                        //Count
                        data.SetUInt8(5);
                        //service_id
                        GXCommon.SetData(settings, data, DataType.Enum, a.Type);
                        if (a.Target == null)
                        {
#pragma warning disable CS0618
                            //class_id
                            GXCommon.SetData(settings, data, DataType.UInt16, a.ObjectType);
                            //logical_name
                            GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(a.LogicalName));
#pragma warning restore CS0618
                        }
                        else
                        {
                            //class_id
                            GXCommon.SetData(settings, data, DataType.UInt16, a.Target.ObjectType);
                            //logical_name
                            GXCommon.SetData(settings, data, DataType.OctetString, GXCommon.LogicalNameToBytes(a.Target.LogicalName));
                        }
                        //index
                        GXCommon.SetData(settings, data, DataType.Int8, a.Index);
                        //parameter
                        DataType tp = a.ParameterDataType;
                        if (tp == DataType.None)
                        {
                            tp = GXDLMSConverter.GetDLMSDataType(a.Parameter);
                        }
                        GXCommon.SetData(settings, data, tp, a.Parameter);
                    }
                }
                return(data.Array());
            }
            e.Error = ErrorCode.ReadWriteDenied;
            return(null);
        }
コード例 #4
0
 public void WriteElementObject(string name, object value)
 {
     if (value != null || !skipDefaults)
     {
         DataType dt = GXDLMSConverter.GetDLMSDataType(value);
         WriteElementObject(name, value, dt, DataType.None);
     }
 }
コード例 #5
0
 public void WriteElementObject(string name, object value, int index)
 {
     if (value != null || !IgnoreDefaultValues)
     {
         DataType dt = GXDLMSConverter.GetDLMSDataType(value);
         WriteElementObject(name, value, dt, DataType.None, index);
     }
 }
コード例 #6
0
 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;
 }
コード例 #7
0
 public void MethodRequest(GXDLMSObject target, int methodIndex, object data, GXReplyData reply)
 {
     lastTransaction = DateTime.Now;
     byte[][] tmp;
     if (data is byte[])
     {
         tmp = client.Method(target, methodIndex, data, DataType.Array);
     }
     else
     {
         tmp = client.Method(target, methodIndex, data, GXDLMSConverter.GetDLMSDataType(data));
     }
     ReadDataBlock(tmp, "", reply);
 }
コード例 #8
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);
     }
 }
コード例 #9
0
        /// <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));
        }
コード例 #10
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);
 }
コード例 #11
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);
 }
コード例 #12
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);
 }
コード例 #13
0
        /// <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());
        }
コード例 #14
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;
            }
        }
コード例 #15
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 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;
            }
        }
コード例 #16
0
        /// <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());
        }