using CMS_CORE; using CMS_CORE.Demo; using CMS_CORE.Fanuc; using CMS_CORE.Osai; using CMS_CORE.Siemens; using Step.Database.Controllers; using Step.Model.DatabaseModels; using Step.Model.DTOModels; using Step.Model.DTOModels.MaintenanceModels; using Step.Model.DTOModels.ToolModels; using Step.Utils; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using static CMS_CORE_Library.DataStructures; using static Step.Config.ServerConfig; using static Step.Model.Constants; namespace Step.NC { public class NcHandler : IDisposable { public Nc numericalControl; public NcHandler() { // Choose NC numericalControl = SetNumericalControl(); } public void Dispose() { numericalControl.NC_Disconnect(); } public CmsError Connect() { // Connect NC if (!numericalControl.NC_IsConnected()) return numericalControl.NC_Connect(); return null; } public Nc SetNumericalControl() { // Return new Numerical control instance choosed from the configuration switch (NcConfig.NcVendor) { case NC_VENDOR.DEMO: return new Nc_Demo(NcConfig.NcIpAddress, NcConfig.NcPort); case NC_VENDOR.FANUC: return new Nc_Fanuc(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); case NC_VENDOR.SIEMENS: return new Nc_Siemens(2000); case NC_VENDOR.OSAI: return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); } return null; } #region Read Data public CmsError GetNcGenericData(out DTONcGenericDataModel genericData) { genericData = new DTONcGenericDataModel(MachineConfig.Model); // Get date time DateTime dateTime = new DateTime(); CmsError cmsError = numericalControl.NC_RDateTime(ref dateTime); if (cmsError.errorCode != 0) return cmsError; genericData.DateTime = dateTime; // Get language CultureInfo lang = new CultureInfo("en"); cmsError = numericalControl.NC_RLanguage(ref lang); if (cmsError.errorCode != 0) return cmsError; genericData.Language = lang.TwoLetterISOLanguageName; string tmpInfo = ""; // Get serial number cmsError = numericalControl.NC_RSerialNumber(ref tmpInfo); if (cmsError.errorCode != 0) return cmsError; genericData.SerialNumber = tmpInfo; // Get software version numericalControl.NC_RSoftwareVersion(ref tmpInfo); if (cmsError.errorCode != 0) return cmsError; genericData.NcSoftwareVersion = tmpInfo; // Get model name numericalControl.NC_RModelName(ref tmpInfo); if (cmsError.errorCode != 0) return cmsError; genericData.NcModel = tmpInfo; // Get machine number numericalControl.NC_RMachineNumber(ref tmpInfo); if (cmsError.errorCode != 0) return cmsError; genericData.CmsMachineIdNumber = tmpInfo; // Get max process number ushort procNum = 0; numericalControl.NC_RProcessesNum(ref procNum); if (cmsError.errorCode != 0) return cmsError; // Max process number genericData.ProcessNumber = procNum; // Get Installation Date genericData.InstallationDate = DateTime.Now; // Get PLC version genericData.PlcVersion = "1.0.0"; // Get PLC version genericData.UnitOfMeasurement = "mm"; return cmsError; } public CmsError GetNcAlarms(out DTOAlarmsModel alarms) { alarms = new DTOAlarmsModel(); List tmpAlarms = new List(); // Read NC active alarms CmsError cmsError = numericalControl.NC_RActiveAlarms(ref tmpAlarms); if (cmsError.errorCode != 0) return cmsError; // Create response list from NC data foreach (AlarmModel ncAlarm in tmpAlarms) { alarms.NcAlarms.Add(new GenericAlarmModel() { Id = ncAlarm.Id, Message = ncAlarm.Message, DateTime = DateTime.Now, RestorationIsEnabled = false }); } // Select distints //alarms.NcAlarms = alarms.NcAlarms?.GroupBy(x => x.Id).Select(x => x.First()).ToList(); // Get NC max process number ushort maxProcNumber = 0; cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); if (cmsError.errorCode != 0) return cmsError; // For each process for (ushort i = 1; i <= maxProcNumber; i++) { // Get process active alarms numericalControl.PROC_RActiveAlarms(i, ref tmpAlarms); // Create response list from NC data foreach (AlarmModel processAlarm in tmpAlarms) { alarms.ProcessAlarms.Add(new ProcessAlarmModel() { Id = processAlarm.Id, Message = processAlarm.Message, Process = processAlarm.Process, DateTime = DateTime.Now, RestorationIsEnabled = false }); } } List plcAlarms = new List(); // Read PLC Active Messages cmsError = numericalControl.PLC_RActiveMessages(ref plcAlarms); bool restorationIsEnabled = false; foreach (PlcAlarmModel plcAlarm in plcAlarms) { var configuredAlarm = InitialAlarmsConfig.Where(x => x.PlcId == plcAlarm.Id).FirstOrDefault(); if (configuredAlarm == null) restorationIsEnabled = false; else restorationIsEnabled = configuredAlarm.RestoreIsActive; // Create response list from plc data alarms.PlcAlarms.Add(new DTOPlcAlarmModel() { Id = plcAlarm.Id, IsWarning = plcAlarm.IsWarning, Process = plcAlarm.Process, RestorationIsActive = plcAlarm.RestorationIsActive, DateTime = DateTime.Now, RestorationIsEnabled = restorationIsEnabled }); } if (cmsError.errorCode != 0) return cmsError; return cmsError; } public CmsError GetAxesPositions(out List axes) { axes = new List(); // Get NC max process number ushort maxProcNumber = 0; CmsError cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); if (cmsError.errorCode != 0) return cmsError; // For each process for (ushort i = 1; i <= maxProcNumber; i++) { cmsError = GetAxesPositionsByProcess(i, out DTOAxesModel axis); if (cmsError.errorCode != 0) return cmsError; axes.Add(axis); } return cmsError; } public CmsError GetAxesPositionsByProcess(ushort processNum, out DTOAxesModel axes) { axes = new DTOAxesModel(); CmsError cmsError = numericalControl.AXES_RInterpPosition(processNum, ref axes.interpolated); if (cmsError.errorCode != 0) return cmsError; numericalControl.AXES_RMachinePosition(processNum, ref axes.machine); if (cmsError.errorCode != 0) return cmsError; numericalControl.AXES_RProgrPosition(processNum, ref axes.programmePos); if (cmsError.errorCode != 0) return cmsError; numericalControl.AXES_RDistanceToGo(processNum, ref axes.toGo); if (cmsError.errorCode != 0) return cmsError; //numericalControl.AXES_RFollowingError(1, ref axes.followingErr); return cmsError; } public CmsError GetPowerOnData(out DTOPowerOnDataModel resultPowerOnData) { resultPowerOnData = new DTOPowerOnDataModel(); // Init object PreAndPostPowerOnModel prePostPowerOn = new PreAndPostPowerOnModel { PostPowerOn = new PostPowerOnModel(), PrePowerOn = new PrePowerOnModel() }; // Read pre and post power on data CmsError cmsError = numericalControl.PLC_RPowerOnData(ref prePostPowerOn); if (cmsError.IsError()) return cmsError; // Set return object resultPowerOnData.PrePowerOn = prePostPowerOn.PrePowerOn; resultPowerOnData.PostPowerOn = prePostPowerOn.PostPowerOn; // Read axes procedure data from cmsError = numericalControl.PLC_RAxesResetData(ref resultPowerOnData.AxisReset); return cmsError; } public CmsError GetProcessesData(out DTOProcessesDataModel processesData) { processesData = new DTOProcessesDataModel(); // Get NC max process number ushort maxProcNumber = 0; CmsError cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); if (cmsError.errorCode != 0) return cmsError; PROC_STATUS status = PROC_STATUS.IDLE; // For each process get info for (ushort i = 1; i <= maxProcNumber; i++) { ProcessDataModel tmpProcPP = new ProcessDataModel(); // Get process status cmsError = numericalControl.PROC_RStatusAndData(i, ref tmpProcPP); // if at least one process is in run, NC is running // Add to list processesData.processes.Add(new ProcessModel() { Id = tmpProcPP.Id, IsInAlarm = tmpProcPP.IsInAlarm, PartProgramName = tmpProcPP.PartProgramName, Reps = tmpProcPP.Reps, Status = tmpProcPP.Status, Type = tmpProcPP.Type, Visible = tmpProcPP.Visible }); if (tmpProcPP.IsSelected && processesData.selectedProcess == 0) // TODO remove with multi-process processesData.selectedProcess = (ushort)tmpProcPP.Id; // Check if there are running process if (!processesData.isRunning) { // Get process status cmsError = numericalControl.PROC_RStatus(i, ref status); if (status == PROC_STATUS.RUN || status == PROC_STATUS.HOLD) processesData.isRunning = true; else status = PROC_STATUS.IDLE; } } // Read selected axes cmsError = numericalControl.AXES_RSelectedAxis(ref processesData.selectedAxis); return cmsError; } public CmsError GetFunctionsMappedWithNC(out List functionsAccessList) { functionsAccessList = new List(); // Read plc functionality List functionalityList = null; CmsError cmsError = numericalControl.PLC_RFunctionAccess(ref functionalityList); // If empty return if (functionalityList == null || functionalityList.Count == 0) return cmsError; using (FunctionsAccessController functionsAccessController = new FunctionsAccessController()) { // Map plc and database data functionsAccessList = functionsAccessController.GetFunctionsMappedWithPlc(functionalityList); } return cmsError; } public CmsError GetMainenancesCounter(out List counters) { // List of PLC counters counters = new List(); // Get counters values from PLC CmsError cmsError = numericalControl.PLC_RMachineCounters(ref counters); return cmsError; } public CmsError GetMaintenanceData(out DTOMaintenanceModel dTOMaintenance, int maintenanceId, int userId) { dTOMaintenance = null; CmsError cmsError = GetMaintenances(out List maintenance, userId); if (cmsError.IsError()) return cmsError; dTOMaintenance = maintenance.Where(x => x.Id == maintenanceId).FirstOrDefault(); return cmsError; } public CmsError GetMaintenances(out List dtoMaintenancesModel, int userId) { // Return value dtoMaintenancesModel = new List(); // Get counters values from PLC CmsError cmsError = GetMainenancesCounter(out List counters); if (cmsError.IsError()) return cmsError; using (MaintenancesController maintenancesController = new MaintenancesController()) { // Get the last performed maintenance for each maintenance List performedMaintenances = maintenancesController.FindLastPerformedMaintenances(); // Get all the active maintenances List maintenances = maintenancesController.FindAll(); // TODO db or config file? double percentage = 0; TimeSpan missingDays = new TimeSpan(); CounterModel counter = new CounterModel(); bool canEdit = false; bool canPerform = false; foreach (var currMaintenance in maintenances) { // Get matching last performed maintenance for current maintenance PerformedMaintenanceModel performed = performedMaintenances.Find(x => x.MaintenanceId == currMaintenance.MaintenanceId); switch (currMaintenance.Type) { case MAINTENANCE_TYPE.MACHINE_INTERVAL: { // Get matching counter for the current maintenance counter = counters.Find(x => x.Id == currMaintenance.CounterId); int perfVal = 0; if (performed != null) perfVal = performed.CounterValue; // Calc percentage = PLC - PERFORMED VALUE * 100 / interval percentage = ((counter.Value - perfVal) * 100) / SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value); missingDays = TimeSpan.FromMinutes(-1 * (counter.Value - perfVal - SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value))); } break; case MAINTENANCE_TYPE.EXP_DATE: { // Already performed if (performed != null) { percentage = 100; missingDays = TimeSpan.Zero; } else { percentage = ((DateTime.Now - currMaintenance.CreationDate).TotalMinutes * 100) / (currMaintenance.Deadline - currMaintenance.CreationDate).TotalMinutes; // TimeSpan.FromTicks((currMaintenance.Deadline.Ticks)).TotalMinutes missingDays = currMaintenance.Deadline - DateTime.Now; counter = new CounterModel(); } } break; case MAINTENANCE_TYPE.TIME_INTERVAL: { // Get last performed, default value is maintenance creation date DateTime perfDate = currMaintenance.CreationDate; if (performed != null) perfDate = performed.Date; // Now - last performed = elapsed interval since last maintenance TimeSpan timePassedFromLastMaint = DateTime.Now.Subtract(perfDate); // Convert in minutes double minutesPassedFromLastMaint = timePassedFromLastMaint.TotalMinutes; // percentage = Passed minutes since last maintenance * 100 / Interval percentage = (minutesPassedFromLastMaint * 100) / SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value); missingDays = TimeSpan.FromMinutes( -1 * (minutesPassedFromLastMaint - SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value))); counter = new CounterModel(); } break; } canEdit = false; using (MachinesUsersController machineUsersController = new MachinesUsersController()) { if(currMaintenance.UserId != null) { // Check if user can edit the maintenance -> caller id - maintenance user id int comparision = machineUsersController.CompareUsersRole(userId, currMaintenance.UserId.Value, MachineConfig.MachineId); if (comparision >= 0) canPerform = canEdit = true; } else { canEdit = false; canPerform = machineUsersController.UserIsCmsAdmin(MachineConfig.MachineId, userId); } } dtoMaintenancesModel.Add(new DTOMaintenanceModel() { Id = currMaintenance.MaintenanceId, Title = currMaintenance.UserId == null ? "" : currMaintenance.Title, CreationDate = currMaintenance.CreationDate, Deadline = currMaintenance.Deadline, Description = currMaintenance.Description, Interval = currMaintenance.Interval, LastExpirationDate = currMaintenance.LastExpirationDate, LastPerformedDate = performed?.Date, Type = currMaintenance.Type.ToString(), UnitOfMeasure = currMaintenance.UnitOfMeasure.ToString(), PercentageOfCompletion = percentage >= 0 && percentage < 100 ? Convert.ToInt32(percentage) : 100, MissingDays = missingDays, PlcCounter = counter.Value, CreatedByCms = currMaintenance.UserId == null, CanEdit = canEdit, CanPerform = canPerform }); } } return cmsError; } public CmsError GetExpiredMaintenances(out List expiredMaintenance) { // Return value expiredMaintenance = new List(); // Get counters values from PLC CmsError cmsError = GetMainenancesCounter(out List counters); if (cmsError.IsError()) return cmsError; using (MaintenancesController maintenancesController = new MaintenancesController()) { // Get the last performed maintenance for each maintenance List performedMaintenances = maintenancesController.FindLastPerformedMaintenances(); // Get all the active maintenances List maintenances = maintenancesController.FindAll(); // TODO db or config file? foreach (var currMaintenance in maintenances) { // Get matching last performed maintenance for current maintenance var performed = performedMaintenances.Find(x => x.MaintenanceId == currMaintenance.MaintenanceId); switch (currMaintenance.Type) { case MAINTENANCE_TYPE.MACHINE_INTERVAL: { // Get matching counter for the current maintenance var counter = counters.Find(x => x.Id == currMaintenance.CounterId); int perfVal = 0; if (performed != null) perfVal = performed.CounterValue; // MAINTENANCE_INTERVAL <= PLC - LASTPERFORMED if (SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value) <= counter.Value - perfVal) { // Update last expiration date if null if (currMaintenance.LastExpirationDate == null) { maintenancesController.UpdateLastExpirationDate(currMaintenance.MaintenanceId, DateTime.Now); currMaintenance.LastExpirationDate = DateTime.Now; } // Add item to return list expiredMaintenance.Add(new DTOExpiredMaintenanceModel() { Id = currMaintenance.MaintenanceId, ExpirationDate = (DateTime)currMaintenance.LastExpirationDate, CreatedByCms = currMaintenance.UserId == null, Title = currMaintenance.UserId == null ? "" : currMaintenance.Title }); } } break; case MAINTENANCE_TYPE.EXP_DATE: { // Already performed if (performed != null) break; // DEADLINE <= NOW if (currMaintenance.Deadline <= DateTime.Now) { maintenancesController.UpdateLastExpirationDate(currMaintenance.MaintenanceId, currMaintenance.Deadline); currMaintenance.LastExpirationDate = currMaintenance.Deadline; // Add item to return list expiredMaintenance.Add(new DTOExpiredMaintenanceModel() { Id = currMaintenance.MaintenanceId, ExpirationDate = currMaintenance.Deadline, CreatedByCms = currMaintenance.UserId == null, Title = currMaintenance.UserId == null ? "" : currMaintenance.Title, }); } } break; case MAINTENANCE_TYPE.TIME_INTERVAL: { // Get last performed, default value is maintenance creation date DateTime perfDate = currMaintenance.CreationDate; if (performed != null) perfDate = performed.Date; // Now - last performed = elapsed interval since last maintenance TimeSpan timePassedFromLastMaint = DateTime.Now.Subtract(perfDate); // Convert in minutes double minutesPassedFromLastMaint = timePassedFromLastMaint.TotalMinutes; // Interval - passed minutes since last maintenance if (SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value) <= minutesPassedFromLastMaint) { // Update last expiration date if (currMaintenance.LastExpirationDate == null) { // Exp date = now - ( expiration intervall) DateTime expirationDate = DateTime.Now.Subtract(TimeSpan.FromMinutes(minutesPassedFromLastMaint - currMaintenance.Interval.Value)); maintenancesController.UpdateLastExpirationDate(currMaintenance.MaintenanceId, expirationDate); currMaintenance.LastExpirationDate = expirationDate; } // Add item to return list expiredMaintenance.Add(new DTOExpiredMaintenanceModel() { Id = currMaintenance.MaintenanceId, ExpirationDate = (DateTime)currMaintenance.LastExpirationDate, CreatedByCms = currMaintenance.UserId == null, Title = currMaintenance.UserId == null ? "" : currMaintenance.Title, }); } } break; } } } return cmsError; } public CmsError GetUserSoftKeys(out List softKeys) { softKeys = new List(); List plcSoftKeys = new List(); // Get softkeys data from PLC CmsError cmsError = numericalControl.PLC_RUserSoftKeys(ref plcSoftKeys); if (cmsError.IsError() || plcSoftKeys.Count == 0) return cmsError; foreach (var softKey in SoftKeysConfig) { // Check type of the selected softkey if (softKey.Type == SOFTKEY_TYPE.GROUP) { // Foreach subkey create a softkey foreach (var subkey in softKey.SubKeys) { // Find the plc matching data var plcSoftKey = plcSoftKeys.Find(x => x.Id == subkey.PlcId); // Create and add new user softkey model softKeys.Add(new DTOUserSoftKeyModel() { Id = subkey.Id, Active = plcSoftKey.Active, Category = softKey.Category, Value = plcSoftKey.Value }); } } else { // Find the plc matching data var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.PlcId); softKeys.Add(new DTOUserSoftKeyModel() { Id = softKey.Id, Active = plcSoftKey.Active, Category = softKey.Category, Value = plcSoftKey.Value }); } } return cmsError; } public CmsError GetNcSoftKeys(out List ncSoftKeys) { ncSoftKeys = new List(); List plcSoftKeys = new List(); // Get Nc softkeys data from PLC CmsError cmsError = numericalControl.PLC_RNcSoftKeys(ref plcSoftKeys); if (cmsError.IsError() || plcSoftKeys.Count == 0) return cmsError; foreach (var softKey in NcSoftKeysConfig) { // Find the plc matching data var plcSoftKey = plcSoftKeys.Find(x => x.Id == softKey.Id); // Create and add Nc softkey model ncSoftKeys.Add(new DTONcSoftKeyModel() { Id = softKey.Id, Active = plcSoftKey.Active, Value = plcSoftKey.Value }); } return cmsError; } public CmsError GetHeadsData(out List heads) { // Returned value heads = new List(); // Number of configured heads int headsNumber = HeadsConfig.Count; List plcHeads = new List(); // Read value from PLC CmsError cmsError = numericalControl.PLC_RHeadsData(plcHeads, headsNumber); if (cmsError.IsError()) return cmsError; foreach (var head in plcHeads) { // Get current head config var configuredHead = HeadsConfig.Find(x => x.Id == head.Id); // Create different model according on type switch (configuredHead.Type) { case HEAD_TYPE.SPINDLE: { heads.Add(new DTOSpindleModel() { Id = head.Id, Process = head.Process, Type = configuredHead.Type.ToString(), inWarning = head.Load_Abrasive >= configuredHead.WarningLimit, inAlarm = head.Load_Abrasive >= configuredHead.AlarmLimit, OverrideEditable = head.OverrideEditable, ActualSpeed = head.ActualSpeed_Pressure, Load = head.Load_Abrasive, MountedTool = (ushort)head.MountedTool_Vacum, Override = head.Override, IsActive = head.IsActive, IsSelected = head.IsSelected, AbrasiveIsActive = head.AbrasiveIsActive }); } break; case HEAD_TYPE.AWJ: { float vacumValue = (float)head.MountedTool_Vacum / 100; heads.Add(new DTOAbrasiveWaterJet() { Id = head.Id, Process = head.Process, Type = configuredHead.Type.ToString(), inWarning = vacumValue >= configuredHead.WarningLimit, inAlarm = vacumValue >= configuredHead.AlarmLimit, OverrideEditable = head.OverrideEditable, ActualPressure = head.ActualSpeed_Pressure, Abrasive = head.Load_Abrasive, Vacum = vacumValue, Override = head.Override, IsActive = head.IsActive, IsSelected = head.IsSelected, AbrasiveIsActive = head.AbrasiveIsActive }); } break; case HEAD_TYPE.WJ: { heads.Add(new DTOWaterJet() { Id = head.Id, Process = head.Process, Type = configuredHead.Type.ToString(), inAlarm = false, inWarning = false, ActualPressure = head.ActualSpeed_Pressure, OverrideEditable = head.OverrideEditable, Override = head.Override, IsActive = head.IsActive, IsSelected = head.IsSelected, AbrasiveIsActive = head.AbrasiveIsActive }); } break; } } return cmsError; } public CmsError ReadAxisData(out List axesNames) { axesNames = new List(); List plcAxes = new List(); // Read selected process ushort selectedProcess = 0; CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess); if (cmsError.IsError()) return cmsError; if( selectedProcess != 0) { // Read axes names cmsError = numericalControl.AXES_RAxesNames(selectedProcess, ref plcAxes); axesNames = plcAxes.Select(x => new DTOAxisNameModel() { Id = x.Id, Name = x.Name }).ToList(); } return cmsError; } public CmsError GetToolTableConfiguration(out ToolTableConfiguration config) { config = new ToolTableConfiguration(); return numericalControl.TOOLS_RConfiguration(ref config); } public CmsError GetToolTableData(out List config) { config = new List(); return numericalControl.TOOLS_RToolsData(ref config); } public CmsError GetShanksData(out List shanks) { shanks = new List(); return numericalControl.TOOLS_RShanksData(ref shanks); } public CmsError GetFamiliesData(out List families) { families = new List(); return numericalControl.TOOLS_RFamilyData(ref families); } public CmsError GetMagazinesPositionsData(out List magazinesPositions) { magazinesPositions = new List(); return numericalControl.TOOLS_RMagazinePositions(ref magazinesPositions); } public CmsError GetMagazineStatus(out DTOMagazineActionModel magazineStatus) { // Set up models magazineStatus= new DTOMagazineActionModel(); MagazineActionModel libModel = new MagazineActionModel(); // Read status from NC CmsError cmsError = numericalControl.TOOLS_GetMagazinesStatus(ref libModel); if (cmsError.IsError()) return cmsError; magazineStatus = (DTOMagazineActionModel)libModel; return cmsError; } #endregion Read Data #region Write data public CmsError PutNcSoftKeyClick(uint id) { // Write Nc softkey press to plc CmsError cmsError = numericalControl.PLC_WNcSoftKey(id); return cmsError; } public CmsError PutUserSoftKeyClick(uint id) { // Write user softkey press to plc return numericalControl.PLC_WUserSoftKey(id); } public CmsError RefreshAlarm(uint id) { // Write in memory the request to refresh the alarm return numericalControl.PLC_WRefreshMessage(id); } public CmsError RestoreAlarm(uint id) { // Write in memory the request to restore the alarm return numericalControl.PLC_WRestoreMessage(id); } public CmsError RefreshAllAlarms() { return numericalControl.PLC_WRefreshAllMessages(); } public CmsError PutSelectProcess(ushort procNumber) { return numericalControl.PROC_WSelectProcess(procNumber); } public CmsError PutSelectAxis(byte axisId) { return numericalControl.AXES_WSelectAxis(axisId); } public CmsError PutOverride(uint id, string action) { HEAD_OVERRIDE_SIGN sign = HEAD_OVERRIDE_SIGN.MINUS; if (action == "plus") sign = HEAD_OVERRIDE_SIGN.PLUS; CmsError cmsError = numericalControl.PLC_WHeadOverride(id, sign); return cmsError; } public CmsError PutPowerOnData(uint id) { // Set to true power on data by id return numericalControl.PLC_WPowerOnData(id, true); } #region Tools public CmsError AddTool(ref SiemensToolModel tool) { return numericalControl.TOOLS_WAddTool(ref tool); } public CmsError UpdateTool(ref SiemensToolModel tool) { return numericalControl.TOOLS_WUpdateTool(ref tool); } public CmsError AddFamily(string name, out FamilyModel family) { family = new FamilyModel() { Name = name }; return numericalControl.TOOLS_WAddFamily(ref family); } public CmsError AddShank(ref ShankModel shank) { return numericalControl.TOOLS_WAddShank(ref shank); } public CmsError UpdateShank(ref ShankModel shank) { return numericalControl.TOOLS_WUpdateShank(ref shank); } public CmsError UpdateFamilyName(string oldName, string newName) { return numericalControl.TOOLS_WUpdateFamilyData(oldName, newName); } public CmsError UpdateMagazinePosition(PositionModel magazinePosition) { return numericalControl.TOOLS_WUpdatePosition(magazinePosition); } public CmsError DeleteTool(int id) { return numericalControl.TOOLS_WDeleteTool(id); } public CmsError DeleteShank(int id) { return numericalControl.TOOLS_WDeleteShank(id); } public CmsError DeleteFamily(string name) { return numericalControl.TOOLS_WDeleteFamily(name); } public CmsError AddEdge(int toolId, ref EdgeModel edge) { return numericalControl.TOOLS_WAddEdge(toolId, ref edge); } public CmsError UpdateEdge(int toolId, ref EdgeModel edge) { return numericalControl.TOOLS_WUpdateEdge(toolId, ref edge); } public CmsError DeleteEdge(int toolId, int edgeId) { return numericalControl.TOOLS_WDeleteEdge(toolId, edgeId); } public CmsError GetMagazinePositionsAndTools(int magazineId, out List magazinePos) { magazinePos = new List(); return numericalControl.TOOLS_RMagazineTools(magazineId, ref magazinePos); } public CmsError GetNotInMagazinesTools(out List multiTools, out List tools) { multiTools = new List(); tools = new List(); return numericalControl.TOOLS_RAvailableTools(ref multiTools, ref tools); } public CmsError LoadToolInMagazine(int magazineId, NewToolInMagazineModel newMag) { return numericalControl.TOOLS_WLoadToolInMagazine(magazineId, newMag); } public CmsError UnloadToolInMagazine(int magazineId, int positionId) { return numericalControl.TOOLS_WUnloadToolInMagazine(magazineId, positionId); } public CmsError LoadTooolIntoShank(int shankId, int positionId, int toolId) { return numericalControl.TOOLS_WLoadToolIntoShank(shankId, positionId, toolId); } public CmsError UnloadTooolFromShank(int shankId, int positionId) { return numericalControl.TOOLS_WUnloadToolFromShank(shankId, positionId); } #endregion #endregion Write data } }