private void AddDayAction(GXDLMSActivityCalendar c, GXDLMSDayProfile target, int index, ListView li) { GXDLMSDayProfileAction item = new GXDLMSDayProfileAction(); GXDLMSActivityCalendarActionDlg dlg = new GXDLMSActivityCalendarActionDlg(item, Target.Parent.GetObjects(ObjectType.ScriptTable)); if (dlg.ShowDialog(this) == DialogResult.OK) { List <GXDLMSDayProfileAction> items = new List <GXDLMSDayProfileAction>(); if (target.DaySchedules != null) { items.AddRange(target.DaySchedules); } items.Add(item); target.DaySchedules = items.ToArray(); if (index == 5) { ActiveDaysList_SelectedIndexChanged(null, null); } else { PassiveDaysList_SelectedIndexChanged(null, null); } errorProvider1.SetError(li, Properties.Resources.ValueChangedTxt); c.UpdateDirty(index, target.DaySchedules); } }
/// <summary> /// Remove selected active day or actions. /// </summary> private void DayProfilePassiveRemoveBtn_Click(object sender, EventArgs e) { try { if (PassiveActionList.SelectedItems.Count == 0) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; while (PassiveDaysList.SelectedItems.Count == 1) { RemoveDayId(target, 9, PassiveDaysList); } } else { GXDLMSDayProfile target = PassiveDaysList.SelectedItems[0].Tag as GXDLMSDayProfile; if (PassiveActionList.SelectedItems.Count != 0) { RemoveDayAction(target, 9, PassiveActionList); } } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add new season profile. /// </summary> private void SeasonProfileActiveAddBtn_Click(object sender, EventArgs e) { try { if (tabControl2.SelectedTab == SeasonProfileActiveTab) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; AddSeasonProfile(target, 3, SeasonProfileActiveLV); } else if (tabControl2.SelectedTab == WeekProfileActiveTab) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; AddSeasonProfile(target, 3, SeasonProfileActiveLV); } else if (tabControl2.SelectedTab == DayProfileActiveTab) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; AddSeasonProfile(target, 3, SeasonProfileActiveLV); } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Edit selected active day. /// </summary> private void DayProfileActiveEditBtn_Click(object sender, EventArgs e) { try { if (ActiveActionList.SelectedItems.Count == 0) { if (ActiveDaysList.SelectedItems.Count == 1) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; EditDayId(target, target.DayProfileTableActive, 5, ActiveDaysList.SelectedItems[0], ActiveDaysList); } } else { if (ActiveActionList.SelectedItems.Count == 1) { ListViewItem li = ActiveActionList.SelectedItems[0]; EditDayAction(5, li, ActiveActionList); } } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void EditSeasonProfile(GXDLMSActivityCalendar target, GXDLMSSeasonProfile[] list, int index, ListViewItem li, ListView lv) { GXDLMSSeasonProfile item = (GXDLMSSeasonProfile)li.Tag; GXDLMSActivityCalendarSeasonProfileDlg dlg = new GXDLMSActivityCalendarSeasonProfileDlg(item, index == 3 ? target.WeekProfileTableActive : target.WeekProfileTablePassive); if (dlg.ShowDialog(this) == DialogResult.OK) { UpdateSeasonProfile(item, li, lv); errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(index, list); } }
private void EditDayId(GXDLMSActivityCalendar target, GXDLMSDayProfile[] list, int index, ListViewItem li, ListView lv) { GXDLMSDayProfile item = (GXDLMSDayProfile)li.Tag; GXDLMSActivityCalendarDayProfileDlg dlg = new GXDLMSActivityCalendarDayProfileDlg(item); if (dlg.ShowDialog(this) == DialogResult.OK) { UpdateDayProfile(item, li, index); errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(index, list); } }
// <summary> /// Remove passive week profile. /// </summary> private void WeekProfilePassiveRemoveBtn_Click(object sender, EventArgs e) { try { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; RemoveWeekProfile(target, 8, PWeekProfileLV); } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add new active day. /// </summary> private void AddDayActiveBtn_Click(object sender, EventArgs e) { try { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; AddDayId(target, 5, ActiveDaysList); } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Add new active action. /// </summary> private void ActiveActionAddBtn_Click(object sender, EventArgs e) { try { if (ActiveDaysList.SelectedItems.Count == 1) { GXDLMSDayProfile it = (GXDLMSDayProfile)ActiveDaysList.SelectedItems[0].Tag; GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; AddDayAction(target, it, 5, ActiveDaysList); } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Edit passive week profile. /// </summary> private void WeekProfilePassiveEditBtn_Click(object sender, EventArgs e) { try { if (PWeekProfileLV.SelectedItems.Count == 1) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; ListViewItem li = PWeekProfileLV.SelectedItems[0]; EditWeekProfile(target, target.WeekProfileTablePassive, 8, li, PWeekProfileLV); } } catch (Exception ex) { MessageBox.Show(Parent, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void RemoveDayId(GXDLMSActivityCalendar target, int index, ListView lv) { List <GXDLMSDayProfile> entries = new List <GXDLMSDayProfile>(); if (index == 5) { if (target.DayProfileTableActive != null) { entries.AddRange(target.DayProfileTableActive); } } else { if (target.DayProfileTablePassive != null) { entries.AddRange(target.DayProfileTablePassive); } } while (lv.SelectedItems.Count != 0) { ListViewItem li = lv.SelectedItems[0]; GXDLMSDayProfile item = (GXDLMSDayProfile)li.Tag; li.Remove(); errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt); if (index == 5) { Target.UpdateDirty(index, target.DayProfileTableActive); } else { Target.UpdateDirty(index, target.DayProfileTablePassive); } entries.Remove(item); } if (index == 5) { target.DayProfileTableActive = entries.ToArray(); } else { target.DayProfileTablePassive = entries.ToArray(); } }
private void AddWeekProfile(GXDLMSActivityCalendar target, int index, ListView li) { GXDLMSWeekProfile item = new GXDLMSWeekProfile(); GXDLMSWeekProfile[] list; GXDLMSDayProfile[] days; if (index == 3) { list = target.WeekProfileTableActive; days = target.DayProfileTableActive; } else { list = target.WeekProfileTablePassive; days = target.DayProfileTablePassive; } GXDLMSActivityCalendarWeekProfileDlg dlg = new GXDLMSActivityCalendarWeekProfileDlg(item, days); if (dlg.ShowDialog(this) == DialogResult.OK) { List <GXDLMSWeekProfile> items = new List <GXDLMSWeekProfile>(); if (list != null) { items.AddRange(list); } items.Add(item); if (index == 4) { target.WeekProfileTableActive = items.ToArray(); } else { target.WeekProfileTablePassive = items.ToArray(); } UpdateWeekProfile(item, null, li); errorProvider1.SetError(li, Properties.Resources.ValueChangedTxt); target.UpdateDirty(index, list); } }
private void EditWeekProfile(GXDLMSActivityCalendar target, GXDLMSWeekProfile[] list, int index, ListViewItem li, ListView lv) { GXDLMSWeekProfile item = (GXDLMSWeekProfile)li.Tag; GXDLMSDayProfile[] days; if (index == 3) { days = target.DayProfileTableActive; } else { days = target.DayProfileTablePassive; } GXDLMSActivityCalendarWeekProfileDlg dlg = new GXDLMSActivityCalendarWeekProfileDlg(item, days); if (dlg.ShowDialog(this) == DialogResult.OK) { UpdateWeekProfile(item, li, lv); errorProvider1.SetError(lv, Properties.Resources.ValueChangedTxt); Target.UpdateDirty(index, list); } }
public void OnValueChanged(int index, object value, bool user) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; if (index == 3) { SeasonProfileActiveLV.Items.Clear(); if (target.SeasonProfileActive != null) { foreach (GXDLMSSeasonProfile it in target.SeasonProfileActive) { ListViewItem li = SeasonProfileActiveLV.Items.Add(it.Name); li.SubItems.AddRange(new string[] { "", "", "", "", "", "" }); li.SubItems[this.YearHeader.Index].Text = it.Start.Value.Year.ToString(); li.SubItems[this.MonthHeader.Index].Text = it.Start.Value.Month.ToString(); li.SubItems[this.DayHeader.Index].Text = it.Start.Value.Day.ToString(); li.SubItems[this.StartHeader.Index].Text = it.Start.ToString(); li.SubItems[this.WeekNameHeader.Index].Text = it.WeekName; } } } else if (index == 4) { AWeekProfileLV.Items.Clear(); if (target.WeekProfileTableActive != null) { foreach (GXDLMSWeekProfile it in target.WeekProfileTableActive) { ListViewItem li = AWeekProfileLV.Items.Add(it.Name); li.SubItems.AddRange(new string[] { it.Monday.ToString(), it.Tuesday.ToString(), it.Wednesday.ToString(), it.Thursday.ToString(), it.Friday.ToString(), it.Saturday.ToString(), it.Sunday.ToString() }); } } } else if (index == 5) { ADayProfileTC.TabPages.Clear(); if (target.DayProfileTableActive != null) { System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CurrentUICulture; foreach (GXDLMSDayProfile it in target.DayProfileTableActive) { TabPage pg = new TabPage("Day " + it.DayId); ListView lv = new ListView(); lv.Dock = DockStyle.Fill; lv.HeaderStyle = ColumnHeaderStyle.Nonclickable; lv.View = View.Details; lv.Columns.Add("Start"); lv.Columns.Add("Script table"); lv.Columns.Add("Script Selector"); pg.Controls.Add(lv); ADayProfileTC.TabPages.Add(pg); foreach (GXDLMSDayProfileAction day in it.DaySchedules) { ListViewItem li = lv.Items.Add(day.StartTime.ToString()); li.SubItems.Add(day.ScriptLogicalName); li.SubItems.Add(day.ScriptSelector.ToString()); } } } } else if (index == 7) { SeasonProfilePassiveLV.Items.Clear(); if (target.SeasonProfilePassive != null) { foreach (GXDLMSSeasonProfile it in target.SeasonProfilePassive) { ListViewItem li = SeasonProfilePassiveLV.Items.Add(it.Name); li.SubItems.AddRange(new string[] { "", "", "", "", "", "" }); li.SubItems[this.YearHeader.Index].Text = it.Start.Value.Year.ToString(); li.SubItems[this.MonthHeader.Index].Text = it.Start.Value.Month.ToString(); li.SubItems[this.DayHeader.Index].Text = it.Start.Value.Day.ToString(); li.SubItems[this.StartHeader.Index].Text = it.Start.ToString(); li.SubItems[this.WeekNameHeader.Index].Text = it.WeekName; } } } else if (index == 8) { PWeekProfileLV.Items.Clear(); if (target.WeekProfileTablePassive != null) { foreach (GXDLMSWeekProfile it in target.WeekProfileTablePassive) { ListViewItem li = PWeekProfileLV.Items.Add(it.Name); li.SubItems.AddRange(new string[] { it.Monday.ToString(), it.Tuesday.ToString(), it.Wednesday.ToString(), it.Thursday.ToString(), it.Friday.ToString(), it.Saturday.ToString(), it.Sunday.ToString() }); } } } else if (index == 9) { PDayProfileTC.TabPages.Clear(); if (target.DayProfileTablePassive != null) { foreach (GXDLMSDayProfile it in target.DayProfileTablePassive) { TabPage pg = new TabPage("Day " + it.DayId); ListView lv = new ListView(); lv.Dock = DockStyle.Fill; lv.HeaderStyle = ColumnHeaderStyle.Nonclickable; lv.View = View.Details; lv.Columns.Add("Start"); lv.Columns.Add("Script table"); lv.Columns.Add("Script Selector"); pg.Controls.Add(lv); PDayProfileTC.TabPages.Add(pg); foreach (GXDLMSDayProfileAction day in it.DaySchedules) { ListViewItem li = lv.Items.Add(day.StartTime.ToString()); li.SubItems.Add(day.ScriptLogicalName); li.SubItems.Add(day.ScriptSelector.ToString()); } } } } }
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.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 = 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) { using (var writer = File.CreateText(GetdataFile())) { //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); } 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.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 GXTime(DateTime.Now), "0.1.10.1.101.255", 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 GXTime(DateTime.Now), "0.1.10.1.101.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.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))); 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(); }
public void OnValueChanged(int index, object value, bool user, bool connected) { GXDLMSActivityCalendar target = Target as GXDLMSActivityCalendar; if (index == 3) { SeasonProfileActiveLV.Items.Clear(); if (target.SeasonProfileActive != null) { foreach (GXDLMSSeasonProfile it in target.SeasonProfileActive) { UpdateSeasonProfile(it, null, SeasonProfileActiveLV); } } } else if (index == 4) { AWeekProfileLV.Items.Clear(); if (target.WeekProfileTableActive != null) { foreach (GXDLMSWeekProfile it in target.WeekProfileTableActive) { UpdateWeekProfile(it, null, AWeekProfileLV); } } } else if (index == 5) { ActiveDaysList.Items.Clear(); if (target.DayProfileTableActive != null) { foreach (GXDLMSDayProfile it in target.DayProfileTableActive) { UpdateDayProfile(it, null, index); } } //Select first item. if (ActiveDaysList.Items.Count != 0) { ActiveDaysList.Items[0].Selected = true; } } else if (index == 7) { SeasonProfilePassiveLV.Items.Clear(); if (target.SeasonProfilePassive != null) { foreach (GXDLMSSeasonProfile it in target.SeasonProfilePassive) { UpdateSeasonProfile(it, null, SeasonProfilePassiveLV); } } } else if (index == 8) { PWeekProfileLV.Items.Clear(); if (target.WeekProfileTablePassive != null) { foreach (GXDLMSWeekProfile it in target.WeekProfileTablePassive) { UpdateWeekProfile(it, null, PWeekProfileLV); } } } else if (index == 9) { PassiveDaysList.Items.Clear(); if (target.DayProfileTablePassive != null) { foreach (GXDLMSDayProfile it in target.DayProfileTablePassive) { UpdateDayProfile(it, null, index); } } //Select first item. if (PassiveDaysList.Items.Count != 0) { PassiveDaysList.Items[0].Selected = true; } } }
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 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.ReadWrite); //Value is get as Octet String. d.SetDataType(2, DataType.OctetString); d.SetUIDataType(2, DataType.String); Items.Add(d); //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 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); GXDLMSImageTransfer i = new GXDLMSImageTransfer(); Items.Add(i); /////////////////////////////////////////////////////////////////////// //Server must initialize after all objects are added. Initialize(); }