예제 #1
0
        private void timeLabelButton_ButtonClick(object sender, EventArgs e)
        {
            TimeConfiguratorForm timeConfigForm = new TimeConfiguratorForm(systemConfiguration.TimeConfig);

            if (timeConfigForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                TimeConfig t = new TimeConfig();
                try
                {
                    t = timeConfigForm.CalcTimeConfig();
                }
                catch
                {
                    MessageBox.Show("Неправильно заданы адреса!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                systemConfiguration.TimeConfig = t;
            }
        }
예제 #2
0
        public TimeConfiguratorForm(TimeConfig TimeConfig)
        {
            InitializeComponent();
            if (TimeConfig.TimeFormat == TimeFormats.ADSPFormat)
            {
                radioButton1.Checked = true;
                stmPanel.Visible     = false;
                textBox1.Text        = "0x" + TimeConfig.ReadAddr.ToString("X4");
                textBox2.Text        = "0x" + TimeConfig.AddrSetTime.ToString("X4");
                textBox3.Text        = "0x" + TimeConfig.SetAddr.ToString("X4");
            }
            else if (TimeConfig.TimeFormat == TimeFormats.RTCFormat)
            {
                radioButton2.Checked = true;
                adspPanel.Visible    = false;

                textBox2_1.Text = "0x" + TimeConfig.ReadAddr.ToString("X4");
                textBox2_2.Text = "0x" + TimeConfig.SetAddr.ToString("X4");
            }
        }
예제 #3
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);
        }
        public static void SendSetTimeRequest(SerialDataProvider SerialPort, TimeConfig CurrentConfig, int Hour, int Min, int Sec, int Day, int Month, int Year)
        {
            if (CurrentConfig.TimeFormat == TimeFormats.STMFormat)
            {
                ushort[] paramRTU = new ushort[4];
                paramRTU[0] = (ushort)(((Month.ToBCD() & 0x1F) << 8) | (Day.ToBCD() & 0x3F));
                paramRTU[1] = (ushort)Year.ToBCD();
                paramRTU[2] = (ushort)(((Min.ToBCD() & 0xFF) << 8) | (Sec.ToBCD() & 0xFF));
                paramRTU[3] = (ushort)(Hour.ToBCD() | 0x0100);
                SerialPort.SetData(1, CurrentConfig.STMProcAddr1_1, null, paramRTU);
            }
            else if (CurrentConfig.TimeFormat == TimeFormats.ADSPFormat)
            {
                ushort[] paramRTU = new ushort[3];
                paramRTU[0] = Sec.ToBCD();
                paramRTU[1] = Min.ToBCD();
                paramRTU[2] = Hour.ToBCD();
                SerialPort.SetData(1, CurrentConfig.SetAddr, null, paramRTU);

                paramRTU[0] = Day.ToBCD();
                paramRTU[1] = Month.ToBCD();
                paramRTU[2] = Year.ToBCD();
                SerialPort.SetData(1, (ushort)(CurrentConfig.SetAddr + 4), null, paramRTU);

                SerialPort.SetData(1, CurrentConfig.AddrSetTime, null, 1);
            }
            else if (CurrentConfig.TimeFormat == TimeFormats.RTCFormat)
            {
                ushort[] paramRTU = new ushort[4];
                paramRTU[0] = (ushort)(((Month.ToBCD() & 0x1F) << 8) | (Day.ToBCD() & 0x3F));
                paramRTU[1] = (ushort)Year.ToBCD();
                paramRTU[2] = (ushort)(((Min.ToBCD() & 0x7F) << 8) | (Sec.ToBCD() & 0x7F));
                paramRTU[3] = (ushort)(Hour.ToBCD() & 0x3F);
                SerialPort.SetData(1, CurrentConfig.SetAddr, null, paramRTU);
            }
        }
        void OpenFileBody(string FileName)
        {
            XDocument document;

            try
            {
                document = XDocument.Load(FileName);
            }
            catch
            {
                throw new Exception("Error open xml file!");
            }
            digitPlates = new List <DigitPlate>();

            int digitCount = 0;

            try
            {
                XElement element = document.Root.Element("Digits");
                digitCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                digitCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }

            for (int i = 0; i < digitCount; i++)
            {
                try
                {
                    XElement   element = document.Root.Element("Digit" + (i + 1).ToString());
                    DigitPlate dp      = new DigitPlate();
                    dp.Titl = element.Attribute("Title").Value;


                    if (element.Attribute("Type").Value == "DigInput")
                    {
                        dp.DigitType = DigitType.DigInput;
                    }
                    else
                    {
                        dp.DigitType = DigitType.DigOutput;
                    }

                    if (element.Attribute("Invert").Value.ToString().ToUpper() == "TRUE")
                    {
                        dp.Invert = true;
                    }
                    else
                    {
                        dp.Invert = false;
                    }


                    dp.StartAddr       = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    dp.EventStructAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventPos").Value.ToString());

                    dp.UseMask = Convert.ToUInt16(element.Attribute("UseMask").Value, 10);
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.DigitNames[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }



                    digitPlates.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Digit" + (i + 1).ToString() + " of xml file!");
                }
            }


            int measureCount = 0;

            measureParams = new List <MeasureParam>();
            try
            {
                XElement element = document.Root.Element("MeasureParams");
                measureCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                measureCount = 0;
                //throw new Exception("Errors in part MeasureParams of xml file!");
            }

            for (int i = 0; i < measureCount; i++)
            {
                try
                {
                    XElement element = document.Root.Element("MeasureParam" + (i + 1).ToString());
                    string   str1, str2, str3;
                    str1 = element.Attribute("Name").Value;
                    str2 = element.Attribute("Addr").Value;
                    str3 = element.Attribute("Format").Value;

                    MeasureParam dp = new MeasureParam(str1, str2, str3);
                    measureParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part MeasureParam" + (i + 1).ToString() + " of xml file!");
                }
            }

            int eventCount = 0;

            eventCodes = new Hashtable();
            try
            {
                XElement element = document.Root.Element("EventCodes");
                eventCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                eventCount = 0;
                //throw new Exception("Errors in part MeasureParams of xml file!");
            }


            for (int i = 0; i < eventCount; i++)
            {
                try
                {
                    XElement element = document.Root.Element("EventCode" + (i + 1).ToString());
                    string   str1, str2;
                    str1 = element.Attribute("Name").Value;
                    str2 = element.Attribute("Code").Value;
                    eventCodes.Add(str2, str1);
                }
                catch
                {
                    throw new Exception("Errors in part EventCode" + (i + 1).ToString() + " of xml file!");
                }
            }

            try
            {
                XElement element = document.Root.Element("OtherParams");
                StartMeasureAddr  = (ushort)ConvertFuncs.StrToShort(element.Attribute("StartMeasureAddr").Value.ToString());
                EventCodeAddr     = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventCodeAddr").Value.ToString());
                EventTimeAddr     = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventTimeAddr").Value.ToString());
                EventBlockCount   = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventBlockCount").Value.ToString());
                LoadEventAddr     = (ushort)ConvertFuncs.StrToShort(element.Attribute("LoadEventAddr").Value.ToString());
                LoadEventDataAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("LoadEventDataAddr").Value.ToString());
                EventCount        = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventCount").Value.ToString());
            }
            catch
            {
                //eventCount = 0;
                throw new Exception("Errors in part OtherParams of xml file!");
            }

            XElement otherelements = document.Root.Element("OtherParams");

            if (otherelements.Attribute("EnaDigits") == null)
            {
                EnaDigits = false;
            }
            else
            {
                EnaDigits = otherelements.Attribute("EnaDigits").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaDirectAccess") == null)
            {
                EnaDirectAccess = false;
            }
            else
            {
                EnaDirectAccess = otherelements.Attribute("EnaDirectAccess").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaFloatDirectAccess") == null)
            {
                EnaFloatDirectAccess = false;
            }
            else
            {
                EnaFloatDirectAccess = otherelements.Attribute("EnaFloatDirectAccess").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaScope") == null)
            {
                EnaScope = false;
            }
            else
            {
                EnaScope = otherelements.Attribute("EnaScope").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaEventLog") == null)
            {
                EnaEventLog = false;
            }
            else
            {
                EnaEventLog = otherelements.Attribute("EnaEventLog").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaLoadSyms") == null)
            {
                EnaLoadSyms = false;
            }
            else
            {
                EnaLoadSyms = otherelements.Attribute("EnaLoadSyms").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaJog") == null)
            {
                EnaJog = false;
            }
            else
            {
                EnaJog = otherelements.Attribute("EnaJog").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaAngle") == null)
            {
                EnaAngle = false;
            }
            else
            {
                EnaAngle = otherelements.Attribute("EnaAngle").Value.ToBoolean();
            }

            if (otherelements.Attribute("EnaForceDig") == null)
            {
                EnaForceDig = false;
            }
            else
            {
                EnaForceDig = otherelements.Attribute("EnaForceDig").Value.ToBoolean();
            }



            /*
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaDigits").Value;
             *             EnaDigits = (o != null);
             *         }
             *         catch
             *         {
             *             EnaDigits = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaDirectAccess").Value;
             *             EnaDirectAccess = (o != null);
             *         }
             *         catch
             *         {
             *             EnaDirectAccess = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaFloatDirectAccess").Value;
             *             EnaFloatDirectAccess = (o != null);
             *         }
             *         catch
             *         {
             *             EnaFloatDirectAccess = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaScope").Value;
             *             EnaScope = (o != null);
             *         }
             *         catch
             *         {
             *             EnaScope = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaEventLog").Value;
             *             EnaEventLog = (o != null);
             *         }
             *         catch
             *         {
             *             EnaEventLog = false;
             *         }
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaLoadSyms").Value;
             *             EnaLoadSyms = (o != null);
             *         }
             *         catch
             *         {
             *             EnaLoadSyms = false;
             *         }
             *
             */


            int readyCount = 0;

            try
            {
                XElement element = document.Root.Element("Readys");
                readyCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                readyCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }


            for (int i = 0; i < readyCount; i++)
            {
                try
                {
                    XElement     element = document.Root.Element("Ready" + (i + 1).ToString());
                    WarningParam dp      = new WarningParam(element.Attribute("Title").Value.ToString());
                    dp.Titl = element.Attribute("Title").Value;



                    dp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.Names[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }


                    readyParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Ready" + (i + 1).ToString() + " of xml file!");
                }
            }


            int warningCount = 0;

            try
            {
                XElement element = document.Root.Element("Warnings");
                warningCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                warningCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }


            for (int i = 0; i < warningCount; i++)
            {
                try
                {
                    XElement     element = document.Root.Element("Warning" + (i + 1).ToString());
                    WarningParam dp      = new WarningParam(element.Attribute("Title").Value.ToString());
                    dp.Titl = element.Attribute("Title").Value;



                    dp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.Names[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }


                    warningParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Warning" + (i + 1).ToString() + " of xml file!");
                }
            }


            int alarmCount = 0;

            try
            {
                XElement element = document.Root.Element("Alarms");
                alarmCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                alarmCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }


            for (int i = 0; i < alarmCount; i++)
            {
                try
                {
                    XElement     element = document.Root.Element("Alarm" + (i + 1).ToString());
                    WarningParam dp      = new WarningParam(element.Attribute("Title").Value.ToString());
                    dp.Titl = element.Attribute("Title").Value;

                    dp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.Names[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }


                    alarmParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Alarm" + (i + 1).ToString() + " of xml file!");
                }
            }



            try
            {
                XElement element = document.Root.Element("TimeSettings");
                timeConfig = new TimeConfig(element);
            }

            catch
            {
                throw new Exception("Errors in part TimeSettings of xml file!");
            }
        }
 public static void SendReadTimeRequest(byte SlaveAddr, SerialDataProvider SerialPort, Action <bool, ushort[]> DataRecieved, TimeConfig CurrentConfig)
 {
     if (CurrentConfig.TimeFormat == TimeFormats.STMFormat)
     {
         SerialPort.GetData(SlaveAddr, CurrentConfig.STMProcAddr1, 4, DataRecieved);
     }
     else if (CurrentConfig.TimeFormat == TimeFormats.ADSPFormat)
     {
         SerialPort.GetData(SlaveAddr, CurrentConfig.ReadAddr, 7, DataRecieved);
     }
     else if (CurrentConfig.TimeFormat == TimeFormats.RTCFormat)
     {
         SerialPort.GetData(SlaveAddr, CurrentConfig.ReadAddr, 4, DataRecieved);
     }
 }
 public static void SendReadTimeRequest(byte SlaveAddr, AsynchSerialPort SerialPort, AsynchSerialPort.DataRecievedRTU DataRecieved, TimeConfig CurrentConfig)
 {
     if (CurrentConfig.TimeFormat == TimeFormats.STMFormat)
     {
         SerialPort.GetDataRTU(SlaveAddr, CurrentConfig.STMProcAddr1, 4, DataRecieved, RequestPriority.Normal);
     }
     else if (CurrentConfig.TimeFormat == TimeFormats.ADSPFormat)
     {
         SerialPort.GetDataRTU(SlaveAddr, CurrentConfig.ReadAddr, 7, DataRecieved, RequestPriority.Normal);
     }
     else if (CurrentConfig.TimeFormat == TimeFormats.RTCFormat)
     {
         SerialPort.GetDataRTU(SlaveAddr, CurrentConfig.ReadAddr, 4, DataRecieved, RequestPriority.Normal);
     }
 }
 public static string ExtractTimeFromArray(ushort[] ParamRTU, TimeConfig CurrentConfig, int Index = 0)
 {
     return(ExtractTimeFromArray(ParamRTU, CurrentConfig.timeFormat, Index));
 }