Esempio n. 1
0
 private void browseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (tiaPortal != null)
     {
         if (browse_dialog == null)
         {
             browse_dialog         = new BrowseDialog(tiaPortal);
             browse_dialog.Descend = TIATree.ControllerOnly;
             browse_dialog.Leaf    = TIATree.SharedDBOnly;
             browse_dialog.AutoExpandMaxChildren = 1;
             browse_dialog.AcceptText            = "Select";
             browse_dialog.Text = "Browse TIA portal";
         }
         if (browse_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
         }
     }
 }
Esempio n. 2
0
        private void alarmDefsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tiaPortal != null)
            {
                if (folder_dialog == null)
                {
                    folder_dialog = new BrowseDialog(tiaPortal);
                    folder_dialog.Descend = TIATree.ControllerOnly;
                    folder_dialog.Leaf = (o => o is IBlockAggregation);
                    folder_dialog.AutoExpandMaxChildren = 1;
                    folder_dialog.AcceptText = "Generate";
                    folder_dialog.Text = "Select where to generate block";
                }
                if (folder_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (folder_dialog.SelectedObject is IBlockAggregation)
                    {
                        IBlockAggregation folder = (IBlockAggregation)folder_dialog.SelectedObject;
                        string filename = AlarmDB.buildFile(defs);

                        try
                        {
                            folder.Import(filename, ImportOptions.Override);
                        }
                        catch (Siemens.Engineering.EngineeringException ex)
                        {
                            MessageBox.Show(this, "Failed to import alarm definitions: " + ex.Message);
                            System.IO.File.Delete(filename);
                            return;
                        }

                        System.IO.File.Delete(filename);

                        // Move up the tree until we find a ControllerTarget
                        IEngineeringObject obj = folder.Parent;
                        while (!(obj is ControllerTarget))
                        {
                            obj = obj.Parent;
                            // Shouldn't happen, but just in case
                            if (obj == null)
                            {
                                MessageBox.Show(this, "No controller found as parent");
                                return;
                            }
                        }
                        ControllerTarget controller = (ControllerTarget)obj;
                        List<ConstTable.Constant> consts = new List<ConstTable.Constant>();
                        foreach (AlarmDefinition alarm in defs)
                        {
                            consts.Add(new ConstTable.Constant("Alarm" + alarm.Name, alarm.ID, alarm.Text));
                        }
                        filename = ConstTable.buildFile("Alarms", consts);
                        try
                        {
                            controller.ControllerTagFolder.TagTables.Import(filename, ImportOptions.Override);
                        }
                        catch (Siemens.Engineering.EngineeringException ex)
                        {
                            MessageBox.Show(this, "Failed to import constants: " + ex.Message);
                            System.IO.File.Delete(filename);
                            return;
                        }

                        System.IO.File.Delete(filename);
                    }
                }

            }
        }
Esempio n. 3
0
        private void extractAlarmDefsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tiaPortal != null)
              {
                  if (data_block_dialog == null)
                  {
                      data_block_dialog = new BrowseDialog(tiaPortal);
                      data_block_dialog.Descend = TIATree.ControllerOnly;
                      data_block_dialog.Leaf = TIATree.SharedDBOnly;
                      data_block_dialog.AutoExpandMaxChildren = 1;
                      data_block_dialog.AcceptText = "Extract";
                      data_block_dialog.Text = "Select alarm data block";
                  }
                  if (data_block_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                  {
                      if (data_block_dialog.SelectedObject is DataBlock)
                      {
                          DataBlock block = (DataBlock)data_block_dialog.SelectedObject;
                          try
                          {

                              // Extract from data base
                              string filename = TempFile.Name("AlarmDB", "xml");

                              block.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                              alarmList.DataSource = null;
                              AlarmDB.parseFile(defs, filename);
                              System.IO.File.Delete(filename);

                              // Extract from constant tags
                              // Move up the tree until we find a ControllerTarget
                              IEngineeringObject obj = (block as IEngineeringObject).Parent;
                              while (!(obj is ControllerTarget))
                              {
                                  obj = obj.Parent;
                                  // Shouldn't happen, but just in case
                                  if (obj == null)
                                  {
                                      MessageBox.Show(this, "No controller found as parent");
                                      return;
                                  }
                              }
                              ControllerTarget controller = (ControllerTarget)obj;
                              List<ConstTable.Constant> consts = new List<ConstTable.Constant>();

                              ControllerTagTable table = controller.ControllerTagFolder.TagTables.Find("Alarms");
                              if (table == null)
                              {
                                  MessageBox.Show(this, "No tag table named Alarms was found");
                              }
                              else
                              {
                                  filename = TempFile.Name("ConstantTags", "xml");
                                  Console.WriteLine("Wrote to " + filename);
                                  table.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                                  List<ConstTable.Constant> constants = ConstTable.getConstants(filename);
                                  foreach (ConstTable.Constant c in constants)
                                  {
                                      if (c.Name.StartsWith("Alarm") && c.Value is int)
                                      {
                                          AlarmDefinition a = defs.FindByID((int)c.Value);
                                          if (a != null)
                                          {
                                              a.Name = c.Name.Substring(5);
                                          }
                                      }
                                  }
                              }
                              defs.ValidateID();

                              alarmList.AutoGenerateColumns = false;
                              alarmList.DataSource = defs;
                          }
                          catch (Exception ex)
                          {
                              MessageBox.Show("Failed to extract alarm definitions: " + ex.Message);
                          }

                      }
                  }
              }
        }
