示例#1
0
        public void SetDigitPlate(DigitPlate DigitPlate)
        {
            textBox1.Text = DigitPlate.Titl;
            textBox2.Text = "0x" + DigitPlate.StartAddr.ToString("X4");
            textBox3.Text = "0x" + DigitPlate.EventStructAddr.ToString("X4");

            ushort step = 1;

            for (int i = 0; i < 16; i++)
            {
                textBoxs[i].Text     = DigitPlate.DigitNames[i];
                checkBoxs[i].Checked = ((step & DigitPlate.UseMask) != 0);
                step = (ushort)(step << 1);
            }

            if (DigitPlate.DigitType == DigitType.DigInput)
            {
                radioButton1.Checked = true;
            }
            else
            {
                radioButton2.Checked = true;
            }

            if (DigitPlate.Invert)
            {
                radioButton4.Checked = true;
            }
            else
            {
                radioButton3.Checked = true;
            }
        }
 public DigitPlateSetupForm(DigitPlate DigitPlate, int Index)
 {
     InitializeComponent();
     digitPlate = DigitPlate;
     Text       = "Дискретный модуль №" + Index.ToString();
     digitPlateSetup1.SetDigitPlate(DigitPlate);
 }
        private void ChangeDigits(int Index1, int Index2)
        {
            DigitPlate dp1 = digitPlates[Index1].Copy();

            digitPlates[Index1] = digitPlates[Index2];
            digitPlates[Index2] = dp1;

            digitLabels[Index1].Text = digitPlates[Index1].Titl;
            digitLabels[Index2].Text = digitPlates[Index2].Titl;
        }
示例#4
0
        public bool GetDigitPlate(out DigitPlate DigitPlate)
        {
            bool       b          = true;
            DigitPlate digitPlate = new DigitPlate();

            digitPlate.Titl = textBox1.Text;

            try
            {
                short u = ConvertFuncs.StrToShort(textBox2.Text);
                digitPlate.StartAddr = (ushort)u;
            }
            catch
            {
                b = false;
            }

            try
            {
                short u = ConvertFuncs.StrToShort(textBox3.Text);
                digitPlate.EventStructAddr = (ushort)u;
            }
            catch
            {
                b = false;
            }

            ushort step  = 1;
            ushort value = 0;

            for (int i = 0; i < 16; i++)
            {
                digitPlate.DigitNames[i] = textBoxs[i].Text;
                if (checkBoxs[i].Checked)
                {
                    value = (ushort)(value | step);
                }
                step = (ushort)(step << 1);
            }

            digitPlate.UseMask = value;

            if (radioButton1.Checked)
            {
                digitPlate.DigitType = DigitType.DigInput;
            }
            else
            {
                digitPlate.DigitType = DigitType.DigOutput;
            }

            digitPlate.Invert = radioButton4.Checked;
            DigitPlate        = digitPlate;
            return(b);
        }
示例#5
0
        public DigitPlate Copy()
        {
            DigitPlate dp = new DigitPlate();

            dp.Titl            = this.Titl;
            dp.StartAddr       = this.startAddr;
            dp.EventStructAddr = this.EventStructAddr;
            dp.UseMask         = this.UseMask;
            dp.DigitNames      = this.DigitNames;
            dp.DigitType       = this.digitType;
            dp.Invert          = this.invert;
            return(dp);
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Внести изменения в профиль?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
     {
         DigitPlate dp;
         if (digitPlateSetup1.GetDigitPlate(out dp))
         {
             digitPlate   = dp;
             DialogResult = System.Windows.Forms.DialogResult.Yes;
         }
         else
         {
             MessageBox.Show("Неправильно заданы параметры!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
 }
        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!");
            }
        }
        private void loadOldStyleButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter     = appTexts.ParameterName(102);
            ofd.DefaultExt = "*.xml";

            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            XDocument document;
            XElement  element;
            int       digitCount;

            try
            {
                document = XDocument.Load(ofd.FileName);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            try
            {
                element    = document.Root.Element("Digits");
                digitCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            List <DigitPlate> loadDigitPlates = new List <DigitPlate>();

            for (int i = 0; i < digitCount; i++)
            {
                try
                {
                    element = document.Root.Element("Digit" + (i + 1).ToString());
                    string str1 = element.Attribute("Title").Value.ToString();
                    string str2 = element.Attribute("EventPos").Value.ToString();
                    string str3 = element.Attribute("Addr1").Value.ToString();
                    string str4 = element.Attribute("Type").Value.ToString();
                    string str5 = element.Attribute("Invert").Value.ToString();
                    string str6 = element.Attribute("UseMask").Value.ToString();

                    DigitPlate dp = new DigitPlate(str1);
                    dp.EventStructAddr = (ushort)ConvertFuncs.StrToShort(str2);
                    dp.StartAddr       = (ushort)(ConvertFuncs.StrToShort(str3) - 1);
                    if (str4 == "0")
                    {
                        dp.DigitType = DigitType.DigInput;
                    }
                    else
                    {
                        dp.DigitType = DigitType.DigOutput;
                    }
                    dp.Invert = (str5 != "0");

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

                    loadDigitPlates.Add(dp);
                }
                catch
                {
                    MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            DigitPlates = loadDigitPlates;
        }