Пример #1
0
        public static void DataHandling(IConfigurationRoot configuration, ITcSysManager10 systemManager, bool debugMode)
        {
            //Get JSon Settings
            var xaePlcData  = new XaePlcData();
            var xaeFileData = new XaeFileData();

            try
            {
                configuration.GetSection("XaePlcData").Bind(xaePlcData);
                configuration.GetSection("XaeFileData").Bind(xaeFileData);
            }
            catch (Exception e)
            {
                DataRelease(e.Message, debugMode);
                return;
            }

            //Write Header
            Helpers.DebugLogger("TwinCAT Plc Module", debugMode);
            Helpers.DebugLogger("-------------------", debugMode);
            Helpers.DebugLogger($"Selected Apdapter Import: {xaePlcData.import}", debugMode);
            Helpers.DebugLogger($"Selected Apdapter Export: {xaePlcData.export}", debugMode);
            Helpers.DebugLogger("-------------------", debugMode);

            if (!xaePlcData.import && !xaePlcData.export && !xaePlcData.syncProject)
            {
                DataRelease("Plc Module Nothing do to - Exit", debugMode);
                return;
            }

            //Get Base PLC-Node
            ITcSmTreeItem plcBase = systemManager.LookupTreeItem("TIPC");

            Helpers.DebugLogger($"Actual Found {plcBase.ChildCount} PLC Programs", debugMode);


            //Check Directory
            string folderName = Helpers.CheckFolder(xaePlcData.folder, debugMode);
            string fileName   = "";

            //Fill Adapter List
            foreach (ITcSmTreeItem childPlc in plcBase)
            {
                //Check ProjectName
                if (childPlc.Name == xaePlcData.projectName)
                {
                    Helpers.DebugLogger($"PLC Programm: {childPlc.PathName}", debugMode);

                    //Get Projects/Instances
                    ITcProjectRoot   projectRoot     = (ITcProjectRoot)childPlc;
                    ITcSmTreeItem    nestedProject   = projectRoot.NestedProject;
                    ITcSmTreeItem    projectInstance = childPlc.get_Child(1);
                    ITcPlcIECProject iecProject      = (ITcPlcIECProject)nestedProject;

                    //FileName
                    if (xaePlcData.exportTimestamp)
                    {
                        fileName = folderName + Helpers.TimeStamp() + "_" + xaePlcData.exportPrefix + childPlc.Name + ".xml";
                    }
                    else
                    {
                        fileName = folderName + xaePlcData.exportPrefix + childPlc.Name + ".xml";
                    }


                    //Export XML Files
                    if (xaePlcData.export)
                    {
                        if (Directory.Exists(folderName))
                        {
                            Helpers.DebugLogger($"Export File: {fileName}", debugMode);
                            iecProject.PlcOpenExport(fileName, "");
                        }
                        else
                        {
                            Helpers.DebugLogger($"Error Plc Export - No Folder: {folderName}", debugMode);
                        }
                    }
                    //Import XML Files
                    if (xaePlcData.import || xaePlcData.syncProject)
                    {
                        if (!xaePlcData.syncProject)
                        {
                            fileName = folderName + xaePlcData.importFile;
                        }

                        if (File.Exists(fileName))
                        {
                            Helpers.DebugLogger($"Import File: {fileName}", debugMode);
                            iecProject.PlcOpenImport(fileName, (int)PLCIMPORTOPTIONS.PLCIMPORTOPTIONS_REPLACE, "");
                        }
                        else
                        {
                            Helpers.DebugLogger($"Error Plc Import: {fileName}", debugMode);
                        }
                    }
                }
            }
        }