Esempio n. 4
0
 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     tiaPortal.Dispose();
     tiaPortal = null;
     folder_dialog = null;
     data_block_dialog = null;
     browse_dialog = null;
     connectToolStripMenuItem.Enabled = true;
     disconnectToolStripMenuItem.Enabled = false;
 }
Esempio n. 5
0
 private void browseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (tiaPortal != null)
       {
           if (browse_dialog == null)
           {
               browse_dialog = new BrowseDialog(tiaPortal);
               browse_dialog.Descend = TIATree.ControllerOnly;
               browse_dialog.Leaf = TIATree.SharedDBOnly;
               browse_dialog.AutoExpandMaxChildren = 1;
               browse_dialog.AcceptText = "Select";
               browse_dialog.Text = "Browse TIA portal";
           }
           if (browse_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
           {
           }
       }
 }
Esempio n. 6
0
        private void extractAlarmDefsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tiaPortal != null)
            {
                if (data_block_dialog == null)
                {
                    data_block_dialog         = new BrowseDialog(tiaPortal);
                    data_block_dialog.Descend = TIATree.ControllerOnly;
                    data_block_dialog.Leaf    = TIATree.SharedDBOnly;
                    data_block_dialog.AutoExpandMaxChildren = 1;
                    data_block_dialog.AcceptText            = "Extract";
                    data_block_dialog.Text = "Select alarm data block";
                }
                if (data_block_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (data_block_dialog.SelectedObject is DataBlock)
                    {
                        DataBlock block = (DataBlock)data_block_dialog.SelectedObject;
                        try
                        {
                            // Extract from data base
                            string filename = TempFile.Name("AlarmDB", "xml");

                            block.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                            alarmList.DataSource = null;
                            AlarmDB.parseFile(defs, filename);
                            System.IO.File.Delete(filename);

                            // Extract from constant tags
                            // Move up the tree until we find a ControllerTarget
                            IEngineeringObject obj = (block as IEngineeringObject).Parent;
                            while (!(obj is ControllerTarget))
                            {
                                obj = obj.Parent;
                                // Shouldn't happen, but just in case
                                if (obj == null)
                                {
                                    MessageBox.Show(this, "No controller found as parent");
                                    return;
                                }
                            }
                            ControllerTarget           controller = (ControllerTarget)obj;
                            List <ConstTable.Constant> consts     = new List <ConstTable.Constant>();

                            ControllerTagTable table = controller.ControllerTagFolder.TagTables.Find("Alarms");
                            if (table == null)
                            {
                                MessageBox.Show(this, "No tag table named Alarms was found");
                            }
                            else
                            {
                                filename = TempFile.Name("ConstantTags", "xml");
                                Console.WriteLine("Wrote to " + filename);
                                table.Export(filename, ExportOptions.WithDefaults | ExportOptions.WithReadOnly);
                                List <ConstTable.Constant> constants = ConstTable.getConstants(filename);
                                foreach (ConstTable.Constant c in constants)
                                {
                                    if (c.Name.StartsWith("Alarm") && c.Value is int)
                                    {
                                        AlarmDefinition a = defs.FindByID((int)c.Value);
                                        if (a != null)
                                        {
                                            a.Name = c.Name.Substring(5);
                                        }
                                    }
                                }
                            }
                            defs.ValidateID();

                            alarmList.AutoGenerateColumns = false;
                            alarmList.DataSource          = defs;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Failed to extract alarm definitions: " + ex.Message);
                        }
                    }
                }
            }
        }
Esempio n. 7
0
        private void alarmDefsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tiaPortal != null)
            {
                if (folder_dialog == null)
                {
                    folder_dialog         = new BrowseDialog(tiaPortal);
                    folder_dialog.Descend = TIATree.ControllerOnly;
                    folder_dialog.Leaf    = (o => o is IBlockAggregation);
                    folder_dialog.AutoExpandMaxChildren = 1;
                    folder_dialog.AcceptText            = "Generate";
                    folder_dialog.Text = "Select where to generate block";
                }
                if (folder_dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (folder_dialog.SelectedObject is IBlockAggregation)
                    {
                        IBlockAggregation folder   = (IBlockAggregation)folder_dialog.SelectedObject;
                        string            filename = AlarmDB.buildFile(defs);

                        try
                        {
                            folder.Import(filename, ImportOptions.Override);
                        }
                        catch (Siemens.Engineering.EngineeringException ex)
                        {
                            MessageBox.Show(this, "Failed to import alarm definitions: " + ex.Message);
                            System.IO.File.Delete(filename);
                            return;
                        }

                        System.IO.File.Delete(filename);

                        // Move up the tree until we find a ControllerTarget
                        IEngineeringObject obj = folder.Parent;
                        while (!(obj is ControllerTarget))
                        {
                            obj = obj.Parent;
                            // Shouldn't happen, but just in case
                            if (obj == null)
                            {
                                MessageBox.Show(this, "No controller found as parent");
                                return;
                            }
                        }
                        ControllerTarget           controller = (ControllerTarget)obj;
                        List <ConstTable.Constant> consts     = new List <ConstTable.Constant>();
                        foreach (AlarmDefinition alarm in defs)
                        {
                            consts.Add(new ConstTable.Constant("Alarm" + alarm.Name, alarm.ID, alarm.Text));
                        }
                        filename = ConstTable.buildFile("Alarms", consts);
                        try
                        {
                            controller.ControllerTagFolder.TagTables.Import(filename, ImportOptions.Override);
                        }
                        catch (Siemens.Engineering.EngineeringException ex)
                        {
                            MessageBox.Show(this, "Failed to import constants: " + ex.Message);
                            System.IO.File.Delete(filename);
                            return;
                        }

                        System.IO.File.Delete(filename);
                    }
                }
            }
        }