public TimeConfig(XElement TimeXElement)
        {
            try
            {
                timeFormat = StringToTimeFormat(TimeXElement.Attribute("TimeFormat").Value);
            }
            catch
            {
                throw new Exception("Error time format!");
            }


            if (timeFormat == TimeFormats.STMFormat)
            {
                try
                {
                    STMProcAddr1 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr1").Value);
                    STMProcAddr2 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr2").Value);
                    STMProcAddr3 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr3").Value);
                    STMProcAddr4 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr4").Value);

                    STMProcAddr1_1 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr1_1").Value);
                    STMProcAddr2_1 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr2_1").Value);
                    STMProcAddr3_1 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr3_1").Value);
                    STMProcAddr4_1 = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("STMProcAddr4_1").Value);
                }
                catch
                {
                    throw new Exception("Error time format!");
                }
            }
            else if (timeFormat == TimeFormats.ADSPFormat)
            {
                try
                {
                    ReadAddr    = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("ReadAddr").Value);
                    SetAddr     = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("SetAddr").Value);
                    AddrSetTime = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("AddrSetTime").Value);
                }
                catch
                {
                    throw new Exception("Error time format!");
                }
            }
            else if (timeFormat == TimeFormats.RTCFormat)
            {
                try
                {
                    ReadAddr = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("ReadAddr").Value);
                    SetAddr  = ConvertFuncs.UInt16ToWord(TimeXElement.Attribute("SetAddr").Value);
                }
                catch
                {
                    throw new Exception("Error time format!");
                }
            }
        }
예제 #2
0
        public TimeConfig CalcTimeConfig()
        {
            TimeConfig timeConfig = new TimeConfig();

            if (radioButton1.Checked)
            {
                timeConfig.TimeFormat = TimeFormats.ADSPFormat;
            }
            else
            {
                timeConfig.TimeFormat = TimeFormats.RTCFormat;
            }

            if (timeConfig.TimeFormat == TimeFormats.ADSPFormat)
            {
                try
                {
                    timeConfig.ReadAddr    = ConvertFuncs.UInt16ToWord(textBox1.Text);
                    timeConfig.AddrSetTime = ConvertFuncs.UInt16ToWord(textBox2.Text);
                    timeConfig.SetAddr     = ConvertFuncs.UInt16ToWord(textBox3.Text);
                }
                catch
                {
                    throw new Exception("Error in addresses!");
                }
            }
            else if (timeConfig.TimeFormat == TimeFormats.RTCFormat)
            {
                try
                {
                    timeConfig.ReadAddr = ConvertFuncs.UInt16ToWord(textBox2_1.Text);
                    timeConfig.SetAddr  = ConvertFuncs.UInt16ToWord(textBox2_2.Text);
                }
                catch
                {
                    throw new Exception("Error in addresses!");
                }
            }
            return(timeConfig);
        }