Пример #2
0
        public static void DataHandling(IConfigurationRoot configuration, ITcSysManager10 systemManager, bool debugMode)
        {
            //Define Internal Variables
            List <string> axesList;

            //Get JSon Settings
            var xaeMotionData = new XaeMotionData();
            var xaeFileData   = new XaeFileData();

            try
            {
                configuration.GetSection("XaeMotionData").Bind(xaeMotionData);
                configuration.GetSection("XaeFileData").Bind(xaeFileData);
            }
            catch (Exception e)
            {
                DataRelease(e.Message, debugMode);
                return;
            }

            //Write Header
            Helpers.DebugLogger("TwinCAT Motion Module", debugMode);
            Helpers.DebugLogger("-------------------", debugMode);
            Helpers.DebugLogger($"Axes Export Mode: {xaeMotionData.export}", debugMode);
            Helpers.DebugLogger($"Axes Import Mode: {xaeMotionData.import}", debugMode);
            Helpers.DebugLogger($"Axes Hardware Mode: {xaeMotionData.hardware}", debugMode);
            Helpers.DebugLogger($"Axes Simulation Mode: {xaeMotionData.simulation}", debugMode);
            Helpers.DebugLogger("-------------------", debugMode);

            if (!xaeMotionData.hardware && !xaeMotionData.simulation && !xaeMotionData.export && !xaeMotionData.import)
            {
                DataRelease("Motion Module Nothing do to - Exit", debugMode);
                return;
            }

            //Get Adapter List
            axesList = new List <string>();
            axesList.Clear();

            //Get Base Axes-Node
            ITcSmTreeItem axesBase = systemManager.LookupTreeItem("TINC^NC-Task 1 SAF^Axes");

            Helpers.DebugLogger($"Actual Found {axesBase.ChildCount} Axes", debugMode);


            //Check Directory
            string folderName = Helpers.CheckFolder(xaeMotionData.folder, debugMode);
            string fileName   = "";

            //Fill Adapter List
            foreach (ITcSmTreeItem childAdapter in axesBase)
            {
                Helpers.DebugLogger($"Axis: {childAdapter.Name}", debugMode);
                axesList.Add(childAdapter.Name);
            }

            //Export XTI Axes
            if (xaeMotionData.export)
            {
                //Export Adapter
                foreach (string axisString in axesList)
                {
                    //FileName
                    if (xaeMotionData.exportTimestamp)
                    {
                        fileName = folderName + Helpers.TimeStamp() + "_" + axisString + ".xti";
                    }
                    else
                    {
                        fileName = folderName + axisString + ".xti";
                    }

                    Helpers.DebugLogger($"Export: {axisString}", debugMode);
                    axesBase.ExportChild(axisString, fileName);
                }
            }

            //Import Simulation XTI Files
            if (xaeMotionData.simulation || xaeMotionData.hardware)
            {
                //Delete Axes
                foreach (string axisString in axesList)
                {
                    //Simulation AXis
                    if ((File.Exists(folderName + axisString + "_SIM.xti") && xaeMotionData.simulation)
                        ||
                        (File.Exists(folderName + axisString + "_HW.xti") && xaeMotionData.hardware))
                    {
                        try
                        {
                            Helpers.DebugLogger($"Delete Axis: {axisString}", debugMode);
                            axesBase.DeleteChild(axisString);
                        } catch (Exception e)
                        {
                            Helpers.DebugLogger(e.Message, debugMode);
                        }
                    }
                }

                //Time for Xae-Update
                Task.Delay(2000).Wait();

                //Import Axes
                foreach (string axisString in axesList)
                {
                    //Simulation AXis
                    if (File.Exists(folderName + axisString + "_SIM.xti") && xaeMotionData.simulation)
                    {
                        try
                        {    //(importFile, "", true, "");
                            axesBase.ImportChild(folderName + axisString + "_SIM.xti", "", true, axisString);
                        } catch (Exception e)
                        {
                            Helpers.DebugLogger(e.Message, debugMode);
                        }
                    }

                    //Hardware AXis
                    if (File.Exists(folderName + axisString + "_HW.xti") && xaeMotionData.hardware)
                    {
                        try
                        {
                            Helpers.DebugLogger($"Import Hardware: {axisString}", debugMode);
                            axesBase.ImportChild(folderName + axisString + "_HW.xti", "", true, axisString);
                        }
                        catch (Exception e)
                        {
                            Helpers.DebugLogger(e.Message, debugMode);
                        }
                    }
                }
            }

            //Import
            if (xaeMotionData.import)
            {
                //Check Directory
                folderName = Helpers.CheckFolder(xaeMotionData.folder, debugMode);


                string[] importFiles = Directory.GetFiles(folderName);
                foreach (string importFile in importFiles)
                {
                    //Check if File is XTI and not Backupfile
                    if ((importFile.IndexOf(".xti") > -1) && (importFile.IndexOf(".bak") == -1))
                    {
                        //Search Axis in List
                        bool axisFound = false;
                        foreach (string axisString in axesList)
                        {
                            if (importFile.IndexOf(axisString) >= -1)
                            {
                                axisFound = true;
                                Helpers.DebugLogger("Axis Exists :" + axisString, debugMode);
                            }
                        }

                        //Import Axis
                        if ((axisFound == false) || (xaeMotionData.replace))
                        {
                            Helpers.DebugLogger(importFile, debugMode);
                            axesBase.ImportChild(importFile, "", true, "");
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void DataHandling(IConfigurationRoot configuration, ITcSysManager10 systemManager, bool debugMode)
        {
            //Define Internal Variables
            List <string> adapterList;

            //Get JSon Settings
            var xaeIoData   = new XaeIoData();
            var xaeFileData = new XaeFileData();

            try
            {
                configuration.GetSection("XaeIoData").Bind(xaeIoData);
                configuration.GetSection("XaeFileData").Bind(xaeFileData);
            }
            catch (Exception e)
            {
                DataRelease(e.Message, debugMode);
                return;
            }

            //Write Header
            Helpers.DebugLogger("TwinCAT IO-xti Module", debugMode);
            Helpers.DebugLogger("-------------------", debugMode);
            Helpers.DebugLogger($"Selected Apdapter Import: {xaeIoData.import}", debugMode);
            Helpers.DebugLogger($"Selected Apdapter Export: {xaeIoData.export}", debugMode);
            Helpers.DebugLogger("-------------------", debugMode);

            if (!xaeIoData.import && !xaeIoData.export)
            {
                DataRelease("Io Module Nothing do to - Exit", debugMode);
                return;
            }


            //Get Adapter List
            adapterList = new List <string>();
            adapterList.Clear();

            //Get Base IO-Node
            //if systemManager.GetType
            ITcSmTreeItem ioBase = systemManager.LookupTreeItem("TIID");

            Helpers.DebugLogger($"Actual Found {ioBase.ChildCount} Adapters", debugMode);

            //Export XTI Files
            if (xaeIoData.export)
            {
                //Check Directory
                string folderName = Helpers.CheckFolder(xaeIoData.folder, debugMode);

                //Fill Adapter List
                foreach (ITcSmTreeItem childAdapter in ioBase)
                {
                    Helpers.DebugLogger($"Adapter: {childAdapter.Name}", debugMode);
                    adapterList.Add(childAdapter.Name);
                }

                //Export Adapter
                foreach (string adapterString in adapterList)
                {
                    string fileName = "";
                    if (xaeIoData.exportTimestamp)
                    {
                        fileName = folderName + Helpers.TimeStamp() + "_" + adapterString + ".xti";
                    }
                    else
                    {
                        fileName = folderName + adapterString + ".xti";
                    }
                    Helpers.DebugLogger($"Export: {adapterString} - {fileName}", debugMode);
                    ioBase.ExportChild(adapterString, fileName);
                }
            }

            //Import XTI Files
            if (xaeIoData.import)
            {
                //Check Directory
                string folderName = Helpers.CheckFolder(xaeIoData.folder, debugMode);

                string[] importFiles = Directory.GetFiles(folderName);
                foreach (string importFile in importFiles)
                {
                    //Check if File is XTI and not Backupfile
                    if ((importFile.IndexOf(".xti") > -1) && (importFile.IndexOf(".bak") == -1))
                    {
                        Helpers.DebugLogger(importFile, debugMode);
                        ioBase.ImportChild(importFile, "", true, "");
                    }
                }
            }
        }