diff --git a/CMS_CORE_Library/DataStructures.cs b/CMS_CORE_Library/DataStructures.cs index e9f3f2e..c7e0e93 100644 --- a/CMS_CORE_Library/DataStructures.cs +++ b/CMS_CORE_Library/DataStructures.cs @@ -1,22 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static CMS_CORE.Nc; - -namespace CMS_CORE_Library +namespace CMS_CORE_Library { public static class DataStructures { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Data structor models public struct PreAndPostPowerOnModel { - public PrePowerOnModel prePowerOn; - public PostPowerOnModel postPowerOn; + public PrePowerOnModel PrePowerOn; + public PostPowerOnModel PostPowerOn; } + public struct PowerOnDataModel { public uint Id; @@ -77,9 +72,10 @@ namespace CMS_CORE_Library public int Percentage; } - #endregion + #endregion Data structor models /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + #region Cms Errors Codes public enum CMS_ERROR_CODES : uint @@ -98,7 +94,6 @@ namespace CMS_CORE_Library SIEMENS_HMI_NOT_RUNNING = 11 } - public class CmsError { public CMS_ERROR_CODES errorCode; @@ -140,6 +135,6 @@ namespace CMS_CORE_Library internal static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND, "CMS-Core-Error: Siemens Environment not found"); internal static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "CMS-Core-Error: Siemens HMI is not Running / Ready"); - #endregion + #endregion Cms Errors Codes } -} +} \ No newline at end of file diff --git a/CMS_CORE_Library/Demo/ILibraryService.cs b/CMS_CORE_Library/Demo/ILibraryService.cs index 5292dc8..0200fa8 100644 --- a/CMS_CORE_Library/Demo/ILibraryService.cs +++ b/CMS_CORE_Library/Demo/ILibraryService.cs @@ -37,6 +37,12 @@ namespace Nc_Demo_Application.Server.Service [WebGet(UriTemplate = "cn/process_number/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void GetProcessNumber(out ushort processNumber); + [WebGet(UriTemplate = "nc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] + void NcAlarms(out List alarms); + + [WebGet(UriTemplate = "plc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] + void PlcAlarms(out List alarms); + #endregion #region Process API diff --git a/CMS_CORE_Library/Demo/Nc_Demo.cs b/CMS_CORE_Library/Demo/Nc_Demo.cs index bd19cc3..07ddccb 100644 --- a/CMS_CORE_Library/Demo/Nc_Demo.cs +++ b/CMS_CORE_Library/Demo/Nc_Demo.cs @@ -215,9 +215,30 @@ namespace CMS_CORE.Demo return NO_ERROR; } - public override CmsError NC_RActiveAlarms(ref List Alarms) + public override CmsError NC_RActiveAlarms(ref List alarms) { - Alarms.Clear(); + // Check if the NC Demo is Connected + CmsError cmsError = CheckConnection(); + if (cmsError.IsError()) + return cmsError; + + try + { + alarms.Clear(); + + List demoAlarms; + // Get Alarms from server + serverService.NcAlarms(out demoAlarms); + // Parse response + foreach (NcAlarmModel demoAlarm in demoAlarms) + { + AddAlarmToList((uint)demoAlarm.code, demoAlarm.text, alarms); + } + } + catch (Exception ex) + { + return ManageException(ex); + } return NO_ERROR; } @@ -269,7 +290,7 @@ namespace CMS_CORE.Demo List demoAlarms; // Get Alarms from server - serverService.GetProcessesAlarms(out demoAlarms); + serverService.PlcAlarms(out demoAlarms); // Parse response foreach (NcAlarmModel demoAlarm in demoAlarms) { @@ -317,8 +338,8 @@ namespace CMS_CORE.Demo powerOnModel = new PreAndPostPowerOnModel() { - postPowerOn = postPowerOn, - prePowerOn = prePowerOn + PostPowerOn = postPowerOn, + PrePowerOn = prePowerOn }; } catch (Exception ex) diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs index f8a7a9b..dea2361 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Database/DatabaseController.cs @@ -266,6 +266,7 @@ namespace Nc_Demo_Application.Database code = Convert.ToInt32(row["code"]), processId = Convert.ToInt32(row["process_id"]) }; + alarms.Add(tmpAlarm); } @@ -391,7 +392,7 @@ namespace Nc_Demo_Application.Database foreach (DataRow row in BinaryMemory.Rows) { // Populate binary column for each row int -> binary - row["binary"] = Convert.ToString(Convert.ToInt32(row["value"].ToString(), 10), 2).PadLeft(8, '0').Substring(0,8); + row["binary"] = Convert.ToString(Convert.ToInt32(row["value"].ToString(), 10), 2).PadLeft(8, '0').Substring(0, 8); // Add binary value to word and integer word = row["binary"] + word; integer = row["binary"] + integer; @@ -488,8 +489,8 @@ namespace Nc_Demo_Application.Database StringBuilder sb = new StringBuilder(binary); sb[7 - bit] = value ? '1' : '0'; binary = sb.ToString(); - - PutByteValue(index, Convert.ToByte(binary,2)); + + PutByteValue(index, Convert.ToByte(binary, 2)); } public void PutByteValue(int index, byte value) diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/ILibraryService.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/ILibraryService.cs index 2803c3f..ca6bbe6 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/ILibraryService.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/ILibraryService.cs @@ -35,6 +35,12 @@ namespace Nc_Demo_Application.Server.Service [WebGet(UriTemplate = "cn/machine_number/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] void MachineNumber(out string machineNumber); + [WebGet(UriTemplate = "nc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] + void NcAlarms(out List alarms); + + [WebGet(UriTemplate = "plc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] + void PlcAlarms(out List alarms); + #endregion #region Process API diff --git a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs index 236d8e9..8340c52 100644 --- a/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs +++ b/CMS_CORE_Nc_Demo_Application/Nc_Demo_Application/Server/Service/LibraryService.cs @@ -21,7 +21,7 @@ namespace Nc_Demo_Application.Server.Service public void Name(out string name) { ncDataData = DatabaseController.getInstance().GetNcData(); - name = ncDataData.name; + name = ncDataData.name; } public void DateTime(out string dateTime) @@ -60,7 +60,7 @@ namespace Nc_Demo_Application.Server.Service softwareVersion = ncDataData.softwareVersion; } #endregion - + #region Process API public void ProcessNumber(out ushort processNumber) { @@ -91,22 +91,36 @@ namespace Nc_Demo_Application.Server.Service mode = ncProcessesData.Find(i => i.id == Convert.ToInt32(id)).mode; } + public void NcAlarms(out List alarms) + { + List ncAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + alarms = ncAlarmsData.FindAll(i => i.processId == 0); + } + + public void PlcAlarms(out List alarms) + { + List ncAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + alarms = ncAlarmsData.FindAll(i => i.processId == -1); + } + public void ProcessAlarms(string id, out List alarms) { CheckProcess(Convert.ToInt32(id)); - List ncAlarmsData = DatabaseController.getInstance().GetNcAlarms(); - alarms = ncAlarmsData.FindAll(i => i.processId == Convert.ToInt32(id)); + List procAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + alarms = procAlarmsData.FindAll(i => i.processId == Convert.ToInt32(id) && i.processId != 0 && i.processId != -1); } + public void ProcessesAlarms(out List alarms) { - alarms = DatabaseController.getInstance().GetNcAlarms(); + List procAlarmsData = DatabaseController.getInstance().GetNcAlarms(); + alarms = procAlarmsData.FindAll(i => i.processId != 0 && i.processId != -1); } private void CheckProcess(int processId) { ProcessNumber(out ushort processNumber); - if( processId > processNumber) + if (processId > processNumber) throw new WebFaultException(HttpStatusCode.BadRequest); } @@ -208,7 +222,7 @@ namespace Nc_Demo_Application.Server.Service public void PutDWord(string index, BinaryMemoryModel body) { - if(body == null) + if (body == null) { throw new WebFaultException(HttpStatusCode.BadRequest); } @@ -256,7 +270,7 @@ namespace Nc_Demo_Application.Server.Service integerList = new List(); for (int i = 0; i < Convert.ToInt32(number); i++) { - integerList.Add(Convert.ToInt32(DatabaseController.getInstance().GetIntegerValue(idx + (4*i)), 2)); + integerList.Add(Convert.ToInt32(DatabaseController.getInstance().GetIntegerValue(idx + (4 * i)), 2)); } }