/// <summary>
 /// Constructor.
 /// </summary>
 public GXDLMSRegisterMonitor()
     : base(ObjectType.RegisterMonitor)
 {
     this.Thresholds = new object[0];
     MonitoredValue  = new GXDLMSMonitoredValue();
     Actions         = new GXDLMSActionSet[0];
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="ln">Logical Name of the object.</param>
 /// <param name="sn">Short Name of the object.</param>
 public GXDLMSRegisterMonitor(string ln, ushort sn)
     : base(ObjectType.RegisterMonitor, ln, sn)
 {
     this.Thresholds = new object[0];
     MonitoredValue  = new GXDLMSMonitoredValue();
     Actions         = new GXDLMSActionSet[0];
 }
 /// <summary> 
 /// Constructor.
 /// </summary> 
 /// <param name="ln">Logican Name of the object.</param>
 /// <param name="sn">Short Name of the object.</param>
 public GXDLMSRegisterMonitor(string ln, ushort sn)
     : base(ObjectType.RegisterMonitor, ln, 0)
 {
     this.Thresholds = new object[0];
     MonitoredValue = new GXDLMSMonitoredValue();
     Actions = new GXDLMSActionSet[0];
 }
 /// <summary> 
 /// Constructor.
 /// </summary> 
 public GXDLMSRegisterMonitor()
     : base(ObjectType.RegisterMonitor)
 {
     this.Thresholds = new object[0];            
     MonitoredValue = new GXDLMSMonitoredValue();
     Actions = new GXDLMSActionSet[0];
 }
        void IGXDLMSBase.Load(GXXmlReader reader)
        {
            List <object> thresholds = new List <object>();

            if (reader.IsStartElement("Thresholds", true))
            {
                while (reader.IsStartElement("Value", false))
                {
                    object it = reader.ReadElementContentAsObject("Value", null);
                    thresholds.Add(it);
                }
                reader.ReadEndElement("Thresholds");
            }
            Thresholds = thresholds.ToArray();
            if (reader.IsStartElement("MonitoredValue", true))
            {
                MonitoredValue.ObjectType     = (ObjectType)reader.ReadElementContentAsInt("ObjectType");
                MonitoredValue.LogicalName    = reader.ReadElementContentAsString("LN");
                MonitoredValue.AttributeIndex = reader.ReadElementContentAsInt("Index");
                reader.ReadEndElement("MonitoredValue");
            }

            List <GXDLMSActionSet> list = new List <GXDLMSActionSet>();

            if (reader.IsStartElement("Actions", true))
            {
                while (reader.IsStartElement("Item", true))
                {
                    GXDLMSActionSet it = new GXDLMSActionSet();
                    list.Add(it);
                    if (reader.IsStartElement("Up", true))
                    {
                        it.ActionUp.LogicalName = reader.ReadElementContentAsString("LN", null);
                        if (it.ActionUp.LogicalName == "")
                        {
                            it.ActionUp.LogicalName = "0.0.0.0.0.0";
                        }
                        it.ActionUp.ScriptSelector = (UInt16)reader.ReadElementContentAsInt("Selector");
                        reader.ReadEndElement("Up");
                    }
                    if (reader.IsStartElement("Down", true))
                    {
                        it.ActionDown.LogicalName = reader.ReadElementContentAsString("LN", null);
                        if (it.ActionDown.LogicalName == "")
                        {
                            it.ActionDown.LogicalName = "0.0.0.0.0.0";
                        }
                        it.ActionDown.ScriptSelector = (UInt16)reader.ReadElementContentAsInt("Selector");
                        reader.ReadEndElement("Down");
                    }
                }
                reader.ReadEndElement("Actions");
            }
            Actions = list.ToArray();
        }
Esempio n. 6
0
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {
         Thresholds = (object[])value;
     }
     else if (index == 3)
     {
         if (MonitoredValue == null)
         {
             MonitoredValue = new GXDLMSMonitoredValue();
         }
         MonitoredValue.ObjectType     = (ObjectType)Convert.ToInt32(((object[])value)[0]);
         MonitoredValue.LogicalName    = GXDLMSClient.ChangeType((byte[])((object[])value)[1], DataType.OctetString).ToString();
         MonitoredValue.AttributeIndex = Convert.ToInt32(((object[])value)[2]);
     }
     else if (index == 4)
     {
         Actions = null;
         if (value != null)
         {
             List <GXDLMSActionSet> items = new List <GXDLMSActionSet>();
             foreach (Object[] action_set in (Object[])value)
             {
                 GXDLMSActionSet set = new GXDLMSActionSet();
                 set.ActionUp.LogicalName      = GXDLMSClient.ChangeType((byte[])((Object[])action_set[0])[0], DataType.OctetString).ToString();
                 set.ActionUp.ScriptSelector   = Convert.ToUInt16(((Object[])action_set[0])[1]);
                 set.ActionDown.LogicalName    = GXDLMSClient.ChangeType((byte[])((Object[])action_set[1])[0], DataType.OctetString).ToString();
                 set.ActionDown.ScriptSelector = Convert.ToUInt16(((Object[])action_set[1])[1]);
                 items.Add(set);
             }
             Actions = items.ToArray();
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Esempio n. 7
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString, settings.UseUtc2NormalTime).ToString();
         }
     }
     else if (e.Index == 2)
     {
         Thresholds = (object[])e.Value;
     }
     else if (e.Index == 3)
     {
         if (MonitoredValue == null)
         {
             MonitoredValue = new GXDLMSMonitoredValue();
         }
         MonitoredValue.ObjectType     = (ObjectType)Convert.ToInt32(((object[])e.Value)[0]);
         MonitoredValue.LogicalName    = GXDLMSClient.ChangeType((byte[])((object[])e.Value)[1], DataType.OctetString, settings.UseUtc2NormalTime).ToString();
         MonitoredValue.AttributeIndex = Convert.ToInt32(((object[])e.Value)[2]);
     }
     else if (e.Index == 4)
     {
         Actions = null;
         if (e.Value != null)
         {
             List <GXDLMSActionSet> items = new List <GXDLMSActionSet>();
             foreach (Object[] action_set in (Object[])e.Value)
             {
                 GXDLMSActionSet set = new GXDLMSActionSet();
                 set.ActionUp.LogicalName      = GXDLMSClient.ChangeType((byte[])((Object[])action_set[0])[0], DataType.OctetString, settings.UseUtc2NormalTime).ToString();
                 set.ActionUp.ScriptSelector   = Convert.ToUInt16(((Object[])action_set[0])[1]);
                 set.ActionDown.LogicalName    = GXDLMSClient.ChangeType((byte[])((Object[])action_set[1])[0], DataType.OctetString, settings.UseUtc2NormalTime).ToString();
                 set.ActionDown.ScriptSelector = Convert.ToUInt16(((Object[])action_set[1])[1]);
                 items.Add(set);
             }
             Actions = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         Thresholds = (object[])e.Value;
     }
     else if (e.Index == 3)
     {
         if (MonitoredValue == null)
         {
             MonitoredValue = new GXDLMSMonitoredValue();
         }
         MonitoredValue.ObjectType     = (ObjectType)Convert.ToInt32(((object[])e.Value)[0]);
         MonitoredValue.LogicalName    = GXCommon.ToLogicalName(((object[])e.Value)[1]);
         MonitoredValue.AttributeIndex = Convert.ToInt32(((object[])e.Value)[2]);
     }
     else if (e.Index == 4)
     {
         Actions = null;
         if (e.Value != null)
         {
             List <GXDLMSActionSet> items = new List <GXDLMSActionSet>();
             foreach (object[] action_set in (object[])e.Value)
             {
                 GXDLMSActionSet set = new GXDLMSActionSet();
                 set.ActionUp.LogicalName      = GXCommon.ToLogicalName(((object[])action_set[0])[0]);
                 set.ActionUp.ScriptSelector   = Convert.ToUInt16(((object[])action_set[0])[1]);
                 set.ActionDown.LogicalName    = GXCommon.ToLogicalName(((object[])action_set[1])[0]);
                 set.ActionDown.ScriptSelector = Convert.ToUInt16(((object[])action_set[1])[1]);
                 items.Add(set);
             }
             Actions = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
 void IGXDLMSBase.SetValue(int index, object value)
 {
     if (index == 1)
     {
         if (value is string)
         {
             LogicalName = value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])value, DataType.OctetString).ToString();
         }
     }
     else if (index == 2)
     {                
         Thresholds = (object[]) value;
     }
     else if (index == 3)
     {
         if (MonitoredValue == null)
         {
             MonitoredValue = new GXDLMSMonitoredValue();
         }
         MonitoredValue.ObjectType = (ObjectType)Convert.ToInt32(((object[])value)[0]);
         MonitoredValue.LogicalName = GXDLMSClient.ChangeType((byte[])((object[])value)[1], DataType.OctetString).ToString();
         MonitoredValue.AttributeIndex = Convert.ToInt32(((object[])value)[2]);
     }
     else if (index == 4)
     {
         Actions = null;
         if (value != null)
         {
             List<GXDLMSActionSet> items = new List<GXDLMSActionSet>();
             foreach (Object[] action_set in (Object[])value)
             {
                 GXDLMSActionSet set = new GXDLMSActionSet();                        
                 set.ActionUp.LogicalName = GXDLMSClient.ChangeType((byte[])((Object[])action_set[0])[0], DataType.OctetString).ToString();
                 set.ActionUp.ScriptSelector = Convert.ToUInt16(((Object[])action_set[0])[1]);
                 set.ActionDown.LogicalName = GXDLMSClient.ChangeType((byte[])((Object[])action_set[1])[0], DataType.OctetString).ToString();
                 set.ActionDown.ScriptSelector = Convert.ToUInt16(((Object[])action_set[1])[1]);
                 items.Add(set);
             }
             Actions = items.ToArray();
         }
     }
     else
     {
         throw new ArgumentException("SetValue failed. Invalid attribute index.");
     }
 }
