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, ""); } } } } }