Added PLC and NC alarms into demo

This commit is contained in:
Lucio Maranta
2018-02-09 15:04:49 +00:00
parent d08bf19bc5
commit 046387ff3b
6 changed files with 73 additions and 30 deletions
+9 -14
View File
@@ -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
}
}
}
+6
View File
@@ -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<NcAlarmModel> alarms);
[WebGet(UriTemplate = "plc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void PlcAlarms(out List<NcAlarmModel> alarms);
#endregion
#region Process API
+26 -5
View File
@@ -215,9 +215,30 @@ namespace CMS_CORE.Demo
return NO_ERROR;
}
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> Alarms)
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> alarms)
{
Alarms.Clear();
// Check if the NC Demo is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
try
{
alarms.Clear();
List<NcAlarmModel> 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<NcAlarmModel> 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)
@@ -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)
@@ -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<NcAlarmModel> alarms);
[WebGet(UriTemplate = "plc/alarms", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
void PlcAlarms(out List<NcAlarmModel> alarms);
#endregion
#region Process API
@@ -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<NcAlarmModel> alarms)
{
List<NcAlarmModel> ncAlarmsData = DatabaseController.getInstance().GetNcAlarms();
alarms = ncAlarmsData.FindAll(i => i.processId == 0);
}
public void PlcAlarms(out List<NcAlarmModel> alarms)
{
List<NcAlarmModel> ncAlarmsData = DatabaseController.getInstance().GetNcAlarms();
alarms = ncAlarmsData.FindAll(i => i.processId == -1);
}
public void ProcessAlarms(string id, out List<NcAlarmModel> alarms)
{
CheckProcess(Convert.ToInt32(id));
List<NcAlarmModel> ncAlarmsData = DatabaseController.getInstance().GetNcAlarms();
alarms = ncAlarmsData.FindAll(i => i.processId == Convert.ToInt32(id));
List<NcAlarmModel> procAlarmsData = DatabaseController.getInstance().GetNcAlarms();
alarms = procAlarmsData.FindAll(i => i.processId == Convert.ToInt32(id) && i.processId != 0 && i.processId != -1);
}
public void ProcessesAlarms(out List<NcAlarmModel> alarms)
{
alarms = DatabaseController.getInstance().GetNcAlarms();
List<NcAlarmModel> 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<int>();
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));
}
}