private void SecretAsciiCb_CheckedChanged(object sender, EventArgs e) { try { if (SecretAsciiCb.Checked) { byte[] data = GXDLMSTranslator.HexToBytes(SecretTB.Text); if (!GXHelpers.IsAscii(data)) { SecretAsciiCb.CheckedChanged -= SecretAsciiCb_CheckedChanged; SecretAsciiCb.Checked = !SecretAsciiCb.Checked; SecretAsciiCb.CheckedChanged += SecretAsciiCb_CheckedChanged; throw new ArgumentOutOfRangeException(Properties.Resources.InvalidASCII); } SecretTB.Text = ASCIIEncoding.ASCII.GetString(data); } else { SecretTB.Text = GXDLMSTranslator.ToHex(ASCIIEncoding.ASCII.GetBytes(SecretTB.Text)); } } catch (Exception ex) { MessageBox.Show(this, ex.Message); } }
public void OnValueChanged(int index, object value, bool user, bool connected) { GXDLMSParameterMonitor target = Target as GXDLMSParameterMonitor; if (index == 2) { if (target.ChangedParameter != null && target.ChangedParameter.Target != null) { TargetTb.Text = target.ChangedParameter.Target.ToString(); IndexTb.Text = target.ChangedParameter.AttributeIndex.ToString(); ValueTb.Text = Convert.ToString(GXHelpers.ConvertFromDLMS(target.ChangedParameter.Value, DataType.None, DataType.None, true, false)); } else { TargetTb.Text = ""; IndexTb.Text = ""; ValueTb.Text = ""; } } else if (index == 4) { ParametersLV.Items.Clear(); if (target.Parameters != null) { foreach (GXDLMSTarget it in target.Parameters) { ListViewItem li = ParametersLV.Items.Add(it.Target.ToString()); li.SubItems.Add(it.AttributeIndex.ToString()); li.Tag = it; } } } }
public void PreAction(GXActionArgs arg) { DialogResult ret; //Update secret. if (arg.Index == 5) { ret = GXHelpers.ShowMessageBox(this, Properties.Resources.SecretSetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { if (SecretTB.Text.Length == 0) { throw new ArgumentException("Invalid password."); } if (SecretAsciiCb.Checked) { arg.Value = SecretTB.Text; } else { arg.Value = GXDLMSTranslator.HexToBytes(SecretTB.Text); } } arg.Handled = ret != DialogResult.Yes; } }
private void UpdateWeekProfile(GXDLMSWeekProfile it, ListViewItem li, ListView list) { string str; if (GXHelpers.IsAscii(it.Name)) { str = ASCIIEncoding.ASCII.GetString(it.Name); } else { str = GXDLMSTranslator.ToHex(it.Name); } if (li == null) { li = list.Items.Add(str); 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() }); li.Tag = it; } else { li.SubItems[0].Text = str; li.SubItems[1].Text = it.Monday.ToString(); li.SubItems[2].Text = it.Tuesday.ToString(); li.SubItems[3].Text = it.Wednesday.ToString(); li.SubItems[4].Text = it.Thursday.ToString(); li.SubItems[5].Text = it.Friday.ToString(); li.SubItems[6].Text = it.Saturday.ToString(); li.SubItems[7].Text = it.Sunday.ToString(); } }
public void PreAction(GXActionArgs arg) { arg.Value = (sbyte)0; DialogResult ret; switch (arg.Index) { case 1: case 2: OnShowDlg(arg); break; case 3: ret = GXHelpers.ShowMessageBox(this, Properties.Resources.CaptureWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; break; case 4: ret = GXHelpers.ShowMessageBox(this, Properties.Resources.ResetAlarm, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; break; case 5: ret = GXHelpers.ShowMessageBox(this, Properties.Resources.SynchronizeClock, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; break; case 6: case 7: OnShowDlg(arg); break; } }
public void PreAction(GXActionArgs arg) { DialogResult ret; if (arg.Action == ActionType.Action) { if (arg.Index == 1) { //Synchronize current time ret = GXHelpers.ShowMessageBox(this, "Are you sure that you want to synchronize current time to the meter?", "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { arg.Value = (sbyte)0; } arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == 2) { OnShowDialog(arg); } else if (arg.Index == 3) { OnShowDialog(arg); } } }
private void UpdateSeasonProfile(GXDLMSSeasonProfile it, ListViewItem li, ListView target) { string str; if (GXHelpers.IsAscii(it.Name)) { str = ASCIIEncoding.ASCII.GetString(it.Name); } else { str = GXDLMSTranslator.ToHex(it.Name); } if (li == null) { li = target.Items.Add(str); li.SubItems.AddRange(new string[] { "", "" }); li.Tag = it; } else { li.SubItems[0].Text = str; } li.SubItems[1].Text = it.Start.ToFormatString(); if (GXHelpers.IsAscii(it.WeekName)) { li.SubItems[2].Text = ASCIIEncoding.ASCII.GetString(it.WeekName); } else { li.SubItems[2].Text = GXDLMSTranslator.ToHex(it.WeekName); } }
public GXDLMSActivityCalendarSeasonProfileDlg(GXDLMSSeasonProfile target, GXDLMSWeekProfile[] weekProfiles) { InitializeComponent(); Target = target; WeekProfile = weekProfiles; AsciiBtn.Checked = GXHelpers.IsAscii(Target.Name); NameTb.Text = GXHelpers.GetString(Target.Name); if (Target.Start != DateTime.MinValue) { StartTb.Text = Target.Start.ToFormatString(); } int pos, selected = -1; if (weekProfiles != null) { foreach (GXDLMSWeekProfile it in weekProfiles) { pos = WeekNameCb.Items.Add(it); if (selected == -1 && StructuralComparisons.StructuralEqualityComparer.Equals(Target.WeekName, it.Name)) { selected = pos; } } if (selected != -1) { WeekNameCb.SelectedIndex = selected; } } OkBtn.Enabled = weekProfiles != null && weekProfiles.Length != 0; }
public void PostAction(GXActionArgs arg) { if (arg.Exception == null) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } arg.Action = ActionType.None; }
public void PostAction(GXActionArgs arg) { if (arg.Exception == null) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } arg.Action = ActionType.None; arg.Rebooting = arg.Target.LogicalName == "0.0.10.0.0.255"; }
public void PreAction(GXActionArgs arg) { if (GXHelpers.ShowMessageBox(this, Properties.Resources.ActivatePassiveCalendar, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information) == DialogResult.Yes) { arg.Value = (sbyte)0; } else { arg.Action = ActionType.None; } }
public void PreAction(GXActionArgs arg) { arg.Value = (sbyte)0; DialogResult ret; if (arg.Index == 1) { //Reset. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.GeneralResetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; } }
public void PreAction(GXActionArgs arg) { if (arg.Action == ActionType.Write && arg.Index == 2) { //Update current time DialogResult ret = GXHelpers.ShowMessageBox(this, Properties.Resources.TimeSetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { (Target as GXDLMSData).Value = GXDateTime.ToUnixTime(DateTime.Now.ToUniversalTime()); } arg.Handled = ret != DialogResult.Yes; } }
void OnShowDialog(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ShowUserDialogEventHandler(OnShowDialog), arg).AsyncWaitHandle.WaitOne(); } else { if (ProfileGenericView.SelectedCells.Count == 1) { DataGridViewRow row = ProfileGenericView.Rows[ProfileGenericView.SelectedCells[0].RowIndex]; if (arg.Index == -1) { //Add to the white list. string data = "<Array Qty=\"01\" ><Structure Qty=\"04\" ><OctetString Value=\"" + row.Cells[2].Value + "\" /><UInt8 Value=\"63\" /><UInt16 Value=\"0004\" /><UInt8 Value=\"5\" /></Structure></Array>"; arg.Action = ActionType.Write; arg.Index = 2; GXDLMSData d = new GXDLMSData("0.0.94.39.48.255"); d.SetDataType(2, DataType.Array); d.Value = GXDLMSTranslator.XmlToValue(data); arg.Target = d; } else if (arg.Index == -2) { //Add to the black list. string data = "<Array Qty=\"01\" ><OctetString Value=\"" + row.Cells[2].Value + "\" /></Array>"; arg.Action = ActionType.Write; arg.Index = 2; arg.Value = GXDLMSTranslator.XmlToValue(data); arg.Target = new GXDLMSData("0.0.94.39.47.255"); arg.Target.SetDataType(2, DataType.Array); } else if (arg.Index == -3) { //Remove from the white or black list. //Add to the white list. long unixTime = GXDateTime.ToUnixTime(DateTime.Parse(Convert.ToString(row.Cells[4].Value))); string data = "<Structure Qty=\"02\" ><OctetString Value=\"" + row.Cells[0].Value + "\" /><UInt32 Value=\"" + unixTime + "\" /></Structure>"; arg.Value = GXDLMSTranslator.XmlToValue(data); ProfileGenericView.Rows.Remove(row); } } else { GXHelpers.ShowMessageBox(this, Properties.Resources.ProfileGenericDeviceAmountWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information); arg.Handled = true; } } }
public void PostAction(GXActionArgs arg) { //Read value after reset. if (arg.Action == ActionType.Action) { arg.Index = 2; arg.Action = ActionType.Read; return; } if (arg.Exception == null) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } arg.Action = ActionType.None; }
public void PreAction(GXActionArgs arg) { arg.Value = (sbyte)0; DialogResult ret; if (arg.Index == 1) { //Reset. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.ProfileGenericResetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == 2) { //Capture. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.ProfileGenericCaptureWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == -1) { //Add to the white list. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.WhiteListWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { OnShowDialog(arg); } arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == -2) { //Add to the black list. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.BlackListWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { OnShowDialog(arg); } arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == -3) { //Remove from te white or black list. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.RemoveDeviceConfirmation, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { OnShowDialog(arg); } arg.Handled = ret != DialogResult.Yes; } }
void OnExecuteScript(GXActionArgs arg) { if (InvokeRequired) { BeginInvoke(new ExecuteScriptEventHandler(OnExecuteScript), arg).AsyncWaitHandle.WaitOne(); } else { DialogResult ret = GXHelpers.ShowMessageBox(this, Properties.Resources.ScriptTableExecute, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { arg.Value = (Target as GXDLMSScriptTable).Execute(arg.Client, UInt16.Parse(ScriptId.Text)); } arg.Handled = ret != DialogResult.Yes; } }
public void PreAction(GXActionArgs arg) { DialogResult ret; if (arg.Action == ActionType.Write) { if (arg.Index == 2) { //Update current time ret = GXHelpers.ShowMessageBox(this, Properties.Resources.TimeSetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { (Target as GXDLMSClock).Time = DateTime.Now; } arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == 3) { //Update current time zone. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.TimeZoneSetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { if (arg.Client.UseUtc2NormalTime) { (Target as GXDLMSClock).TimeZone = (int)TimeZoneInfo.Local.BaseUtcOffset.TotalMinutes; } else { (Target as GXDLMSClock).TimeZone = -(int)TimeZoneInfo.Local.BaseUtcOffset.TotalMinutes; } Target.UpdateDirty(3, (Target as GXDLMSClock).TimeZone); } arg.Handled = ret != DialogResult.Yes; } } else if (arg.Action == ActionType.Action) { if (arg.Index == 5 || arg.Index == 6) { OnShowDlg(arg); } else { arg.Value = (sbyte)0; } } }
public void OnValueChanged(int index, object value, bool user) { GXDLMSAutoAnswer target = Target as GXDLMSAutoAnswer; if (index == 3) { ListeningWindowLV.Items.Clear(); if (target.ListeningWindow != null) { foreach (var it in target.ListeningWindow) { ListViewItem li = ListeningWindowLV.Items.Add(it.Key.ToString()); li.SubItems.Add(GXHelpers.ConvertDLMS2String(it.Value.ToString())); } } } else if (index == 5) { if (target.NumberOfCalls == 0) { NumberOfCallsTB.Value = "No limit."; } else { NumberOfCallsTB.Value = target.NumberOfCalls.ToString(); } } else if (index == 6) { if (target.NumberOfRingsInListeningWindow == 0) { this.RingCountInWindowTB.Text = "No connect."; } else { this.RingCountInWindowTB.Text = target.NumberOfRingsInListeningWindow.ToString(); } if (target.NumberOfRingsOutListeningWindow == 0) { this.RingCountOutOfWindowTB.Text = "No connect."; } else { this.RingCountOutOfWindowTB.Text = target.NumberOfRingsOutListeningWindow.ToString(); } } }
public void PostAction(GXActionArgs arg) { if (arg.Exception == null && arg.Action == ActionType.Action) { if (arg.Index == 1) { arg.Action = ActionType.Read; arg.Index = 2; } else { if (arg.Index == 2) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (arg.Index == 4) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (arg.Index == 5) { BeginInvoke(new GetValueEventHandler(SaveCertificateRequest), arg).AsyncWaitHandle.WaitOne(); } else if (arg.Index == 6) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (arg.Index == 7) { BeginInvoke(new GetValueEventHandler(SaveCertificate), arg).AsyncWaitHandle.WaitOne(); } else if (arg.Index == 8) { GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } arg.Action = ActionType.None; } } else { arg.Action = ActionType.None; } }
public void PreAction(GXActionArgs arg) { arg.Value = (sbyte)0; DialogResult ret; if (arg.Index == 1) { //Request Action. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.AccountActivateWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { } arg.Handled = ret != DialogResult.Yes; } else if (arg.Index == 1) { //Reset. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.RegisterResetWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); arg.Handled = ret != DialogResult.Yes; } }
static public object ConvertFromDLMS(object data, DataType from, DataType type, bool arrayAsString) { if (type == DataType.Array) { return(data); } if (type == DataType.None) { if (arrayAsString && data != null && data.GetType().IsArray) { data = GXHelpers.GetArrayAsString(data); } return(data); } //Show Octet string... if (from == DataType.OctetString && type == DataType.OctetString) { if (data is byte[]) { string str = ""; byte[] arr = (byte[])data; if (arr.Length == 0) { data = string.Empty; } else { foreach (byte it in arr) { str += it.ToString() + "."; } data = str.Substring(0, str.Length - 1); } } } //Convert DLMS octect string to Windows string. else if (from == DataType.OctetString && type == DataType.String) { if (data is string) { return(data); } else if (data is byte[]) { byte[] arr = (byte[])data; data = System.Text.Encoding.ASCII.GetString(arr); } } //Convert DLMS date time to Windows Time. else if (type == DataType.DateTime) { if (data is byte[]) { if (((byte[])data).Length == 5) { return(GXDLMSClient.ChangeType((byte[])data, DataType.Date)); } return(GXDLMSClient.ChangeType((byte[])data, DataType.DateTime)); } return(data); } //Convert DLMS date time to Windows Date. else if (type == DataType.Date) { if (data is DateTime) { return(data); } if (data is string) { return(data); } if (!data.GetType().IsArray || ((Array)data).Length < 5) { throw new Exception("DateTime conversion failed. Invalid DLMS format."); } return(GXDLMSClient.ChangeType((byte[])data, DataType.Date)); } //Convert DLMS date time to Windows Time. else if (type == DataType.Time) { if (data is byte[]) { return(GXDLMSClient.ChangeType((byte[])data, type)); } return(data); } else if (data is byte[]) { if (type == DataType.String) { data = System.Text.Encoding.ASCII.GetString((byte[])data); } else { data = ToHexString(data); } } else if (data is Array) { data = ArrayToString(data); } return(data); }
public void PostAction(GXActionArgs arg) { GXDLMSImageTransfer it = Target as GXDLMSImageTransfer; if (arg.Action == ActionType.Read) { if (arg.Index == 5) { if (!it.ImageTransferEnabled) { updatingImage = false; GXHelpers.ShowMessageBox(this, Properties.Resources.ImageTransferDisabled, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); arg.Action = ActionType.None; return; } OnDescription(Properties.Resources.ImageTransferEnabled); //Get ImageBlockSize. arg.Index = 2; } else if (arg.Index == 2) { OnDescription(Properties.Resources.ImageBlockSize + it.ImageBlockSize); //Invoke Initiates image transfer. arg.Index = 1; arg.Action = ActionType.Action; } else if (arg.Index == 6) { OnImageTransferStatus(it.ImageTransferStatus); GetDelay(arg); if (arg.Exception != null) { return; } int delay = (int)arg.Value; arg.Value = null; switch (it.ImageTransferStatus) { case ImageTransferStatus.NotInitiated: if (++statusReadCount > 10) { OnDescription("Failed to read Image transfer status after image transfer initiate."); GXHelpers.ShowMessageBox(this, "Failed to read Image transfer status after image transfer initiate.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); arg.Action = ActionType.None; updatingImage = false; return; } Thread.Sleep(delay); arg.Index = 6; break; case ImageTransferStatus.TransferInitiated: if (!transformingImage) { arg.Action = ActionType.Action; arg.Index = 2; transformingImage = true; } else { if (!Properties.Settings.Default.ImageManualUpdate) { arg.Index = 3; arg.Action = ActionType.Action; } else { arg.Action = ActionType.None; ManualBtn_CheckedChanged(null, null); } } break; case ImageTransferStatus.VerificationInitiated: Thread.Sleep(delay); OnDescription(Properties.Resources.VerificationInitiated); arg.Text = Properties.Resources.VerificationInitiated; arg.Index = 6; break; case ImageTransferStatus.VerificationSuccessful: arg.Index = 4; arg.Action = ActionType.Action; break; case ImageTransferStatus.VerificationFailed: OnDescription(Properties.Resources.VerificationFailed); arg.Text = Properties.Resources.VerificationFailed; arg.Action = ActionType.None; break; case ImageTransferStatus.ActivationInitiated: Thread.Sleep(delay); OnDescription(Properties.Resources.ActivationInitiated); arg.Text = Properties.Resources.ActivationInitiated; break; case ImageTransferStatus.ActivationSuccessful: OnDescription(Properties.Resources.ActivationSuccessful); GXHelpers.ShowMessageBox(this, Properties.Resources.ImageActivatedTxt, "", MessageBoxButtons.OK, MessageBoxIcon.Information); arg.Action = ActionType.None; break; case ImageTransferStatus.ActivationFailed: OnDescription(Properties.Resources.ActivationFailed); arg.Text = Properties.Resources.ActivationFailed; arg.Action = ActionType.None; break; } } } else if (arg.Action == ActionType.Action) { if (arg.Index == 1) { OnDescription("Image transfer initiated."); arg.Action = ActionType.Read; arg.Index = 6; } else if (arg.Index == 2) { OnDescription("Image transfered."); arg.Index = 6; arg.Action = ActionType.Read; } else if (arg.Index == 3) { if (arg.Exception is GXDLMSException) { //If meter is activating image. if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure) { if (!Properties.Settings.Default.ImageManualUpdate) { arg.Exception = null; GetDelay(arg); if (arg.Exception != null) { return; } int delay = (int)arg.Value; Thread.Sleep(delay); arg.Value = null; } return; } } if (!Properties.Settings.Default.ImageManualUpdate) { arg.Index = 6; arg.Action = ActionType.Read; } else { arg.Action = ActionType.None; } } else if (arg.Index == 4) { if (arg.Exception is GXDLMSException) { //If meter is activating image. if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure) { if (!Properties.Settings.Default.ImageManualUpdate) { arg.Exception = null; GetDelay(arg); if (arg.Exception != null) { return; } int delay = (int)arg.Value; Thread.Sleep(delay); arg.Value = null; } return; } } OnDescription(Properties.Resources.ImageActivatedTxt); arg.Action = ActionType.None; arg.Rebooting = true; } } }
public void PostAction(GXActionArgs arg) { GXDLMSImageTransfer it = Target as GXDLMSImageTransfer; GXImageUpdateStatus status = (GXImageUpdateStatus)arg.Tag; if (arg.Action == ActionType.Read) { if (arg.Index == 5) { if (!it.ImageTransferEnabled) { GXHelpers.ShowMessageBox(this, Properties.Resources.ImageTransferDisabled, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); arg.Action = ActionType.None; return; } OnDescription(Properties.Resources.ImageTransferEnabled); //Get ImageBlockSize. arg.Index = 2; } else if (arg.Index == 2) { OnDescription(Properties.Resources.ImageBlockSize + it.ImageBlockSize); //Read image_transferred_blocks_status. arg.Index = 3; } else if (arg.Index == 3) { int index = 0; foreach (char b in it.ImageTransferredBlocksStatus) { if (b == '0') { DialogResult ret = GXHelpers.ShowMessageBox(this, index + " Image blocks already exists. Do you want to overwrite image? " + Environment.NewLine + "Answering No will update missing blocks.", "GXDLMSDirector", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Cancel) { arg.Action = ActionType.None; return; } if (ret == DialogResult.No) { status.ImageStartIndex = index; arg.Index = 2; arg.Action = ActionType.Action; return; } break; } ++index; } OnDescription(Properties.Resources.ImageBlockSize + it.ImageBlockSize); //Invoke Initiates image transfer. arg.Index = 1; arg.Action = ActionType.Action; } else if (arg.Index == 6) { OnImageTransferStatus(it.ImageTransferStatus); GetDelay(arg); if (arg.Exception != null) { return; } int delay = (int)arg.Value; arg.Value = null; switch (it.ImageTransferStatus) { case ImageTransferStatus.NotInitiated: if (++status.StatusReadCount > 10) { OnDescription("Failed to read Image transfer status after image transfer initiate."); GXHelpers.ShowMessageBox(this, "Failed to read Image transfer status after image transfer initiate.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); arg.Action = ActionType.None; return; } Thread.Sleep(delay); arg.Index = 6; break; case ImageTransferStatus.TransferInitiated: if (!status.TransformingImage) { arg.Action = ActionType.Action; arg.Index = 2; status.TransformingImage = true; } else { if (!Properties.Settings.Default.ImageManualUpdate) { arg.Action = ActionType.Action; if (arg.Client.CanInvoke(arg.Target, 3)) { arg.Index = 3; } else if (arg.Client.CanInvoke(arg.Target, 4)) { arg.Index = 4; } else { GXHelpers.ShowMessageBox(this, Properties.Resources.ImageTransferedNotActivatedTxt, "", MessageBoxButtons.OK, MessageBoxIcon.Information); arg.Action = ActionType.None; } } else { arg.Action = ActionType.None; ManualBtn_CheckedChanged(null, null); } } break; case ImageTransferStatus.VerificationInitiated: Thread.Sleep(delay); OnDescription(Properties.Resources.VerificationInitiated); arg.Text = Properties.Resources.VerificationInitiated; arg.Index = 6; break; case ImageTransferStatus.VerificationSuccessful: arg.Index = 4; arg.Action = ActionType.Action; break; case ImageTransferStatus.VerificationFailed: OnDescription(Properties.Resources.VerificationFailed); arg.Text = Properties.Resources.VerificationFailed; arg.Action = ActionType.None; break; case ImageTransferStatus.ActivationInitiated: Thread.Sleep(delay); OnDescription(Properties.Resources.ActivationInitiated); arg.Text = Properties.Resources.ActivationInitiated; break; case ImageTransferStatus.ActivationSuccessful: OnDescription(Properties.Resources.ActivationSuccessful); GXHelpers.ShowMessageBox(this, Properties.Resources.ImageActivatedTxt, "", MessageBoxButtons.OK, MessageBoxIcon.Information); arg.Action = ActionType.None; break; case ImageTransferStatus.ActivationFailed: OnDescription(Properties.Resources.ActivationFailed); arg.Text = Properties.Resources.ActivationFailed; arg.Action = ActionType.None; break; } } } else if (arg.Action == ActionType.Action) { if (arg.Index == 1) { OnDescription("Image transfer initiated."); arg.Action = ActionType.Read; arg.Index = 6; } else if (arg.Index == 2) { OnDescription("Image transfered."); arg.Index = 6; arg.Action = ActionType.Read; } else if (arg.Index == 3) { if (arg.Exception is GXDLMSException) { //If meter is verifying the image. if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure) { if (!Properties.Settings.Default.ImageManualUpdate) { arg.Exception = null; GetDelay(arg); if (arg.Exception != null) { return; } int delay = (int)arg.Value; Thread.Sleep(delay); arg.Value = null; } } else { OnDescription("Image verifying failed."); } return; } if (!Properties.Settings.Default.ImageManualUpdate) { arg.Index = 6; arg.Action = ActionType.Read; } else { arg.Action = ActionType.None; } } else if (arg.Index == 4) { if (arg.Exception is GXDLMSException) { //If meter is activating image. if ((arg.Exception as GXDLMSException).ErrorCode == (int)ErrorCode.TemporaryFailure) { if (!Properties.Settings.Default.ImageManualUpdate) { arg.Exception = null; GetDelay(arg); if (arg.Exception != null) { return; } int delay = (int)arg.Value; Thread.Sleep(delay); arg.Value = null; } } else { OnDescription("Image activation failed."); } return; } OnDescription(Properties.Resources.ImageActivatedTxt); arg.Action = ActionType.None; arg.Rebooting = true; GXHelpers.ShowMessageBox(this, Properties.Resources.ActionImplemented, "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public void PreAction(GXActionArgs arg) { //Add object to association view. if (arg.Index == 3) { GXDLMSObject it = new GXDLMSData(); OnShowDialog(it, arg); } else if (arg.Index == 4) { // Remove object from association view. OnShowDialog(null, arg); } //Add user to user list. else if (arg.Index == 5) { OnShowDialog(true, arg); } else if (arg.Index == 6) { // Remove user from user list. OnShowDialog(false, arg); } if (arg.Action == ActionType.Write && arg.Index == 7) { DialogResult ret; //Update pw. ret = GXHelpers.ShowMessageBox(this, Properties.Resources.SetPasswordWarning, "", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (ret == DialogResult.Yes) { byte[] value; if (SecretAsciiCb.Checked) { value = ASCIIEncoding.ASCII.GetBytes(SecretTB.Text); } else { value = GXDLMSTranslator.HexToBytes(SecretTB.Text); } GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName; if (target.AuthenticationMechanismName.MechanismId == Authentication.Low) { arg.Index = 7; arg.Action = ActionType.Write; } else { arg.Action = ActionType.Action; arg.Index = 2; } if (arg.Action == ActionType.Write) { target.Secret = value; } else { GXByteBuffer bb = new GXByteBuffer(); bb.SetUInt8((byte)DataType.OctetString); bb.SetUInt8((byte)value.Length); bb.Set(value); arg.Value = bb.Array(); } } arg.Handled = ret != DialogResult.Yes; } else if (arg.Action == ActionType.Write && arg.Index == 2) { //Skip write invoke. arg.Handled = true; } }
void OnUpdateValue(object value) { string str; if (value != null && value.GetType().IsArray) { str = Convert.ToString(GXHelpers.ConvertFromDLMS(value, DataType.None, DataType.None, true)); } else { str = GXHelpers.ConvertDLMS2String(value); } if (Type == GXValueFieldType.TextBox) { textBox1.TextChanged -= new EventHandler(textBox1_TextChanged); this.textBox1.Text = str; textBox1.TextChanged += new EventHandler(textBox1_TextChanged); } else if (Type == GXValueFieldType.CompoBox) { if (comboBox1.Items.Count != 0) { if (value != null) { if (Items != null && Items.Count != 0) { foreach (GXObisValueItem it in Items) { if (it.Value.Equals(Convert.ChangeType(value, it.Value.GetType()))) { int pos = comboBox1.Items.IndexOf(it.UIValue); if (pos != -1) { comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged); comboBox1.SelectedIndex = pos; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); return; } } } } else if (value is Enum) { comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged); comboBox1.SelectedItem = value; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); return; } } else { comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged); comboBox1.SelectedIndex = -1; comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); return; } } this.comboBox1.Text = str; } else if (Type == GXValueFieldType.ListBox) { if (value is Array) { this.listBox1.Items.Clear(); foreach (Array it in (Array)value) { List <byte> arr = new List <byte>(); foreach (object item in it) { if (item is Array) { foreach (byte b in (Array)item) { arr.Add(b); } } else { arr.Add((byte)item); } } listBox1.Items.Add(ASCIIEncoding.ASCII.GetString((byte[])arr.ToArray())); } } else if (value is Enum) { listBox1.SelectedItem = value; return; } } else if (Type == GXValueFieldType.CheckedListBox) { if (value is Enum) { checkedlistBox1.ItemCheck -= CheckedlistBox1_ItemCheck; //Uncheck all items. for (int pos = 0; pos != checkedlistBox1.Items.Count; ++pos) { checkedlistBox1.SetItemChecked(pos, false); } foreach (var it in Enum.GetValues(value.GetType())) { if (((int)it & (int)value) != 0 || ((int)it == (int)value)) { checkedlistBox1.SetItemChecked(checkedlistBox1.Items.IndexOf(it), true); } } checkedlistBox1.ItemCheck += CheckedlistBox1_ItemCheck; return; } } else { throw new InvalidExpressionException(); } }
public GXDLMSActivityCalendarWeekProfileDlg(GXDLMSWeekProfile target, GXDLMSDayProfile[] days) { InitializeComponent(); Target = target; AsciiBtn.Checked = GXHelpers.IsAscii(Target.Name); NameTb.Text = GXHelpers.GetString(Target.Name); if (days == null || days.Length == 0) { MondayCb.Enabled = TuesdayCb.Enabled = WednesdayCb.Enabled = ThursdayCb.Enabled = FridayCb.Enabled = SaturdayCb.Enabled = SundayCb.Enabled = OkBtn.Enabled = false; } else { MondayCb.Items.AddRange(days); TuesdayCb.Items.AddRange(days); WednesdayCb.Items.AddRange(days); ThursdayCb.Items.AddRange(days); FridayCb.Items.AddRange(days); SaturdayCb.Items.AddRange(days); SundayCb.Items.AddRange(days); foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Monday) { MondayCb.SelectedItem = it; break; } } foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Tuesday) { TuesdayCb.SelectedItem = it; break; } } foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Wednesday) { WednesdayCb.SelectedItem = it; break; } } foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Thursday) { ThursdayCb.SelectedItem = it; break; } } foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Friday) { FridayCb.SelectedItem = it; break; } } foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Saturday) { SaturdayCb.SelectedItem = it; break; } } foreach (GXDLMSDayProfile it in days) { if (it.DayId == Target.Sunday) { SundayCb.SelectedItem = it; break; } } } }
public void OnValueChanged(GXDLMSViewArguments arg) { GXDLMSAssociationLogicalName target = Target as GXDLMSAssociationLogicalName; //object list. if (arg.Index == 2) { GXDLMSObjectCollection items = target.ObjectList; ObjectsView.Items.Clear(); if (items != null) { foreach (GXDLMSObject it in items) { ListViewItem li = ObjectsView.Items.Add(it.ObjectType.ToString()); li.SubItems.Add(it.Version.ToString()); //Version li.SubItems.Add(it.LogicalName); li.Tag = it; //access_rights: access_right if (it is IGXDLMSBase) { string str = null; //Show attribute access. int cnt = (it as IGXDLMSBase).GetAttributeCount(); for (int pos = 1; pos != cnt + 1; ++pos) { if (str != null) { str += ", "; } if (target.Version < 3) { AccessMode mode = it.GetAccess(pos); str += pos.ToString() + " = " + mode; } else { AccessMode3 mode = it.GetAccess3(pos); str += pos.ToString() + " = " + mode; } } li.SubItems.Add(str); //Show method access. str = null; cnt = (it as IGXDLMSBase).GetMethodCount(); for (int pos = 1; pos != cnt + 1; ++pos) { if (str != null) { str += ", "; } if (target.Version < 3) { MethodAccessMode mode = it.GetMethodAccess(pos); str += pos.ToString() + " = " + mode; } else { MethodAccessMode3 mode = it.GetMethodAccess3(pos); str += pos.ToString() + " = " + mode; } } li.SubItems.Add(str); } } } } //Associated partners ID. else if (arg.Index == 3) { ClientSAPTb.Text = Convert.ToString(target.ClientSAP); ServerSAPTb.Text = Convert.ToString(target.ServerSAP); } else if (arg.Index == 4) { try { this.ApplicationContextIDCb.SelectedIndexChanged -= new System.EventHandler(this.ApplicationContextIDCb_SelectedIndexChanged); ApplicationContextIDCb.Items.Clear(); if (target.ApplicationContextName.ContextId == ApplicationContextName.LogicalName || target.ApplicationContextName.ContextId == ApplicationContextName.LogicalNameWithCiphering) { ApplicationContextIDCb.Items.AddRange(new object[] { ApplicationContextName.LogicalName, ApplicationContextName.LogicalNameWithCiphering }); } else { ApplicationContextIDCb.Items.AddRange(new object[] { ApplicationContextName.ShortName, ApplicationContextName.ShortNameWithCiphering }); } // Application context name. ApplicationJointISOCTTTb.Text = Convert.ToString(target.ApplicationContextName.JointIsoCtt); ApplicationCountryTb.Text = Convert.ToString(target.ApplicationContextName.Country); ApplicationCountryNameTb.Text = Convert.ToString(target.ApplicationContextName.CountryName); ApplicationIdentifiedOrganizationTb.Text = Convert.ToString(target.ApplicationContextName.IdentifiedOrganization); ApplicationDLMSUATb.Text = Convert.ToString(target.ApplicationContextName.DlmsUA); ApplicationContextTb.Text = Convert.ToString(target.ApplicationContextName.ApplicationContext); ApplicationContextIDCb.SelectedItem = target.ApplicationContextName.ContextId; ApplicationRegistrationAuthorityCb.SelectedItem = FindCountry(target.ApplicationContextName.JointIsoCtt, target.ApplicationContextName.Country, target.ApplicationContextName.CountryName); } finally { ApplicationContextIDCb.SelectedIndexChanged += new System.EventHandler(this.ApplicationContextIDCb_SelectedIndexChanged); } } else if (arg.Index == 5) { // xDLMS_context_info ShowConformance(target.XDLMSContextInfo.Conformance); MaxReceivePDUSizeTb.Text = target.XDLMSContextInfo.MaxReceivePduSize.ToString(); MaxSendPDUSizeTb.Text = target.XDLMSContextInfo.MaxSendPduSize.ToString(); DLMSVersionNumberTB.Text = target.XDLMSContextInfo.DlmsVersionNumber.ToString(); CypheringInfoTb.Text = GXDLMSTranslator.ToHex(target.XDLMSContextInfo.CypheringInfo); } else if (arg.Index == 6) { Freeze = true; // authentication_mechanism_name AuthenticationJointISOCTTTb.Text = Convert.ToString(target.AuthenticationMechanismName.JointIsoCtt); AuthenticationCountryTb.Text = Convert.ToString(target.AuthenticationMechanismName.Country); AuthenticationCountryNameTb.Text = Convert.ToString(target.AuthenticationMechanismName.CountryName); AuthenticationIdentifiedorganizationTb.Text = Convert.ToString(target.AuthenticationMechanismName.IdentifiedOrganization); AuthenticationDLMSUATb.Text = Convert.ToString(target.AuthenticationMechanismName.DlmsUA); AuthenticationMechanismNameTb.Text = Convert.ToString(target.AuthenticationMechanismName.AuthenticationMechanismName); AuthenticationMechanismIdCb.Text = Convert.ToString(target.AuthenticationMechanismName.MechanismId); AuthenticationRegistrationAuthorityCb.SelectedItem = FindCountry(target.AuthenticationMechanismName.JointIsoCtt, target.AuthenticationMechanismName.Country, target.AuthenticationMechanismName.CountryName); Freeze = false; } else if (arg.Index == 7) { //Secret. if (GXHelpers.IsAscii(target.Secret)) { SecretAsciiCb.Checked = true; SecretTB.Text = ASCIIEncoding.ASCII.GetString(target.Secret); } else { SecretTB.Text = GXDLMSTranslator.ToHex(target.Secret); } } else if (arg.Index == 9) { SecuritySetupCb.Items.Clear(); //security_setup_reference if (target.Parent != null) { SecuritySetupCb.Items.Add(""); foreach (GXDLMSSecuritySetup it in target.Parent.GetObjects(ObjectType.SecuritySetup)) { SecuritySetupCb.Items.Add(it); if (target.SecuritySetupReference == it.LogicalName) { SecuritySetupCb.SelectedIndexChanged -= new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged); SecuritySetupCb.SelectedItem = it; SecuritySetupCb.SelectedIndexChanged += new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged); } } } else { GXDLMSSecuritySetup it = new GXDLMSSecuritySetup(target.SecuritySetupReference); SecuritySetupCb.Items.Add(it); SecuritySetupCb.SelectedIndexChanged -= new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged); SecuritySetupCb.SelectedItem = it; SecuritySetupCb.SelectedIndexChanged += new System.EventHandler(this.SecuritySetupCb_SelectedIndexChanged); } } //User list. else if (arg.Index == 10) { List <KeyValuePair <byte, string> > items = target.UserList; UsersList.Items.Clear(); if (items != null) { foreach (KeyValuePair <byte, string> it in items) { ListViewItem li = UsersList.Items.Add(it.Key.ToString()); li.SubItems.Add(it.Value); li.Tag = it.Key; } } } else if (arg.Index == 11) //Current user { foreach (ListViewItem it in UsersList.Items) { if ((byte)it.Tag == target.CurrentUser.Key) { it.Selected = true; } else if (it.Selected) { it.Selected = false; } } } }