Esempio n. 10
0
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         if (e.Value != null)
         {
             List <object> arr;
             if (e.Value is List <object> )
             {
                 arr = (List <object>)e.Value;
             }
             else
             {
                 arr = new List <object>((object[])e.Value);
             }
             Thresholds = arr.ToArray();
         }
         else
         {
             Thresholds = new object[0];
         }
     }
     else if (e.Index == 3)
     {
         if (MonitoredValue == null)
         {
             MonitoredValue = new GXDLMSMonitoredValue();
         }
         if (e.Value != null)
         {
             List <object> arr;
             if (e.Value is List <object> )
             {
                 arr = (List <object>)e.Value;
             }
             else
             {
                 arr = new List <object>((object[])e.Value);
             }
             MonitoredValue.ObjectType     = (ObjectType)Convert.ToInt32(arr[0]);
             MonitoredValue.LogicalName    = GXCommon.ToLogicalName(arr[1]);
             MonitoredValue.AttributeIndex = Convert.ToInt32(arr[2]);
         }
         else
         {
             MonitoredValue.ObjectType     = ObjectType.None;
             MonitoredValue.LogicalName    = "";
             MonitoredValue.AttributeIndex = 0;
         }
     }
     else if (e.Index == 4)
     {
         Actions = null;
         if (e.Value != null)
         {
             List <GXDLMSActionSet> items = new List <GXDLMSActionSet>();
             List <object>          arr, action_set, it;
             if (e.Value is List <object> )
             {
                 arr = (List <object>)e.Value;
             }
             else
             {
                 arr = new List <object>((object[])e.Value);
             }
             foreach (object tmp in arr)
             {
                 if (tmp is List <object> )
                 {
                     action_set = (List <object>)tmp;
                 }
                 else
                 {
                     action_set = new List <object>((object[])tmp);
                 }
                 if (action_set[0] is List <object> )
                 {
                     it = (List <object>)action_set[0];
                 }
                 else
                 {
                     it = new List <object>((object[])action_set[0]);
                 }
                 GXDLMSActionSet set = new GXDLMSActionSet();
                 set.ActionUp.LogicalName    = GXCommon.ToLogicalName(it[0]);
                 set.ActionUp.ScriptSelector = Convert.ToUInt16(it[1]);
                 if (action_set[1] is List <object> )
                 {
                     it = (List <object>)action_set[1];
                 }
                 else
                 {
                     it = new List <object>((object[])action_set[1]);
                 }
                 set.ActionDown.LogicalName    = GXCommon.ToLogicalName(it[0]);
                 set.ActionDown.ScriptSelector = Convert.ToUInt16(it[1]);
                 items.Add(set);
             }
             Actions = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
Esempio n. 11
0
    void Init()
    {
        Media.OnReceived += new Gurux.Common.ReceivedEventHandler(OnReceived);
        Media.OnClientConnected += new Gurux.Common.ClientConnectedEventHandler(OnClientConnected);
        Media.OnClientDisconnected += new Gurux.Common.ClientDisconnectedEventHandler(OnClientDisconnected);
        Media.OnError += new Gurux.Common.ErrorEventHandler(OnError);
        Media.Open();
        ///////////////////////////////////////////////////////////////////////
        //Add Logical Device Name. 123456 is meter serial number.
        GXDLMSData ldn = new GXDLMSData("0.0.42.0.0.255");
        ldn.Value = "Gurux123456";
        //Set access right. Client can't change Device name.
        ldn.SetAccess(2, AccessMode.Read);
        //Value is get as Octet String.
        ldn.SetDataType(2, DataType.OctetString);
        ldn.SetUIDataType(2, DataType.String);
        Items.Add(ldn);

        //Add firmware version.
        GXDLMSData fw = new GXDLMSData("1.0.0.2.0.255");
        fw.Value = "Gurux FW 0.0.1";
        Items.Add(fw);

        //Add Last average.
        GXDLMSRegister r = new GXDLMSRegister("1.1.21.25.0.255");
        //Set access right. Client can't change average value.
        r.SetAccess(2, AccessMode.Read);
        Items.Add(r);
        //Add default clock. Clock's Logical Name is 0.0.1.0.0.255.
        GXDLMSClock clock = new GXDLMSClock();
        clock.Begin = new GXDateTime(-1, 9, 1, -1, -1, -1, -1);
        clock.End = new GXDateTime(-1, 3, 1, -1, -1, -1, -1);
        clock.Deviation = 0;
        Items.Add(clock);
        //Add Tcp Udp setup. Default Logical Name is 0.0.25.0.0.255.
        GXDLMSTcpUdpSetup tcp = new GXDLMSTcpUdpSetup();
        Items.Add(tcp);
        ///////////////////////////////////////////////////////////////////////
        //Add Load profile.
        GXDLMSProfileGeneric pg = new GXDLMSProfileGeneric("1.0.99.1.0.255");
        //Set capture period to 60 second.
        pg.CapturePeriod = 60;
        //Maximum row count.
        pg.ProfileEntries = 100;
        pg.SortMethod = SortMethod.FiFo;
        pg.SortObject = clock;
        //Add columns.
        //Set saved attribute index.
        pg.CaptureObjects.Add(new GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(clock, new GXDLMSCaptureObject(2, 0)));
        //Set saved attribute index.
        pg.CaptureObjects.Add(new GXKeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(r, new GXDLMSCaptureObject(2, 0)));
        Items.Add(pg);
        //Add initial rows.
        pg.Buffer.Add(new object[] { DateTime.Now, (int)10 });
        ///////////////////////////////////////////////////////////////////////
        //Add Auto connect object.
        GXDLMSAutoConnect ac = new GXDLMSAutoConnect();
        ac.Mode = AutoConnectMode.AutoDiallingAllowedAnytime;
        ac.Repetitions = 10;
        ac.RepetitionDelay = 60;
        //Calling is allowed between 1am to 6am.
        ac.CallingWindow.Add(new KeyValuePair<GXDateTime, GXDateTime>(new GXDateTime(-1, -1, -1, 1, 0, 0, -1), new GXDateTime(-1, -1, -1, 6, 0, 0, -1)));
        ac.Destinations = new string[] { "www.gurux.org" };
        Items.Add(ac);
        ///////////////////////////////////////////////////////////////////////
        //Add Activity Calendar object.
        GXDLMSActivityCalendar activity = new GXDLMSActivityCalendar();
        activity.CalendarNameActive = "Active";
        activity.SeasonProfileActive = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Summer time", new GXDateTime(-1, 3, 31, -1, -1, -1, -1), "") };
        activity.WeekProfileTableActive = new GXDLMSWeekProfile[] { new GXDLMSWeekProfile("Monday", 1, 1, 1, 1, 1, 1, 1) };
        activity.DayProfileTableActive = new GXDLMSDayProfile[] { new GXDLMSDayProfile(1, new GXDLMSDayProfileAction[] { new GXDLMSDayProfileAction(new GXDateTime(DateTime.Now), "test", 1) }) };
        activity.CalendarNamePassive = "Passive";
        activity.SeasonProfilePassive = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Winter time", new GXDateTime(-1, 10, 30, -1, -1, -1, -1), "") };
        activity.WeekProfileTablePassive = new GXDLMSWeekProfile[] { new GXDLMSWeekProfile("Tuesday", 1, 1, 1, 1, 1, 1, 1) };
        activity.DayProfileTablePassive = new GXDLMSDayProfile[] { new GXDLMSDayProfile(1, new GXDLMSDayProfileAction[] { new GXDLMSDayProfileAction(new GXDateTime(DateTime.Now), "0.0.1.0.0.255", 1) }) };
        activity.Time = new GXDateTime(DateTime.Now);
        Items.Add(activity);
        ///////////////////////////////////////////////////////////////////////
        //Add Optical Port Setup object.
        GXDLMSIECOpticalPortSetup optical = new GXDLMSIECOpticalPortSetup();
        optical.DefaultMode = OpticalProtocolMode.Default;
        optical.ProposedBaudrate = BaudRate.Baudrate9600;
        optical.DefaultBaudrate = BaudRate.Baudrate300;
        optical.ResponseTime = LocalPortResponseTime.ms200;
        optical.DeviceAddress = "Gurux";
        optical.Password1 = "Gurux1";
        optical.Password2 = "Gurux2";
        optical.Password5 = "Gurux5";
        Items.Add(optical);
        ///////////////////////////////////////////////////////////////////////
        //Add Demand Register object.
        GXDLMSDemandRegister dr = new GXDLMSDemandRegister();
        dr.LogicalName = "0.0.1.0.0.255";
        dr.CurrentAverageValue = (uint)10;
        dr.LastAverageValue = (uint)20;
        dr.Status = (byte)1;
        dr.StartTimeCurrent = dr.CaptureTime = new GXDateTime(DateTime.Now);
        dr.Period = 10;
        dr.NumberOfPeriods = 1;
        Items.Add(dr);
        ///////////////////////////////////////////////////////////////////////
        //Add Register Monitor object.
        GXDLMSRegisterMonitor rm = new GXDLMSRegisterMonitor();
        rm.LogicalName = "0.0.1.0.0.255";
        rm.Thresholds = new object[] { (int)0x1234, (int)0x5678 };
        GXDLMSActionSet set = new GXDLMSActionSet();
        set.ActionDown.LogicalName = rm.LogicalName;
        set.ActionDown.ScriptSelector = 1;
        set.ActionUp.LogicalName = rm.LogicalName;
        set.ActionUp.ScriptSelector = 2;
        rm.Actions = new GXDLMSActionSet[] {
            set
            };
        rm.MonitoredValue.Update(r, 2);
        Items.Add(rm);
        ///////////////////////////////////////////////////////////////////////
        //Add Activate test mode Script table object.
        GXDLMSScriptTable st = new GXDLMSScriptTable("0.1.10.1.101.255");
        GXDLMSScript s = new GXDLMSScript();
        s.Id = 1;
        GXDLMSScriptAction a = new GXDLMSScriptAction();
        a.Target = null;

        s.Actions.Add(a);
        st.Scripts.Add(s);
        Items.Add(st);
        ///////////////////////////////////////////////////////////////////////
        //Add action schedule object.
        GXDLMSActionSchedule actionS = new GXDLMSActionSchedule();
        actionS.LogicalName = "0.0.1.0.0.255";
        actionS.Target = st;
        actionS.ExecutedScriptSelector = 1;
        actionS.Type = SingleActionScheduleType.SingleActionScheduleType1;
        actionS.ExecutionTime = new GXDateTime[] { new GXDateTime(DateTime.Now) };
        Items.Add(actionS);
        ///////////////////////////////////////////////////////////////////////
        //Add SAP Assignment object.
        GXDLMSSapAssignment sap = new GXDLMSSapAssignment();
        sap.SapAssignmentList.Add(new KeyValuePair<UInt16, string>(1, "Gurux"));
        sap.SapAssignmentList.Add(new KeyValuePair<UInt16, string>(16, "Gurux-2"));
        Items.Add(sap);

        ///////////////////////////////////////////////////////////////////////
        //Add Auto Answer object.
        GXDLMSAutoAnswer aa = new GXDLMSAutoAnswer();
        aa.Mode = AutoAnswerMode.Connected;
        aa.ListeningWindow.Add(new KeyValuePair<GXDateTime, GXDateTime>(new GXDateTime(-1, -1, -1, 6, -1, -1, -1), new GXDateTime(-1, -1, -1, 8, -1, -1, -1)));
        aa.Status = AutoAnswerStatus.Inactive;
        aa.NumberOfCalls = 0;
        aa.NumberOfRingsInListeningWindow = 1;
        aa.NumberOfRingsOutListeningWindow = 2;
        Items.Add(aa);
        ///////////////////////////////////////////////////////////////////////
        //Add Modem Configuration object.
        GXDLMSModemConfiguration mc = new GXDLMSModemConfiguration();
        mc.CommunicationSpeed = BaudRate.Baudrate57600;
        GXDLMSModemInitialisation init = new GXDLMSModemInitialisation();
        init.Request = "AT";
        init.Response = "OK";
        init.Delay = 0;
        mc.InitialisationStrings = new GXDLMSModemInitialisation[] { init };
        Items.Add(mc);

        ///////////////////////////////////////////////////////////////////////
        //Add Mac Address Setup object.
        GXDLMSMacAddressSetup mac = new GXDLMSMacAddressSetup();
        mac.MacAddress = "00:11:22:33:44:55:66";
        Items.Add(mac);

        ///////////////////////////////////////////////////////////////////////
        //Add Image transfer object.
        GXDLMSImageTransfer i = new GXDLMSImageTransfer();
        Items.Add(i);
        ///////////////////////////////////////////////////////////////////////
        //Add IP4 Setup object.
        GXDLMSIp4Setup ip4 = new GXDLMSIp4Setup();
        //Get local IP address.
        var host = Dns.GetHostEntry(Dns.GetHostName());
        foreach (var ip in host.AddressList)
        {
            if (ip.AddressFamily == AddressFamily.InterNetwork)
            {
                ip4.IPAddress = ip.ToString();
            }
        }
        Items.Add(ip4);

        //Add Push Setup. (On Connectivity)
        GXDLMSPushSetup push = new GXDLMSPushSetup("0.0.25.9.0.255");
        //Send Push messages to this address as default.
        push.Destination = ip4.IPAddress + ":7000";
        Items.Add(push);
        //Add push object itself. This is needed to tell structure of data to the Push listener.
        push.PushObjectList.Add(new KeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(push, new GXDLMSCaptureObject(2, 0)));
        //Add logical device name.
        push.PushObjectList.Add(new KeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(ldn, new GXDLMSCaptureObject(2, 0)));
        //Add .0.0.25.1.0.255 Ch. 0 IPv4 setup IP address.
        push.PushObjectList.Add(new KeyValuePair<GXDLMSObject, GXDLMSCaptureObject>(ip4, new GXDLMSCaptureObject(3, 0)));

        //Add  S-FSK objects
        Items.Add(new GXDLMSSFSKPhyMacSetUp());
        Items.Add(new GXDLMSSFSKActiveInitiator());
        Items.Add(new GXDLMSSFSKMacCounters());
        Items.Add(new GXDLMSSFSKMacSynchronizationTimeouts());
        //Add IEC14908 (OSGB) objects.
        Items.Add(new GXDLMSIEC14908Diagnostic());
        Items.Add(new GXDLMSIEC14908Identification());
        Items.Add(new GXDLMSIEC14908PhysicalSetup());
        Items.Add(new GXDLMSIEC14908PhysicalStatus());

        ///////////////////////////////////////////////////////////////////////
        //Server must initialize after all objects are added.
        Initialize();
    }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         if (e.Value is string)
         {
             LogicalName = e.Value.ToString();
         }
         else
         {
             LogicalName = GXDLMSClient.ChangeType((byte[])e.Value, DataType.OctetString).ToString();
         }
     }
     else if (e.Index == 2)
     {
         Thresholds = (object[])e.Value;
     }
     else if (e.Index == 3)
     {
         if (MonitoredValue == null)
         {
             MonitoredValue = new GXDLMSMonitoredValue();
         }
         MonitoredValue.ObjectType = (ObjectType)Convert.ToInt32(((object[])e.Value)[0]);
         MonitoredValue.LogicalName = GXDLMSClient.ChangeType((byte[])((object[])e.Value)[1], DataType.OctetString).ToString();
         MonitoredValue.AttributeIndex = Convert.ToInt32(((object[])e.Value)[2]);
     }
     else if (e.Index == 4)
     {
         Actions = null;
         if (e.Value != null)
         {
             List<GXDLMSActionSet> items = new List<GXDLMSActionSet>();
             foreach (Object[] action_set in (Object[])e.Value)
             {
                 GXDLMSActionSet set = new GXDLMSActionSet();
                 set.ActionUp.LogicalName = GXDLMSClient.ChangeType((byte[])((Object[])action_set[0])[0], DataType.OctetString).ToString();
                 set.ActionUp.ScriptSelector = Convert.ToUInt16(((Object[])action_set[0])[1]);
                 set.ActionDown.LogicalName = GXDLMSClient.ChangeType((byte[])((Object[])action_set[1])[0], DataType.OctetString).ToString();
                 set.ActionDown.ScriptSelector = Convert.ToUInt16(((Object[])action_set[1])[1]);
                 items.Add(set);
             }
             Actions = items.ToArray();
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
        /// <summary>
        /// Generic initialize for all servers.
        /// </summary>
        /// <param name="server"></param>
        public void Initialize(int port)
        {
            Media = new GXNet(NetworkType.Tcp, port);
            Media.OnReceived += new Gurux.Common.ReceivedEventHandler(OnReceived);
            Media.OnClientConnected += new Gurux.Common.ClientConnectedEventHandler(OnClientConnected);
            Media.OnClientDisconnected += new Gurux.Common.ClientDisconnectedEventHandler(OnClientDisconnected);
            Media.OnError += new Gurux.Common.ErrorEventHandler(OnError);
            Media.Open();
            ///////////////////////////////////////////////////////////////////////
            //Add Logical Device Name. 123456 is meter serial number.
            GXDLMSData d = new GXDLMSData("0.0.42.0.0.255");
            d.Value = "Gurux123456";
            //Set access right. Client can't change Device name.
            d.SetAccess(2, AccessMode.Read);
            //Value is get as Octet String.
            d.SetDataType(2, DataType.OctetString);
            Items.Add(d);
            //Add Last avarage.
            GXDLMSRegister r = new GXDLMSRegister("1.1.21.25.0.255");
            //Set access right. Client can't change average value.
            r.SetAccess(2, AccessMode.Read);
            Items.Add(r);
            //Add default clock. Clock's Logical Name is 0.0.1.0.0.255.
            GXDLMSClock clock = new GXDLMSClock();
            clock.Begin = new GXDateTime(-1, 9, 1, -1, -1, -1, -1);
            clock.End = new GXDateTime(-1, 3, 1, -1, -1, -1, -1);
            clock.Deviation = 0;
            Items.Add(clock);
            //Add Tcp Udp setup. Default Logical Name is 0.0.25.0.0.255.
            GXDLMSTcpUdpSetup tcp = new GXDLMSTcpUdpSetup();
            Items.Add(tcp);
            ///////////////////////////////////////////////////////////////////////
            //Add Load profile.
            GXDLMSProfileGeneric pg = new GXDLMSProfileGeneric("1.0.99.1.0.255");
            //Set capture period to 60 second.
            pg.CapturePeriod = 60;
            //Maximum row count.
            pg.ProfileEntries = 100;
            pg.SortMethod = SortMethod.FiFo;
            pg.SortObject = clock;
            //Add colums.
            //Set saved attribute index.
            clock.SelectedAttributeIndex = 2;
            pg.CaptureObjects.Add(clock);
            //Set saved attribute index.
            r.SelectedAttributeIndex = 2;
            pg.CaptureObjects.Add(r);
            Items.Add(pg);
            //Add initial rows.
            pg.Buffer.Add(new object[] { DateTime.Now, (int)10 });
            ///////////////////////////////////////////////////////////////////////
            //Add Auto connect object.
            GXDLMSAutoConnect ac = new GXDLMSAutoConnect();
            ac.Mode = AutoConnectMode.AutoDiallingAllowedAnytime;
            ac.Repetitions = 10;
            ac.RepetitionDelay = 60;
            //Calling is allowed between 1am to 6am.
            ac.CallingWindow.Add(new KeyValuePair<GXDateTime, GXDateTime>(new GXDateTime(-1, -1, -1, 1, 0, 0, -1), new GXDateTime(-1, -1, -1, 6, 0, 0, -1)));
            ac.Destinations = new string[] { "www.gurux.org"};
            Items.Add(ac);

            ///////////////////////////////////////////////////////////////////////
            //Add Activity Calendar object.
            GXDLMSActivityCalendar activity = new GXDLMSActivityCalendar();
            activity.CalendarNameActive = "Active";            
            activity.SeasonProfileActive = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Summer time", new GXDateTime(-1, 3, 31, -1, -1, -1, -1), "")};
            activity.WeekProfileTableActive = new GXDLMSWeekProfile[]{new GXDLMSWeekProfile("Monday", 1, 1, 1, 1, 1, 1, 1)};
            activity.DayProfileTableActive = new GXDLMSDayProfile[]{new GXDLMSDayProfile(1, new GXDLMSDayProfileAction[]{new GXDLMSDayProfileAction(new GXDateTime(DateTime.Now), "test", 1)})};
            activity.CalendarNamePassive = "Passive";
            activity.SeasonProfilePassive = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Winter time", new GXDateTime(-1, 10, 30, -1, -1, -1, -1), "")};
            activity.WeekProfileTablePassive = new GXDLMSWeekProfile[]{new GXDLMSWeekProfile("Tuesday", 1, 1, 1, 1, 1, 1, 1)};
            activity.DayProfileTablePassive = new GXDLMSDayProfile[] { new GXDLMSDayProfile(1, new GXDLMSDayProfileAction[] { new GXDLMSDayProfileAction(new GXDateTime(DateTime.Now), "0.0.1.0.0.255", 1) }) };
            activity.Time = new GXDateTime(DateTime.Now);
            Items.Add(activity);

            ///////////////////////////////////////////////////////////////////////
            //Add Optical Port Setup object.
            GXDLMSIECOpticalPortSetup optical = new GXDLMSIECOpticalPortSetup();
            optical.DefaultMode = OpticalProtocolMode.Default;
            optical.ProposedBaudrate = BaudRate.Baudrate9600;
            optical.DefaultBaudrate = BaudRate.Baudrate300;
            optical.ResponseTime = LocalPortResponseTime.ms200;
            optical.DeviceAddress = "Gurux";
            optical.Password1 = "Gurux1";
            optical.Password2 = "Gurux2";
            optical.Password5 = "Gurux5";
            Items.Add(optical);

            ///////////////////////////////////////////////////////////////////////
            //Add Demand Register object.
            GXDLMSDemandRegister dr = new GXDLMSDemandRegister();
            dr.LogicalName = "0.0.1.0.0.255";
            dr.CurrentAvarageValue = (uint) 10;
            dr.LastAvarageValue = (uint) 20;
            dr.Status = (byte)1;
            dr.StartTimeCurrent = dr.CaptureTime = new GXDateTime(DateTime.Now);
            dr.Period = 10;
            dr.NumberOfPeriods = 1;
            Items.Add(dr);

            ///////////////////////////////////////////////////////////////////////
            //Add Register Monitor object.
            GXDLMSRegisterMonitor rm = new GXDLMSRegisterMonitor();
            rm.LogicalName = "0.0.1.0.0.255";
            rm.Thresholds = new object[] { (int)0x1234, (int)0x5678 };
            GXDLMSActionSet set = new GXDLMSActionSet();
            set.ActionDown.LogicalName = rm.LogicalName;
            set.ActionDown.ScriptSelector = 1;
            set.ActionUp.LogicalName = rm.LogicalName;
            set.ActionUp.ScriptSelector = 2;            
            rm.Actions = new GXDLMSActionSet[] {set };
            rm.MonitoredValue.Update(r, 2);
            Items.Add(rm);
            
            ///////////////////////////////////////////////////////////////////////
            //Add action schedule object.
            GXDLMSActionSchedule actionS = new GXDLMSActionSchedule();
            actionS.LogicalName = "0.0.1.0.0.255";
            actionS.ExecutedScriptLogicalName = "1.2.3.4.5.6";
            actionS.ExecutedScriptSelector = 1;
            actionS.Type = SingleActionScheduleType.SingleActionScheduleType1;
            actionS.ExecutionTime = new GXDateTime[] {new GXDateTime(DateTime.Now) };
            Items.Add(actionS);            

            ///////////////////////////////////////////////////////////////////////
            //Add SAP Assignment object.
            GXDLMSSapAssignment sap = new GXDLMSSapAssignment();
            sap.SapAssignmentList.Add(new KeyValuePair<UInt16, string>(1, "Gurux"));
            sap.SapAssignmentList.Add(new KeyValuePair<UInt16, string>(16, "Gurux-2"));
            Items.Add(sap);

            ///////////////////////////////////////////////////////////////////////
            //Add Auto Answer object.
            GXDLMSAutoAnswer aa = new GXDLMSAutoAnswer();
            aa.Mode = AutoConnectMode.EmailSending;
            aa.ListeningWindow.Add(new KeyValuePair<GXDateTime, GXDateTime>(new GXDateTime(-1, -1, -1, 6, -1, -1, -1), new GXDateTime(-1, -1, -1, 8, -1, -1, -1)));
            aa.Status = AutoAnswerStatus.Inactive;
            aa.NumberOfCalls = 0;
            aa.NumberOfRingsInListeningWindow = 1;
            aa.NumberOfRingsOutListeningWindow = 2;
            Items.Add(aa);

            ///////////////////////////////////////////////////////////////////////
            //Add Modem Configuration object.
            GXDLMSModemConfiguration mc = new GXDLMSModemConfiguration();
            mc.CommunicationSpeed = BaudRate.Baudrate57600;
            GXDLMSModemInitialisation init = new GXDLMSModemInitialisation();
            init.Request = "AT";
            init.Response = "OK";
            init.Delay = 0;
            mc.InitialisationStrings = new GXDLMSModemInitialisation[] { init };
            Items.Add(mc);

            ///////////////////////////////////////////////////////////////////////
            //Add Mac Address Setup object.
            GXDLMSMacAddressSetup mac = new GXDLMSMacAddressSetup();
            mac.MacAddress = "00:11:22:33:44:55:66";
            Items.Add(mac);            
            ///////////////////////////////////////////////////////////////////////
            //Server must initialize after all objects are added.
            Initialize();
        }