Ejemplo n.º 1
0
 void OnShowDlg(GXActionArgs arg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne();
     }
     else
     {
         GXDLMSIp6Setup target = Target as GXDLMSIp6Setup;
         if (arg.Index == 5)
         {
             GXClockPresetTimeDlg dlg = new GXClockPresetTimeDlg();
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 GXByteBuffer bb = new GXByteBuffer();
                 bb.SetUInt8((byte)DataType.Structure);
                 bb.SetUInt8(4);
                 //Add data type and length.
                 bb.SetUInt8((byte)DataType.OctetString);
                 bb.SetUInt8(12);
                 bb.Set(GXDLMSTranslator.HexToBytes(dlg.PresetTime.ToHex(false, GXDlmsUi.UseMeterTimeZone)));
                 //Add data type and length.
                 bb.SetUInt8((byte)DataType.OctetString);
                 bb.SetUInt8(12);
                 bb.Set(GXDLMSTranslator.HexToBytes(dlg.IntervalStart.ToHex(false, GXDlmsUi.UseMeterTimeZone)));
                 //Add data type and length.
                 bb.SetUInt8((byte)DataType.OctetString);
                 bb.SetUInt8(12);
                 bb.Set(GXDLMSTranslator.HexToBytes(dlg.IntervalEnd.ToHex(false, GXDlmsUi.UseMeterTimeZone)));
                 arg.Value = bb.Array();
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 6)
         {
             GXTextDlg dlg = new GXTextDlg("Shift Time", "Shift Time (s):", "", typeof(Int16));
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 arg.Value = Int16.Parse(dlg.GetValue());
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else
         {
             arg.Handled = true;
         }
     }
 }
 void OnShowDlg(GXActionArgs arg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne();
     }
     else
     {
         GXDLMSIp6Setup target = Target as GXDLMSIp6Setup;
         if (arg.Index == 1)
         {
             GXTextDlg dlg = new GXTextDlg("Update Amount", "Amount:", "", typeof(Int32));
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 arg.Value = Int32.Parse(dlg.GetValue());
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 2)
         {
             GXTextDlg dlg = new GXTextDlg("Set Amount", "Amount:", "", typeof(Int32));
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 arg.Value = Int32.Parse(dlg.GetValue());
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 3)
         {
             GXTextDlg dlg = new GXTextDlg("Invoke Credit", "Value:", "", typeof(sbyte));
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 arg.Value = sbyte.Parse(dlg.GetValue());
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else
         {
             arg.Handled = true;
         }
     }
 }
 public void OnValueChanged(int index, object value, bool user, bool connected)
 {
     if (index == 4)
     {
         UnicastAddressView.Items.Clear();
         GXDLMSIp6Setup target = Target as GXDLMSIp6Setup;
         if (target.UnicastIPAddress != null)
         {
             foreach (IPAddress it in target.UnicastIPAddress)
             {
                 ListViewItem li = UnicastAddressView.Items.Add(it.ToString());
                 li.Tag = it;
             }
         }
     }
     else if (index == 5)
     {
         MulticastAddressView.Items.Clear();
         GXDLMSIp6Setup target = Target as GXDLMSIp6Setup;
         if (target.MulticastIPAddress != null)
         {
             foreach (IPAddress it in target.MulticastIPAddress)
             {
                 ListViewItem li = MulticastAddressView.Items.Add(it.ToString());
                 li.Tag = it;
             }
         }
     }
     else if (index == 6)
     {
         GatewayAddressView.Items.Clear();
         GXDLMSIp6Setup target = Target as GXDLMSIp6Setup;
         if (target.GatewayIPAddress != null)
         {
             foreach (IPAddress it in target.GatewayIPAddress)
             {
                 ListViewItem li = GatewayAddressView.Items.Add(it.ToString());
                 li.Tag = it;
             }
         }
     }
     else if (index == 10)
     {
         DiscoverySetupView.Items.Clear();
         GXDLMSIp6Setup target = Target as GXDLMSIp6Setup;
         if (target.NeighborDiscoverySetup != null)
         {
             foreach (GXNeighborDiscoverySetup it in target.NeighborDiscoverySetup)
             {
                 ListViewItem li = DiscoverySetupView.Items.Add(it.MaxRetry.ToString());
                 li.SubItems.Add(it.RetryWaitTime.ToString());
                 li.SubItems.Add(it.SendPeriod.ToString());
                 li.Tag = it;
             }
         }
     }
     else if (index != 0)
     {
         throw new IndexOutOfRangeException("index");
     }
 }
 void OnShowDlg(GXActionArgs arg)
 {
     if (InvokeRequired)
     {
         BeginInvoke(new ShowDlgEventHandler(OnShowDlg), arg).AsyncWaitHandle.WaitOne();
     }
     else
     {
         GXTextDlg       dlg;
         IPv6AddressType type;
         GXDLMSIp6Setup  target = Target as GXDLMSIp6Setup;
         if (arg.Index == 1)
         {
             if (AddressTab.SelectedIndex == 0)
             {
                 dlg  = new GXTextDlg("Add Unicast Address", "Unicast address:", "", typeof(IPAddress));
                 type = IPv6AddressType.Unicast;
             }
             else if (AddressTab.SelectedIndex == 1)
             {
                 dlg  = new GXTextDlg("Add Multicast IP Address", "Multicast address:", "", typeof(IPAddress));
                 type = IPv6AddressType.Multicast;
             }
             else if (AddressTab.SelectedIndex == 2)
             {
                 dlg  = new GXTextDlg("Add Gateway IP Address", "Gateway address:", "", typeof(IPAddress));
                 type = IPv6AddressType.Gateway;
             }
             else
             {
                 throw new ArgumentOutOfRangeException();
             }
             if (dlg.ShowDialog(this) == DialogResult.OK)
             {
                 IPAddress addr = IPAddress.Parse(dlg.GetValue());
                 arg.Value = target.AddAddress(arg.Client, type, addr);
             }
             else
             {
                 arg.Handled = true;
             }
         }
         else if (arg.Index == 2)
         {
             if (AddressTab.SelectedIndex == 0 && UnicastAddressView.SelectedItems.Count != 0)
             {
                 ListViewItem li      = UnicastAddressView.SelectedItems[0];
                 IPAddress    address = (IPAddress)li.Tag;
                 UnicastAddressView.Items.Remove(li);
                 arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Unicast, address);
             }
             else if (AddressTab.SelectedIndex == 1 && MulticastAddressView.SelectedItems.Count != 0)
             {
                 ListViewItem li      = MulticastAddressView.SelectedItems[0];
                 IPAddress    address = (IPAddress)li.Tag;
                 MulticastAddressView.Items.Remove(li);
                 arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Multicast, address);
             }
             else if (AddressTab.SelectedIndex == 2 && GatewayAddressView.SelectedItems.Count != 0)
             {
                 ListViewItem li      = GatewayAddressView.SelectedItems[0];
                 IPAddress    address = (IPAddress)li.Tag;
                 GatewayAddressView.Items.Remove(li);
                 arg.Value = target.RemoveAddress(arg.Client, IPv6AddressType.Gateway, address);
             }
             else
             {
                 throw new ArgumentOutOfRangeException();
             }
         }
         else
         {
             arg.Handled = true;
         }
     }
 }
