public static void DataHandling(IConfigurationRoot configuration, ITcSysManager10 systemManager, bool debugMode) { //Define Internal Variables List <ITcSmTreeItem> 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 Tree Module", debugMode); Helpers.DebugLogger("-------------------", debugMode); //Get Adapter List adapterList = new List <ITcSmTreeItem>(); adapterList.Clear(); //Get Base IO-Node ITcSmTreeItem ioBase = systemManager.LookupTreeItem("TIID"); Helpers.DebugLogger($"Actual Found {ioBase.ChildCount} Adapters", debugMode); //Check Directory string folderName = Helpers.CheckFolder(xaeIoData.folder, debugMode); //Fill Adapter List foreach (ITcSmTreeItem childAdapter in ioBase) { Helpers.DebugLogger($"Adapter: {childAdapter.Name}", debugMode); //Recurve Work GetTreeItems(childAdapter, adapterList); } }
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, ""); } } } } }
public static void DataHandling(IConfigurationRoot configuration, ITcSysManager10 systemManager, bool debugMode) { //Get JSon Settings var xaeMappingData = new XaeMappingData(); var xaeFileData = new XaeFileData(); try { configuration.GetSection("XaeMappingData").Bind(xaeMappingData); configuration.GetSection("XaeFileData").Bind(xaeFileData); } catch (Exception e) { DataRelease(e.Message, debugMode); return; } //Write Header Helpers.DebugLogger("TwinCAT Mapping Module", debugMode); Helpers.DebugLogger("-------------------", debugMode); Helpers.DebugLogger($"Selected Mapping Import: {xaeMappingData.import}", debugMode); Helpers.DebugLogger($"Selected Mapping Export: {xaeMappingData.export}", debugMode); Helpers.DebugLogger("-------------------", debugMode); if (!xaeMappingData.import && !xaeMappingData.export) { DataRelease("Mapping Module Nothing do to - Exit", debugMode); return; } //Export Symbol Mapping if (xaeMappingData.export) { //Check Directory string folderName = Helpers.CheckFolder(xaeMappingData.folder, debugMode); string fileName = ""; if (xaeMappingData.exportTimestamp) { fileName = folderName + Helpers.TimeStamp() + "_" + xaeMappingData.exportFile; } else { fileName = folderName + "_" + xaeMappingData.exportFile; } //Write OutputStream Helpers.DebugLogger("Export Symbol Configuration", debugMode); string mappingInfo = systemManager.ProduceMappingInfo(); XmlDocument xmlDocument = new XmlDocument(); xmlDocument.LoadXml(mappingInfo); xmlDocument.Save(fileName); xmlDocument = null; } //Import XTI Files if (xaeMappingData.import) { //Check Directory string folderName = Helpers.CheckFolder(xaeMappingData.folder, debugMode); string fileName = folderName + xaeMappingData.importFile; //Check Directory if (!File.Exists(fileName)) { DataRelease("Mapping File not found", debugMode); } else { //Read XML Document XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); //MappingInfo string mappingInfo = ""; using (StringWriter writer = new StringWriter()) { xmlDocument.Save(writer); mappingInfo = writer.ToString(); } Helpers.DebugLogger("Import Mapping: \n" + mappingInfo, debugMode); systemManager.ConsumeMappingInfo(mappingInfo); xmlDocument = null; } } }
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); } } } } }
static void Main(string[] args) { //Invoke Log4Net Helpers.InvokeLog4Net(); //Dynamic Appsettings File for different options string appsetttingsFile = "appsettings.json"; //Argument for appsetting file if (args.Length > 0) { if (args[0] == "help") { WriteLine("Usage -->"); WriteLine("-----------------------"); WriteLine("NetCoreTwinCatXport.exe YOUR APPSETTINGS_FILE.json\n"); WriteLine("------------------------"); WriteLine("otherwise appsettings.json will be used"); WriteLine("------------------------"); return; } appsetttingsFile = args[0]; } Helpers.DebugLogger(appsetttingsFile, true); //Configuration Builder var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(appsetttingsFile, optional: true, reloadOnChange: true); //Get Json Data via Configuration Builder IConfigurationRoot configuration = null; try { configuration = builder.Build(); } catch (Exception e) { Helpers.DebugLogger(e.Message, true); return; } var xaeFileData = new XaeFileData(); var xaeInterfaceData = new XaeInterfaceData(); try { configuration.GetSection("XaeInterfaceData").Bind(xaeInterfaceData); } catch (Exception e) { Helpers.DebugLogger(e.Message, xaeInterfaceData.debugmode); } //Output Operation Comment Helpers.DebugLogger("------------Operation Comment----------", xaeInterfaceData.debugmode); Helpers.DebugLogger(xaeInterfaceData.operationComment, xaeInterfaceData.debugmode); Helpers.DebugLogger("------------Operation Comment----------", xaeInterfaceData.debugmode); //Start Xae Interface ITcSysManager10 systemManager = XaeInterface.AttachToXae(configuration); if (systemManager == null) { Helpers.DebugLogger("No SystemManager Project Found", xaeInterfaceData.debugmode); return; } //Determine priority and execute - highest prio = 20 for (int prorityLoop = 1; prorityLoop <= 20; prorityLoop++) { //Execute XaeIo DataHandling if (xaeInterfaceData.executeIo == prorityLoop) { XaeIo.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute XaeMapping DataHandling if (xaeInterfaceData.executeMapping == prorityLoop) { XaeMapping.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute XaeMotion DataHandling if (xaeInterfaceData.executeMotion == prorityLoop) { XaeMotion.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute Io Tree if (xaeInterfaceData.executeIoTree == prorityLoop) { XaeIoTree.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } //Execute PLC if (xaeInterfaceData.executePlc == prorityLoop) { XaePlc.DataHandling(configuration, systemManager, xaeInterfaceData.debugmode); } } //Activate Actual Configuration if (xaeInterfaceData.activateConfiguration) { XaeSystem.ActivateActualConfiguration(configuration, systemManager, xaeInterfaceData.debugmode); } //Close Solution if (xaeInterfaceData.closeActiveXae) { XaeInterface.CloseSolution(); } //Build Solution if (xaeInterfaceData.buildSolution) { XaeInterface.BuildSolution(false); } }
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, ""); } } } }