예제 #1
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (GXByteBuffer.IsAsciiString(Identification))
            {
                sb.Append(ASCIIEncoding.ASCII.GetString(Identification));
            }
            else
            {
                sb.Append(Internal.GXCommon.ToHex(Identification, false));
            }
            sb.Append(" ");
            if (GXByteBuffer.IsAsciiString(Signature))
            {
                sb.Append(ASCIIEncoding.ASCII.GetString(Signature));
            }
            else
            {
                sb.Append(Internal.GXCommon.ToHex(Signature, false));
            }
            sb.Append(" ");
            sb.Append(Convert.ToString(Size));
            return(sb.ToString());
        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (GXByteBuffer.IsAsciiString(Name))
            {
                sb.Append(ASCIIEncoding.ASCII.GetString(Name));
            }
            else
            {
                sb.Append(GXDLMSTranslator.ToHex(Name));
            }
            sb.Append(' ');
            sb.Append(Start.ToFormatString());
            sb.Append(' ');
            if (GXByteBuffer.IsAsciiString(WeekName))
            {
                sb.Append(ASCIIEncoding.ASCII.GetString(WeekName));
            }
            else
            {
                sb.Append(GXDLMSTranslator.ToHex(WeekName));
            }
            return(sb.ToString());
        }
        public void OnValueChanged(GXDLMSViewArguments arg)
        {
            GXDLMSImageTransfer target = Target as GXDLMSImageTransfer;

            if (arg.Index == 3)
            {
                ImageTransferredBlocksStatusTB.Text = (string)arg.Value;
            }
            else if (arg.Index == 5)
            {
                ImageTransferEnabledCB.CheckedChanged -= new System.EventHandler(ImageTransferEnabledCB_CheckedChanged);
                ImageTransferEnabledCB.Checked         = target.ImageTransferEnabled;
                ImageTransferEnabledCB.CheckedChanged += new System.EventHandler(ImageTransferEnabledCB_CheckedChanged);
            }
            else if (arg.Index == 6)
            {
                ImageTransferStatusTb.Text = target.ImageTransferStatus.ToString();
                ManualBtn_CheckedChanged(null, null);
            }
            else if (arg.Index == 7)
            {
                ImagesView.Items.Clear();
                if (target.ImageActivateInfo != null)
                {
                    foreach (GXDLMSImageActivateInfo it in target.ImageActivateInfo)
                    {
                        ListViewItem li = ImagesView.Items.Add(it.Size.ToString());
                        if (GXByteBuffer.IsAsciiString(it.Identification))
                        {
                            li.SubItems.Add(ASCIIEncoding.ASCII.GetString(it.Identification));
                        }
                        else
                        {
                            li.SubItems.Add(GXDLMSTranslator.ToHex(it.Identification));
                        }
                        if (GXByteBuffer.IsAsciiString(it.Signature))
                        {
                            li.SubItems.Add(ASCIIEncoding.ASCII.GetString(it.Signature));
                        }
                        else
                        {
                            li.SubItems.Add(GXDLMSTranslator.ToHex(it.Signature));
                        }
                        li.Tag = it;
                    }
                }
            }
            else if (arg.Index != 0)
            {
                throw new IndexOutOfRangeException("index");
            }
        }
