public void Run(IEditorApplication context, IBehavior behavior)
 {
     try
     {
         frmDescription frm = new frmDescription("Editor", "Wizard", context.Name);
         frm.ShowDialog();
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
 }
 public void Start(IEditorApplication context, IBehavior behavior)
 {
     try
     {
         frmDescription frm = new frmDescription("Editor", "Service", context.Name);
         frm.Show();
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show(ex.Message);
     }
 }
Пример #3
0
        private void ImportVars(IEditorApplication context, IBehavior behavior)
        {
            IVariableCollection variableCollection = context.Workspace.ActiveProject.VariableCollection;


            frmDescription frmSelection = new frmDescription();

            if (frmSelection.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                variableCollection = context.Workspace.ActiveProject.VariableCollection;

                //Displays all variable names in the zenon editor
                foreach (IVariable variable in variableCollection)
                {
                    context.DebugPrint("Variable name: " + variable.Name + " / Channel: " + variable.DataBlock, DebugPrintStyle.Standard);
                }

                IDataType myDatatype = context.Workspace.ActiveProject.DataTypeCollection["REAL"];

                // Treiber mappen
                IDriverCollection driverCollection = context.Workspace.ActiveProject.DriverCollection;

                if (driverCollection == null || driverCollection.Count < 1)
                {
                    return;
                }

                IDriver sel_driver = null;
                //Displays all available drivers in zenon
                foreach (IDriver driver in driverCollection)
                {
                    if (driver.Name == "S7TCP32")
                    {
                        sel_driver = driver;
                        context.DebugPrint("Driver ausgewäht = " + sel_driver.Name, DebugPrintStyle.Standard);
                    }
                }

                #region Numerisch
                //Einlesen von CSV für numerische Variablen
                List <GTINumVal> GTINumValues = new List <GTINumVal>();
                try
                {
                    context.DebugPrint("Einlesen von: " + frmSelection.file_numeric, DebugPrintStyle.Standard);
                    GTINumValues = ReadCSV(frmSelection.file_numeric);
                }
                catch (Exception creationException)
                {
                    context.DebugPrint("Reading CSV error: " + creationException.Message, DebugPrintStyle.Error);
                    return;
                }
                if (GTINumValues.Count < 1)
                {
                    context.DebugPrint("Reading CSV error", DebugPrintStyle.Error);
                    return;
                }

                foreach (GTINumVal tempVal in GTINumValues)
                {
                    string myVariableName = tempVal.Name;

                    // Jetzt werden die Variablen erstellt
                    if (variableCollection[myVariableName] == null)
                    {
                        try
                        {
                            switch (tempVal.GtiDatentyp)
                            {
                            case "LW":
                                myDatatype = context.Workspace.ActiveProject.DataTypeCollection["DINT"];
                                break;

                            case "FLOAT":
                                myDatatype = context.Workspace.ActiveProject.DataTypeCollection["REAL"];
                                break;

                            case "WORT":
                                myDatatype = context.Workspace.ActiveProject.DataTypeCollection["INT"];
                                break;

                            case "BCD-DL":
                                myDatatype = context.Workspace.ActiveProject.DataTypeCollection["INT"];
                                break;

                            case "S7-BYTE":
                                myDatatype = context.Workspace.ActiveProject.DataTypeCollection["USINT"];
                                break;

                            default:
                                myDatatype = context.Workspace.ActiveProject.DataTypeCollection["REAL"];
                                break;
                            }

                            variableCollection.Create(myVariableName, sel_driver, ChannelType.DriverVariable, myDatatype);

                            if (variableCollection[myVariableName] == null)
                            {
                                context.DebugPrint("Variable could not be created.", DebugPrintStyle.Error);
                                return;
                            }

                            variableCollection[myVariableName].DataBlock = tempVal.DataBlock;
                            variableCollection[myVariableName].Offset    = tempVal.Offset;
                            //variableCollection[myVariableName].Unit = "%";
                            variableCollection[myVariableName].SignalMaximumRange    = tempVal.MaxWert;
                            variableCollection[myVariableName].SignalMinimumRange    = tempVal.MinWert;
                            variableCollection[myVariableName].MeasuringMaximumRange = tempVal.MaxNorm;
                            variableCollection[myVariableName].MeasuringMinimumRange = tempVal.MinNorm;
                            variableCollection[myVariableName].Digits     = tempVal.Komma;
                            variableCollection[myVariableName].NetAddress = tempVal.Netzadresse;
                        }
                        catch (Exception creationException)
                        {
                            context.DebugPrint("Variable creation error: " + creationException.Message, DebugPrintStyle.Error);
                        }
                        context.DebugPrint("Variable " + variableCollection[myVariableName].Name + " has been created.", DebugPrintStyle.Standard);
                    }
                    else
                    {
                        context.DebugPrint("The variable " + variableCollection[myVariableName].Name + " exists already!", DebugPrintStyle.Warning);
                    }
                }
                #endregion

                #region Logisch
                //Einlesen von CSV für numerische Variablen
                List <GTILogVal> GTILogValues = new List <GTILogVal>();
                try
                {
                    context.DebugPrint("Einlesen von: " + frmSelection.file_logic, DebugPrintStyle.Standard);
                    GTILogValues = ReadLogCSV(frmSelection.file_logic);
                }
                catch (Exception creationException)
                {
                    context.DebugPrint("Reading CSV error: " + creationException.Message, DebugPrintStyle.Error);
                    return;
                }
                if (GTINumValues.Count < 1)
                {
                    context.DebugPrint("Reading CSV error", DebugPrintStyle.Error);
                    return;
                }

                foreach (GTILogVal tempVal in GTILogValues)
                {
                    string myVariableName = tempVal.Name;

                    // Jetzt werden die Variablen erstellt
                    if (variableCollection[myVariableName] == null)
                    {
                        try
                        {
                            myDatatype = context.Workspace.ActiveProject.DataTypeCollection["BOOL"];
                            variableCollection.Create(myVariableName, sel_driver, ChannelType.DriverVariable, myDatatype);

                            if (variableCollection[myVariableName] == null)
                            {
                                context.DebugPrint("Variable could not be created.", DebugPrintStyle.Error);
                                return;
                            }

                            variableCollection[myVariableName].DataBlock  = tempVal.DataBlock;
                            variableCollection[myVariableName].Offset     = tempVal.Offset;
                            variableCollection[myVariableName].BitNumber  = tempVal.Bit;
                            variableCollection[myVariableName].NetAddress = tempVal.Netzadresse;
                        }
                        catch (Exception creationException)
                        {
                            context.DebugPrint("Variable creation error: " + creationException.Message, DebugPrintStyle.Error);
                        }
                        context.DebugPrint("Variable " + variableCollection[myVariableName].Name + " has been created.", DebugPrintStyle.Standard);
                    }
                    else
                    {
                        context.DebugPrint("The variable " + variableCollection[myVariableName].Name + " exists already!", DebugPrintStyle.Warning);
                    }
                }
                #endregion

                #region Limits

                //Einlesen von CSV für numerische Variablen
                List <GTIAlert> GTIAlerts = new List <GTIAlert>();
                GTIAlerts = ReadAlertCSV(frmSelection.file_alert);

                context.DebugPrint("Number: " + GTIAlerts.Count(), DebugPrintStyle.Standard);

                foreach (GTIAlert alert in GTIAlerts)
                {
                    context.DebugPrint("Alert: " + alert.Number + " / Name: " + alert.AlarmText + " / Variable: " + alert.Variable, DebugPrintStyle.Standard);
                }

                if (variableCollection == null || variableCollection.Count < 1)
                {
                    return;
                }

                //Alle Variablen als "False" setzten
                foreach (IVariable variable in variableCollection)
                {
                    for (int i = 0; i < variable.EditorLimitValueCount; i++)
                    {
                        variable.DeleteEditorLimitValue(i);
                    }

                    if (GTIAlerts.Where(x => x.Variable == variable.Name).Count() > 0)
                    {
                        variable.CreateEditorLimitValue();
                        IEditorLimitValue limit = variable.GetEditorLimitValue(0);
                        limit.IsActive = true;
                        limit.Text     = GTIAlerts.Where(x => x.Variable == variable.Name).FirstOrDefault().AlarmText;
                    }
                }

                #endregion
            }
        }