Example #1
0
 /// <summary>
 /// Show action data.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ActionsList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (MacrosView.SelectedIndices.Count == 1)
     {
         GXMacro macro = GetMacros()[MacrosView.SelectedIndices[0]];
         if (macro.Type == UserActionType.Get || macro.Type == UserActionType.Set)
         {
             if (!tabControl1.TabPages.Contains(VisualizedTab))
             {
                 tabControl1.TabPages.Insert(0, VisualizedTab);
             }
         }
         else
         {
             if (tabControl1.TabPages.Contains(VisualizedTab))
             {
                 tabControl1.TabPages.Remove(VisualizedTab);
             }
         }
         string actual, expected;
         if (Properties.Settings.Default.MacroRaw)
         {
             expected = macro.Data;
         }
         else
         {
             expected = macro.Value;
         }
         OriginalDataTb.Text = expected;
         if (Results.ContainsKey(macro))
         {
             if (Properties.Settings.Default.MacroRaw)
             {
                 actual   = Results[macro].Data;
                 expected = macro.Data;
             }
             else
             {
                 actual   = Results[macro].Value;
                 expected = macro.Value;
             }
             if (actual != expected)
             {
                 ReplyDataTb.Text    = actual;
                 ActualPanel.Visible = true;
             }
             else
             {
                 ActualPanel.Visible = false;
             }
         }
         else
         {
             ActualPanel.Visible = false;
             ReplyDataTb.Text    = null;
         }
         try
         {
             if (macro.Type == UserActionType.Get || macro.Type == UserActionType.Set)
             {
                 if (macro.ObjectType != 0)
                 {
                     GXDLMSObject obj = GXDLMSClient.CreateObject((ObjectType)macro.ObjectType);
                     if (obj != null)
                     {
                         obj.LogicalName = macro.LogicalName;
                         for (int pos = 1; pos != (obj as IGXDLMSBase).GetAttributeCount() + 1; ++pos)
                         {
                             obj.SetAccess(pos, AccessMode.NoAccess);
                         }
                         obj.SetAccess(macro.Index, AccessMode.ReadWrite);
                         obj.SetDataType(macro.Index, (DataType)macro.DataType);
                         obj.SetUIDataType(macro.Index, (DataType)macro.UIDataType);
                         if (!string.IsNullOrEmpty(macro.Data) && Target != null)
                         {
                             object value = GXDLMSTranslator.XmlToValue(macro.Data);
                             if (value is byte[] && macro.UIDataType != 0)
                             {
                                 value = Target.Comm.client.ChangeType(new GXByteBuffer((byte[])value), (DataType)macro.UIDataType);
                             }
                             else if (value is byte[] &&
                                      macro.DataType != (int)DataType.None &&
                                      macro.DataType != (int)DataType.OctetString)
                             {
                                 if (macro.DataType == (int)DataType.Array ||
                                     macro.DataType == (int)DataType.Structure)
                                 {
                                     GXByteBuffer bb = new GXByteBuffer((byte[])value);
                                     //Skip data type.
                                     bb.Position = 1;
                                     value       = Target.Comm.client.ChangeType(bb, (DataType)macro.DataType);
                                 }
                                 else
                                 {
                                     GXByteBuffer bb = new GXByteBuffer((byte[])value);
                                     value = Target.Comm.client.ChangeType(bb, (DataType)macro.DataType);
                                 }
                             }
                             if (macro.ObjectType == (int)ObjectType.ProfileGeneric && macro.Index == 2 && !string.IsNullOrEmpty(macro.External))
                             {
                                 Target.Comm.client.UpdateValue(obj, 3, GXDLMSTranslator.XmlToValue(macro.External));
                             }
                             Target.Comm.client.UpdateValue(obj, macro.Index, value);
                         }
                         if (SelectedView == null || SelectedView.Target.ObjectType != obj.ObjectType)
                         {
                             //SelectedView must remove from the controls.
                             ObjectPanelFrame.Controls.Clear();
                             if (Target == null)
                             {
                                 SelectedView = GXDlmsUi.GetView(Views, obj, Standard.DLMS);
                             }
                             else
                             {
                                 SelectedView = GXDlmsUi.GetView(Views, obj, Target.Comm.client.Standard);
                             }
                             SelectedView.Target = obj;
                             GXDlmsUi.ObjectChanged(SelectedView, obj, false);
                             SelectedView.OnDirtyChange(macro.Index, true);
                             ObjectPanelFrame.Controls.Add(((Form)SelectedView));
                             ((Form)SelectedView).Show();
                         }
                         else
                         {
                             SelectedView.Target = obj;
                             GXDlmsUi.ObjectChanged(SelectedView, obj, false);
                             SelectedView.OnDirtyChange(macro.Index, true);
                         }
                     }
                 }
             }
         }
         catch (Exception Ex)
         {
             GXDLMS.Common.Error.ShowError(this, Ex);
         }
     }
     else
     {
         OriginalDataTb.Text = "";
         if (GetMacros().Count == 0 && tabControl1.TabPages.Contains(VisualizedTab))
         {
             tabControl1.TabPages.Remove(VisualizedTab);
         }
     }
 }