Ejemplo n.º 5
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";
            //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.
            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.TimeZone  = -(int)TimeZoneInfo.Local.BaseUtcOffset.TotalMinutes;
            clock.Deviation = 60;
            Items.Add(clock);
            ///////////////////////////////////////////////////////////////////////
            //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 = 100000;
            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.
            //Generate Profile Generic data file
            lock (FileLock)
            {
                //Create 10 000 rows for profile generic file.
                //In example profile generic we have two columns.
                //Date time and integer value.
                int      rowCount = 10000;
                DateTime dt       = DateTime.Now;
                //Reset minutes and seconds to Zero.
                dt = dt.AddSeconds(-dt.Second);
                dt = dt.AddMinutes(-dt.Minute);
                dt = dt.AddHours(-(rowCount - 1));
                StringBuilder sb = new StringBuilder();
                for (int pos = 0; pos != rowCount; ++pos)
                {
                    sb.Append(dt.ToString(CultureInfo.InvariantCulture));
                    sb.Append(';');
                    sb.AppendLine(Convert.ToString(pos + 1));
                    dt = dt.AddHours(1);
                }
                using (var writer = File.CreateText(GetdataFile()))
                {
                    sb.Length -= 2;
                    writer.Write(sb.ToString());
                }
            }
            ///////////////////////////////////////////////////////////////////////
            //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.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 GXTime(DateTime.Now), "0.1.10.1.101.255", 1) }) };
            activity.SeasonProfileActive    = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Summer time", new GXDateTime(-1, 3, 31, -1, -1, -1, -1), activity.WeekProfileTableActive[0]) };

            activity.CalendarNamePassive     = "Passive";
            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 GXTime(DateTime.Now), "0.1.10.1.101.255", 1) }) };
            activity.SeasonProfilePassive    = new GXDLMSSeasonProfile[] { new GXDLMSSeasonProfile("Winter time", new GXDateTime(-1, 10, 30, -1, -1, -1, -1), activity.WeekProfileTablePassive[0]) };
            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.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 IP6 Setup object.
            GXDLMSIp6Setup ip6 = new GXDLMSIp6Setup();

            Items.Add(ip6);

            //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)));

            Items.Add(new GXDLMSSpecialDaysTable());
            //Add  S-FSK objects
            Items.Add(new GXDLMSSFSKPhyMacSetUp());
            Items.Add(new GXDLMSSFSKActiveInitiator());
            Items.Add(new GXDLMSSFSKMacCounters());
            Items.Add(new GXDLMSSFSKMacSynchronizationTimeouts());
            ///Add G3-PLC objects.
            Items.Add(new GXDLMSG3Plc6LoWPan());
            Items.Add(new GXDLMSG3PlcMacLayerCounters());
            Items.Add(new GXDLMSG3PlcMacSetup());
            //Add security setup object
            Items.Add(new GXDLMSSecuritySetup());
            ///////////////////////////////////////////////////////////////////////
            //Server must initialize after all objects are added.
            Initialize();
        }