예제 #4
0
 /// <summary>
 /// Browse image.
 /// </summary>
 private void BrowseBtn_Click(object sender, EventArgs e)
 {
     try
     {
         OpenFileDialog dlg = new OpenFileDialog();
         dlg.Multiselect = false;
         if (FileNameTb.Text != "")
         {
             dlg.InitialDirectory = Path.GetDirectoryName(FileNameTb.Text);
             dlg.FileName         = FileNameTb.Text;
         }
         else
         {
             dlg.InitialDirectory = Directory.GetCurrentDirectory();
         }
         dlg.Filter        = Properties.Resources.ImageFilesTxt;
         dlg.DefaultExt    = ".bin";
         dlg.ValidateNames = true;
         if (dlg.ShowDialog(this) == DialogResult.OK)
         {
             FileNameTb.Text = dlg.FileName;
         }
         if (IdentificationTb.Text == "")
         {
             if (string.Compare(Path.GetExtension(FileNameTb.Text), ".xml", true) == 0)
             {
                 XmlDocument doc = new XmlDocument();
                 doc.Load(FileNameTb.Text);
                 byte[] arr = GetIdentification(doc.ChildNodes);
                 if (GXByteBuffer.IsAsciiString(arr))
                 {
                     IdentificationTb.Text = ASCIIEncoding.ASCII.GetString(arr);
                 }
                 else
                 {
                     IdentificationTb.Text = GXDLMSTranslator.ToHex(arr);
                 }
             }
             else
             {
                 IdentificationTb.Text = Path.GetFileNameWithoutExtension(dlg.FileName);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #5
0
 public GXByteEditor(byte[] value)
 {
     InitializeComponent();
     if (value != null)
     {
         if (GXByteBuffer.IsAsciiString(value))
         {
             ValueTb.Text    = ASCIIEncoding.ASCII.GetString(value);
             AsciiCb.Checked = true;
         }
         else
         {
             ValueTb.Text = Gurux.Common.GXCommon.ToHex(value);
         }
     }
 }
        public GXSecuritySetupKeyDlg(int version)
        {
            InitializeComponent();
            GlobalKeyType type = (GlobalKeyType)Properties.Settings.Default.SecurityType;

            foreach (GlobalKeyType it in Enum.GetValues(typeof(GlobalKeyType)))
            {
                if (version == 0 && it == GlobalKeyType.Kek)
                {
                    break;
                }
                SecurityPolicyTB.Items.Add(it);
                if (it == type)
                {
                    SecurityPolicyTB.SelectedItem = it;
                }
            }
            byte[] key = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.SecurityKey);
            if (key != null)
            {
                if (GXByteBuffer.IsAsciiString(key))
                {
                    KeyTb.Text         = ASCIIEncoding.ASCII.GetString(key);
                    KeyAsciiCb.Checked = true;
                }
                else
                {
                    KeyTb.Text = GXDLMSTranslator.ToHex(key);
                }
            }
            //Update KEK.
            key = GXDLMSTranslator.HexToBytes(Properties.Settings.Default.SecurityKek);
            if (key != null)
            {
                if (GXByteBuffer.IsAsciiString(key))
                {
                    KekTb.Text         = ASCIIEncoding.ASCII.GetString(key);
                    KekAsciiCb.Checked = true;
                }
                else
                {
                    KekTb.Text = GXDLMSTranslator.ToHex(key);
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Converts given object to given type.
 /// </summary>
 /// <param name="context">An ITypeDescriptorContext that provides a format context.</param>
 /// <param name="culture">Culture info.</param>
 /// <param name="value">The object to convert.</param>
 /// <param name="destType">The type to convert to.</param>
 /// <returns>Converted type of the object.</returns>
 public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destType)
 {
     try
     {
         if (value is byte[])
         {
             if (GXByteBuffer.IsAsciiString((byte[])value))
             {
                 return(ASCIIEncoding.ASCII.GetString((byte[])value));
             }
             else
             {
                 return(Gurux.Common.GXCommon.ToHex((byte[])value));
             }
         }
         return(base.ConvertTo(context, culture, value, destType));
     }
     catch (Exception Ex)
     {
         MessageBox.Show(Ex.Message);
     }
     return(null);
 }
 void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
 {
     if (e.Index == 1)
     {
         LogicalName = GXCommon.ToLogicalName(e.Value);
     }
     else if (e.Index == 2)
     {
         if (e.Value is byte[] v)
         {
             if (IsSec() || !GXByteBuffer.IsAsciiString(v))
             {
                 CalendarNameActive = GXCommon.ToHex(v, false);
             }
             else
             {
                 CalendarNameActive = ASCIIEncoding.ASCII.GetString(v);
             }
         }
         else
         {
             CalendarNameActive = Convert.ToString(e.Value);
         }
     }
     else if (e.Index == 3)
     {
         SeasonProfileActive = SetSeasonProfile(settings, e.Value);
     }
     else if (e.Index == 4)
     {
         WeekProfileTableActive = SetWeekProfileTable(settings, e.Value);
     }
     else if (e.Index == 5)
     {
         DayProfileTableActive = SetDayProfileTable(settings, e.Value);
     }
     else if (e.Index == 6)
     {
         if (e.Value is byte[] v)
         {
             if (IsSec() || !GXByteBuffer.IsAsciiString(v))
             {
                 CalendarNamePassive = GXCommon.ToHex(v, false);
             }
             else
             {
                 CalendarNamePassive = ASCIIEncoding.ASCII.GetString(v);
             }
         }
         else
         {
             CalendarNamePassive = Convert.ToString(e.Value);
         }
     }
     else if (e.Index == 7)
     {
         SeasonProfilePassive = SetSeasonProfile(settings, e.Value);
     }
     else if (e.Index == 8)
     {
         WeekProfileTablePassive = SetWeekProfileTable(settings, e.Value);
     }
     else if (e.Index == 9)
     {
         DayProfileTablePassive = SetDayProfileTable(settings, e.Value);
     }
     else if (e.Index == 10)
     {
         if (e.Value is byte[])
         {
             Time = (GXDateTime)GXDLMSClient.ChangeType((byte[])e.Value, DataType.DateTime, settings.UseUtc2NormalTime);
         }
         else if (e.Value is GXDateTime)
         {
             Time = (GXDateTime)e.Value;
         }
         else
         {
             Time = new GXDateTime(Convert.ToDateTime(e.Value));
         }
     }
     else
     {
         e.Error = ErrorCode.ReadWriteDenied;
     }
 }
예제 #9
0
        void IGXDLMSBase.SetValue(GXDLMSSettings settings, ValueEventArgs e)
        {
            switch (e.Index)
            {
            case 1:
                LogicalName = GXCommon.ToLogicalName(e.Value);
                break;

            case 2:
                if (e.Value is byte[])
                {
                    if (GXByteBuffer.IsAsciiString((byte[])e.Value))
                    {
                        CalendarName = ASCIIEncoding.ASCII.GetString((byte[])e.Value);
                    }
                    else
                    {
                        CalendarName = GXCommon.ToHex((byte[])e.Value, true);
                    }
                }
                else
                {
                    CalendarName = Convert.ToString(e.Value);
                }
                break;

            case 3:
                Enabled = Convert.ToBoolean(e.Value);
                break;

            case 4:
            {
                if (e.Value is List <object> )
                {
                    List <object> it = e.Value as List <object>;
                    Plan.DefaultTariffBand = Convert.ToByte(it[0]);
                    UpdateSeason(Plan.WinterSeason, (it[1] as List <object>)[0] as List <object>);
                    UpdateSeason(Plan.SummerSeason, (it[1] as List <object>)[1] as List <object>);
                    Plan.WeeklyActivation = Convert.ToString(it[2]);
                    List <UInt16> days = new List <ushort>();
                    foreach (UInt16 v in (List <object>)it[3])
                    {
                        days.Add(v);
                    }
                    Plan.SpecialDays = days.ToArray();
                }

                break;
            }

            case 5:
            {
                if (e.Value is List <object> )
                {
                    List <object> it   = e.Value as List <object>;
                    GXDateTime    time = (GXDateTime)it[0];
                    time.Skip &= ~(DateTimeSkips.Year | DateTimeSkips.Month | DateTimeSkips.Day | DateTimeSkips.DayOfWeek);
                    GXDateTime date = (GXDateTime)it[1];
                    date.Skip           &= ~(DateTimeSkips.Hour | DateTimeSkips.Minute | DateTimeSkips.Second | DateTimeSkips.Ms);
                    ActivationTime       = new DLMS.GXDateTime(date);
                    ActivationTime.Value = ActivationTime.Value.AddHours(time.Value.Hour);
                    ActivationTime.Value = ActivationTime.Value.AddMinutes(time.Value.Minute);
                    ActivationTime.Value = ActivationTime.Value.AddSeconds(time.Value.Second);
                    ActivationTime.Skip  = date.Skip | time.Skip;
                }
                else if (e.Value is string)
                {
                    ActivationTime = new GXDateTime((string)e.Value);
                }
                else
                {
                    ActivationTime = new GXDateTime(DateTime.MinValue);
                }

                break;
            }

            default:
                e.Error = ErrorCode.ReadWriteDenied;
                break;
            }
        }