Added new alarm structure, and fixed Power on functions
This commit is contained in:
@@ -6,6 +6,7 @@ using CMS_CORE.Siemens;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using static CMS_CORE_Library.DataStructures;
|
||||
@@ -60,12 +61,12 @@ namespace CMS_CORE_Application
|
||||
DateTime NcTime = new DateTime();
|
||||
Dictionary<String, double> Axes = new Dictionary<String, double>();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
List<String> Alm = new List<string>();
|
||||
List<String> Msg = new List<string>();
|
||||
List<String> Alm2 = new List<string>();
|
||||
List<AlarmModel> procAlarms = new List<AlarmModel>();
|
||||
List<AlarmModel> Msg = new List<AlarmModel>();
|
||||
List<AlarmModel> ncAlarms = new List<AlarmModel>();
|
||||
List<String> Lines = new List<string>();
|
||||
PrePowerOnModel prePowerOn = new PrePowerOnModel();
|
||||
|
||||
|
||||
PostPowerOnModel postPowerOn = new PostPowerOnModel();
|
||||
|
||||
if (NCType == "Siemens")
|
||||
N = new Nc_Siemens(500);
|
||||
@@ -81,6 +82,7 @@ namespace CMS_CORE_Application
|
||||
N.NC_RProcessesNum(ref procnum);
|
||||
N.NC_RMachineNumber(ref MachNumber);
|
||||
bool error = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
sw.Restart();
|
||||
@@ -96,13 +98,13 @@ namespace CMS_CORE_Application
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
cmsError = N.PROC_RActiveAlarms(1, ref Alm);
|
||||
cmsError = N.PROC_RActiveAlarms(1, ref procAlarms);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
cmsError = N.NC_RActiveAlarms(ref Alm2);
|
||||
cmsError = N.NC_RActiveAlarms(ref ncAlarms);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
@@ -120,42 +122,44 @@ namespace CMS_CORE_Application
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
cmsError = N.PROC_RPPLines(1, ref Lines);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
cmsError = N.PROC_RPPName(1, ref PPName);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
|
||||
//cmsError = N.PROC_RPPLines(1, ref Lines);
|
||||
//if (cmsError.IsError())
|
||||
//{
|
||||
// error = true;
|
||||
// SetError(Lines, cmsError);
|
||||
//}
|
||||
|
||||
//cmsError = N.PROC_RPPName(1, ref PPName);
|
||||
//if (cmsError.IsError())
|
||||
//{
|
||||
// error = true;
|
||||
// SetError(Lines, cmsError);
|
||||
//}
|
||||
|
||||
cmsError = N.NC_RDateTime(ref NcTime);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
prePowerOn = new PrePowerOnModel()
|
||||
{
|
||||
PowerOn = true,
|
||||
ProtectionStatus = false,
|
||||
AirPressure = false,
|
||||
EmergencyButtons = false,
|
||||
SettingMode = false,
|
||||
StartingKey = true
|
||||
};
|
||||
|
||||
cmsError = N.Nc_RWPrePowerOnFunctions(Nc.W, ref prePowerOn);
|
||||
PreAndPostPowerOnModel preAndPostPowerOnModel = new PreAndPostPowerOnModel();
|
||||
cmsError = N.Nc_RPowerOnData(ref preAndPostPowerOnModel);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
|
||||
if (!error && !this.IsDisposed && this.InvokeRequired)
|
||||
cmsError = N.Nc_WPowerOnData(10, true);
|
||||
if (cmsError.IsError())
|
||||
{
|
||||
error = true;
|
||||
SetError(Lines, cmsError);
|
||||
}
|
||||
|
||||
if (!this.IsDisposed && this.InvokeRequired)
|
||||
{
|
||||
this.Invoke((ThreadStart)delegate ()
|
||||
{
|
||||
@@ -166,9 +170,9 @@ namespace CMS_CORE_Application
|
||||
TXTMachNum.Text = MachNumber;
|
||||
TXTSft.Text = SFTVersion;
|
||||
TXTTime.Text = sw.ElapsedMilliseconds.ToString() + " mS";
|
||||
TXTAlm.Text = String.Join(Environment.NewLine, Alm);
|
||||
TXTAlmNc.Text = String.Join(Environment.NewLine, Alm2);
|
||||
TXTMsg.Text = String.Join(Environment.NewLine, Msg);
|
||||
TXTAlm.Text = String.Join(Environment.NewLine, procAlarms.Select(x => x.message));
|
||||
TXTAlmNc.Text = String.Join(Environment.NewLine, ncAlarms.Select(x => x.message));
|
||||
TXTMsg.Text = String.Join(Environment.NewLine, Msg.Select(x => x.message));
|
||||
TXTPPName.Text = PPName;
|
||||
TXTNow.Text = NcTime.ToString();
|
||||
Error.Text = "";
|
||||
@@ -194,19 +198,7 @@ namespace CMS_CORE_Application
|
||||
{
|
||||
this.Invoke((ThreadStart)delegate ()
|
||||
{
|
||||
TXTPath1.Text = "";
|
||||
TXTStat1.Text = "";
|
||||
TXTNProcess.Text = "";
|
||||
TXTName.Text = "";
|
||||
TXTMachNum.Text = "";
|
||||
TXTSft.Text = "";
|
||||
TXTTime.Text = "";
|
||||
TXTAlm.Text = "";
|
||||
TXTAlmNc.Text = "";
|
||||
TXTMsg.Text = "";
|
||||
TXTPPName.Text = "";
|
||||
TXTNow.Text = "";
|
||||
TXTPPLines.Text = "";
|
||||
|
||||
Error.Text = cmsError.message;
|
||||
|
||||
TXTPPLines.Text = String.Join(Environment.NewLine, Lines);
|
||||
|
||||
@@ -73,15 +73,41 @@ namespace CMS_CORE_Library
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#region Data structor models
|
||||
|
||||
|
||||
public struct PreAndPostPowerOnModel
|
||||
{
|
||||
public PrePowerOnModel prePowerOn;
|
||||
public PostPowerOnModel postPowerOn;
|
||||
}
|
||||
public struct PowerOnDataModel
|
||||
{
|
||||
public uint Id;
|
||||
public bool Active;
|
||||
public bool Clickable;
|
||||
}
|
||||
|
||||
public class PrePowerOnModel
|
||||
{
|
||||
public bool PowerOn;
|
||||
public bool AirPressure;
|
||||
public bool ProtectionStatus;
|
||||
public bool EmergencyButtons;
|
||||
public bool SettingMode;
|
||||
public bool StartingKey;
|
||||
public PowerOnDataModel PowerOn;
|
||||
public PowerOnDataModel AirPressure;
|
||||
public PowerOnDataModel ProtectionStatus;
|
||||
public PowerOnDataModel EmergencyButtons;
|
||||
public PowerOnDataModel SettingMode;
|
||||
public PowerOnDataModel StartingKey;
|
||||
}
|
||||
|
||||
public class PostPowerOnModel
|
||||
{
|
||||
public PowerOnDataModel AxisReset;
|
||||
public PowerOnDataModel WaterjetPump;
|
||||
}
|
||||
|
||||
public class AlarmModel
|
||||
{
|
||||
public uint id;
|
||||
public string message;
|
||||
public bool isWarning;
|
||||
public int process;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -79,6 +79,9 @@ namespace Nc_Demo_Application.Server.Service
|
||||
[WebGet(UriTemplate = "binary_memory/integer/{index}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
|
||||
void GetInteger(string index, out int value);
|
||||
|
||||
[WebInvoke(Method = "PUT", UriTemplate = "binary_memory/boolean/{index}/{bit}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
|
||||
void PutBoolean(string index, string bit, BinaryMemoryModel body);
|
||||
|
||||
[WebInvoke(Method = "PUT", UriTemplate = "binary_memory/byte/{index}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
|
||||
void PutByte(string index, BinaryMemoryModel body);
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace CMS_CORE_Library.Demo.Models
|
||||
[DataContract]
|
||||
class BinaryMemoryModel
|
||||
{
|
||||
[DataMember]
|
||||
public bool boolean;
|
||||
[DataMember]
|
||||
public byte binary;
|
||||
[DataMember]
|
||||
|
||||
@@ -11,6 +11,7 @@ using Nc_Demo_Application.Server.Service;
|
||||
using CMS_CORE.Utils;
|
||||
using static CMS_CORE_Library.DataStructures;
|
||||
using System.Collections;
|
||||
using static CMS_CORE.Nc;
|
||||
|
||||
namespace CMS_CORE.Demo
|
||||
{
|
||||
@@ -204,67 +205,49 @@ namespace CMS_CORE.Demo
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError NC_RActiveAlarms(ref List<string> Alarms)
|
||||
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> Alarms)
|
||||
{
|
||||
Alarms.Clear();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_RWPrePowerOnFunctions(bool bWrite, ref PrePowerOnModel prePowerOnData)
|
||||
public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Read case: Read bit
|
||||
if (bWrite == R)
|
||||
{
|
||||
byte readedByte = 0;
|
||||
// read data from server
|
||||
CmsError cmsError = MEM_RWByte(bWrite, 0, 0, 0, 0, ref readedByte);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
// Convert a byte into PrePowerOn model
|
||||
bool[] bits = new bool[8];
|
||||
// Convert 1/0 to true/false
|
||||
bits = Convert.ToString(readedByte, 2).Select(s => s.Equals('1')).Reverse().ToArray();
|
||||
int readValue = 0;
|
||||
// Read pre power on and post power on data from memory
|
||||
CmsError cmsError = MEM_RWInteger(R, 0, MEMORY_ADDRESS.PRE_POWER_ON.MemType, MEMORY_ADDRESS.PRE_POWER_ON.Address, ref readValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
prePowerOnData = new PrePowerOnModel()
|
||||
{
|
||||
PowerOn = bits[0],
|
||||
AirPressure = bits[1],
|
||||
ProtectionStatus = bits[2],
|
||||
EmergencyButtons = bits[3],
|
||||
SettingMode = bits[4],
|
||||
StartingKey = bits[5]
|
||||
};
|
||||
}
|
||||
// Write case: write bit
|
||||
else
|
||||
bool[] bits = new bool[32];
|
||||
|
||||
// Convert int into to true/false array
|
||||
bits = new BitArray(new int[] { readValue }).Cast<bool>().ToArray();
|
||||
// Create adn set pre power on object
|
||||
PrePowerOnModel prePowerOn = new PrePowerOnModel()
|
||||
{
|
||||
// Create an array
|
||||
bool[] bitsArray = new bool[8]
|
||||
{
|
||||
prePowerOnData.PowerOn,
|
||||
prePowerOnData.AirPressure,
|
||||
prePowerOnData.ProtectionStatus,
|
||||
prePowerOnData.EmergencyButtons,
|
||||
prePowerOnData.SettingMode,
|
||||
prePowerOnData.StartingKey,
|
||||
false,false
|
||||
};
|
||||
// Create 1/0 string
|
||||
string bits = "";
|
||||
for(int i = 7; i >= 0; i--)
|
||||
{
|
||||
bits += bitsArray[i] ? "1" : "0";
|
||||
}
|
||||
// Convert to byte
|
||||
byte writeByte = Convert.ToByte(bits, 2);
|
||||
// Send data to server
|
||||
CmsError cmsError = MEM_RWByte(bWrite, 0, 0, 0, 0, ref writeByte);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
PowerOn = new PowerOnDataModel() { Id = 0, Active = bits[0], Clickable = bits[8] }, // id = N, bits = N, Clickable = N + 8 (Second bit)
|
||||
AirPressure = new PowerOnDataModel() { Id = 1, Active = bits[1], Clickable = bits[9] },
|
||||
ProtectionStatus = new PowerOnDataModel() { Id = 2, Active = bits[2], Clickable = bits[10] },
|
||||
EmergencyButtons = new PowerOnDataModel() { Id = 3, Active = bits[3], Clickable = bits[11] },
|
||||
SettingMode = new PowerOnDataModel() { Id = 4, Active = bits[4], Clickable = bits[12] },
|
||||
StartingKey = new PowerOnDataModel() { Id = 5, Active = bits[5], Clickable = bits[13] }
|
||||
};
|
||||
// Create and set post power on object
|
||||
PostPowerOnModel postPowerOn = new PostPowerOnModel()
|
||||
{
|
||||
AxisReset = new PowerOnDataModel() { Id = 8, Active = bits[16], Clickable = bits[24] }, // id = N - 8, bits = N, Clickable = N + 8 (Second bit)
|
||||
WaterjetPump = new PowerOnDataModel() { Id = 9, Active = bits[17], Clickable = bits[25] }
|
||||
};
|
||||
|
||||
powerOnModel = new PreAndPostPowerOnModel()
|
||||
{
|
||||
postPowerOn = postPowerOn,
|
||||
prePowerOn = prePowerOn
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -273,12 +256,35 @@ namespace CMS_CORE.Demo
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_WPowerOnData(uint id, bool value)
|
||||
{
|
||||
try
|
||||
{
|
||||
CmsError cmsError;
|
||||
// Check bit range
|
||||
if (id > 16)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
// Choose Pre-Power-On or Post-Power-Om
|
||||
if (id <= 8)
|
||||
// Pre: memory bit = id
|
||||
cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.PRE_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.PRE_POWER_ON_CLICKED.Address, (int)id, ref value);
|
||||
else
|
||||
// Post: memory bit = id - 8
|
||||
cmsError = MEM_RWBoolean(W, 0, MEMORY_ADDRESS.POST_POWER_ON_CLICKED.MemType, MEMORY_ADDRESS.POST_POWER_ON_CLICKED.Address, (int)id - 8, ref value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
#endregion
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#region PLC High-level data
|
||||
|
||||
public override CmsError PLC_RActiveMessages(ref List<String> Alarms)
|
||||
public override CmsError PLC_RActiveMessages(ref List<AlarmModel> alarms)
|
||||
{
|
||||
// Check if the NC Demo is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
@@ -287,7 +293,7 @@ namespace CMS_CORE.Demo
|
||||
|
||||
try
|
||||
{
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
|
||||
List<NcAlarmModel> demoAlarms;
|
||||
// Get Alarms from server
|
||||
@@ -295,7 +301,7 @@ namespace CMS_CORE.Demo
|
||||
// Parse response
|
||||
foreach (NcAlarmModel demoAlarm in demoAlarms)
|
||||
{
|
||||
Alarms.Add(demoAlarm.text);
|
||||
AddAlarmToList((uint)demoAlarm.id, demoAlarm.text, alarms);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -355,7 +361,7 @@ namespace CMS_CORE.Demo
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<string> Alarms)
|
||||
public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<AlarmModel> alarms)
|
||||
{
|
||||
// Check if the NC Demo is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
@@ -364,12 +370,13 @@ namespace CMS_CORE.Demo
|
||||
|
||||
try
|
||||
{
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
serverService.GetProcessAlarms(ProcNumber.ToString(), out List<NcAlarmModel> demoAlarms);
|
||||
|
||||
// Parse response
|
||||
foreach (NcAlarmModel demoAlarm in demoAlarms)
|
||||
{
|
||||
Alarms.Add(demoAlarm.text);
|
||||
AddAlarmToList((uint)demoAlarm.id, demoAlarm.text, demoAlarm.processId, alarms);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -541,7 +548,9 @@ namespace CMS_CORE.Demo
|
||||
// Write case: write bit
|
||||
else
|
||||
{
|
||||
|
||||
BinaryMemoryModel binaryMemoryModel = new BinaryMemoryModel();
|
||||
binaryMemoryModel.boolean = Value;
|
||||
serverService.PutBoolean(MemIndex.ToString(), MemBit.ToString(), binaryMemoryModel);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1085,6 +1094,19 @@ namespace CMS_CORE.Demo
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
internal static class MEMORY_ADDRESS
|
||||
{
|
||||
internal const int STARTING_ADDRESS = 0;
|
||||
|
||||
internal static MEMORY_CELL PRE_POWER_ON = new MEMORY_CELL(MEMORY_Type.Demo, 13, 0, 1);
|
||||
internal static MEMORY_CELL PRE_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_Type.Demo, 14, 0, 1);
|
||||
|
||||
internal static MEMORY_CELL POST_POWER_ON = new MEMORY_CELL(MEMORY_Type.Demo, 15, 0, 1);
|
||||
internal static MEMORY_CELL POST_POWER_ON_CLICKABLE = new MEMORY_CELL(MEMORY_Type.Demo, 16, 0, 1);
|
||||
|
||||
internal static MEMORY_CELL PRE_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_Type.Demo, 17, 0, 1);
|
||||
internal static MEMORY_CELL POST_POWER_ON_CLICKED = new MEMORY_CELL(MEMORY_Type.Demo, 18, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ namespace CMS_CORE.Fanuc
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_RWPrePowerOnFunctions(bool bWrite, ref PrePowerOnModel prePowerOnData)
|
||||
public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
@@ -324,14 +324,14 @@ namespace CMS_CORE.Fanuc
|
||||
|
||||
|
||||
//Get the NC Alarms
|
||||
public override CmsError NC_RActiveAlarms(ref List<string> Alarms)
|
||||
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> alarms)
|
||||
{
|
||||
//Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
|
||||
Focas1.ODBALMMSG2 Messg = new Focas1.ODBALMMSG2();
|
||||
short nReturn = 0;
|
||||
@@ -350,35 +350,38 @@ namespace CMS_CORE.Fanuc
|
||||
return GetNcError(nReturn);
|
||||
|
||||
//Add Alarm in List
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
if (count >= 1)
|
||||
Alarms.Add(Messg.msg1.alm_no + " " + Messg.msg1.alm_msg.Substring(0, Messg.msg1.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg1.alm_no, Messg.msg1.alm_msg.Substring(0, Messg.msg1.msg_len), alarms);
|
||||
if (count >= 2)
|
||||
Alarms.Add(Messg.msg2.alm_no + " " + Messg.msg2.alm_msg.Substring(0, Messg.msg2.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg2.alm_no, Messg.msg2.alm_msg.Substring(0, Messg.msg2.msg_len), alarms);
|
||||
if (count >= 3)
|
||||
Alarms.Add(Messg.msg3.alm_no + " " + Messg.msg3.alm_msg.Substring(0, Messg.msg3.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg3.alm_no, Messg.msg3.alm_msg.Substring(0, Messg.msg3.msg_len), alarms);
|
||||
if (count >= 4)
|
||||
Alarms.Add(Messg.msg4.alm_no + " " + Messg.msg4.alm_msg.Substring(0, Messg.msg4.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg4.alm_no, Messg.msg4.alm_msg.Substring(0, Messg.msg4.msg_len), alarms);
|
||||
if (count >= 5)
|
||||
Alarms.Add(Messg.msg5.alm_no + " " + Messg.msg5.alm_msg.Substring(0, Messg.msg5.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg5.alm_no, Messg.msg5.alm_msg.Substring(0, Messg.msg5.msg_len), alarms);
|
||||
if (count >= 6)
|
||||
Alarms.Add(Messg.msg6.alm_no + " " + Messg.msg6.alm_msg.Substring(0, Messg.msg6.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg6.alm_no, Messg.msg6.alm_msg.Substring(0, Messg.msg6.msg_len), alarms);
|
||||
if (count >= 7)
|
||||
Alarms.Add(Messg.msg7.alm_no + " " + Messg.msg7.alm_msg.Substring(0, Messg.msg7.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg7.alm_no, Messg.msg7.alm_msg.Substring(0, Messg.msg7.msg_len), alarms);
|
||||
if (count >= 8)
|
||||
Alarms.Add(Messg.msg8.alm_no + " " + Messg.msg8.alm_msg.Substring(0, Messg.msg8.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg8.alm_no, Messg.msg8.alm_msg.Substring(0, Messg.msg8.msg_len), alarms);
|
||||
if (count >= 9)
|
||||
Alarms.Add(Messg.msg9.alm_no + " " + Messg.msg9.alm_msg.Substring(0, Messg.msg9.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg9.alm_no, Messg.msg9.alm_msg.Substring(0, Messg.msg9.msg_len), alarms);
|
||||
if (count >= 10)
|
||||
Alarms.Add(Messg.msg10.alm_no + " " + Messg.msg10.alm_msg.Substring(0, Messg.msg10.msg_len));
|
||||
AddAlarmToList((uint)Messg.msg10.alm_no, Messg.msg10.alm_msg.Substring(0, Messg.msg10.msg_len), alarms);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
public override CmsError Nc_WPowerOnData(uint id, bool value)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
//Get the process Alarms
|
||||
public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<string> Alarms)
|
||||
public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<AlarmModel> Alarms)
|
||||
{
|
||||
Alarms.Clear();
|
||||
|
||||
@@ -469,7 +472,7 @@ namespace CMS_CORE.Fanuc
|
||||
|
||||
|
||||
//Get the PMC Messages
|
||||
public override CmsError PLC_RActiveMessages(ref List<String> Alarms)
|
||||
public override CmsError PLC_RActiveMessages(ref List<AlarmModel> alarms)
|
||||
{
|
||||
//Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
@@ -488,17 +491,23 @@ namespace CMS_CORE.Fanuc
|
||||
return GetNcError(nReturn);
|
||||
|
||||
//Add Alarm in List
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
|
||||
if (count >= 1 && Messg.msg1.datano >= 0)
|
||||
Alarms.Add(Messg.msg1.datano + " " + Messg.msg1.data);
|
||||
AddAlarmToList((uint)Messg.msg1.datano, Messg.msg1.data, alarms);
|
||||
|
||||
if (count >= 2 && Messg.msg2.datano >= 0)
|
||||
Alarms.Add(Messg.msg2.datano + " " + Messg.msg2.data);
|
||||
AddAlarmToList((uint)Messg.msg2.datano, Messg.msg2.data, alarms);
|
||||
|
||||
if (count >= 3 && Messg.msg3.datano >= 0)
|
||||
Alarms.Add(Messg.msg3.datano + " " + Messg.msg3.data);
|
||||
AddAlarmToList((uint)Messg.msg3.datano, Messg.msg3.data, alarms);
|
||||
|
||||
if (count >= 4 && Messg.msg4.datano >= 0)
|
||||
Alarms.Add(Messg.msg4.datano + " " + Messg.msg4.data);
|
||||
AddAlarmToList((uint)Messg.msg4.datano, Messg.msg4.data, alarms);
|
||||
|
||||
if (count >= 5 && Messg.msg5.datano >= 0)
|
||||
Alarms.Add(Messg.msg5.datano + " " + Messg.msg5.data);
|
||||
AddAlarmToList((uint)Messg.msg5.datano, Messg.msg5.data, alarms);
|
||||
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -1502,7 +1511,7 @@ namespace CMS_CORE.Fanuc
|
||||
|
||||
// If the 2 path are the same
|
||||
if (partProgramPath == newPartProgramPath)
|
||||
return GetNcError( 5); // TODO FIX
|
||||
return GetNcError(5); // TODO FIX
|
||||
|
||||
if (failIfExist)
|
||||
{
|
||||
|
||||
+49
-14
@@ -286,20 +286,27 @@ namespace CMS_CORE
|
||||
* </summary>
|
||||
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
* <param name="ProcNumber">Process to execute the action</param>
|
||||
* <param name="Alarms">Reference of a List of String Variables where data will be saved</param>
|
||||
* <param name="alarms">Reference of a List of String Variables where data will be saved</param>
|
||||
* */
|
||||
public abstract CmsError NC_RActiveAlarms(ref List<String> Alarms);
|
||||
public abstract CmsError NC_RActiveAlarms(ref List<AlarmModel> alarms);
|
||||
|
||||
/**
|
||||
* <summary>
|
||||
* Read the status of the Power on data ( Pre-Power-On / Post-Power-On )
|
||||
* <para>
|
||||
* Compatibility: Fanuc | Osai | Demo | Siemens
|
||||
* </para>
|
||||
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
* </summary>
|
||||
* <param name="bWrite">Set True to Write-operation (Also Allowed <see cref="W"/>/<see cref="R"/>)</param>
|
||||
* <param name="powerOnModel"> Reference to the structure where the power on data will be saved</param>
|
||||
**/
|
||||
public abstract CmsError Nc_RWPrePowerOnFunctions(Boolean bWrite, ref PrePowerOnModel prePowerOnData);
|
||||
public abstract CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel);
|
||||
|
||||
/**
|
||||
*
|
||||
**/
|
||||
public abstract CmsError Nc_WPowerOnData(uint id, bool value);
|
||||
|
||||
#endregion
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -380,7 +387,7 @@ namespace CMS_CORE
|
||||
* <returns cref="CmsError">Returns an error when an internal or a library error occours</returns>
|
||||
* <param name="Alarms">Reference of a List of String Variables where data will be saved</param>
|
||||
* */
|
||||
public abstract CmsError PLC_RActiveMessages(ref List<String> Alarms);
|
||||
public abstract CmsError PLC_RActiveMessages(ref List<AlarmModel> Alarms);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -427,7 +434,7 @@ namespace CMS_CORE
|
||||
* <param name="ProcNumber">Process to execute the action</param>
|
||||
* <param name="Alarms">Reference of a List of String Variables where data will be saved</param>
|
||||
* */
|
||||
public abstract CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<String> Alarms);
|
||||
public abstract CmsError PROC_RActiveAlarms(ushort procNumber, ref List<AlarmModel> alarms);
|
||||
|
||||
|
||||
/**
|
||||
@@ -1123,7 +1130,12 @@ namespace CMS_CORE
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//Siemens Memory Type,
|
||||
/** <summary>Siemens DB</summary> */
|
||||
Siemens_DB = 0
|
||||
Siemens_DB = 0,
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// Demo memory type
|
||||
/**<summary>Demo default memory</summary> **/
|
||||
Demo = 0
|
||||
};
|
||||
|
||||
// NC Memory Type Name
|
||||
@@ -1160,14 +1172,14 @@ namespace CMS_CORE
|
||||
#region Fixed memory area
|
||||
|
||||
// R-W MEMORY Cell
|
||||
internal struct MEMORY_Cell
|
||||
internal struct MEMORY_CELL
|
||||
{
|
||||
public readonly MEMORY_Type MemType;
|
||||
public readonly int Address;
|
||||
public readonly int SubAddress; //Only for Siemens
|
||||
public readonly int Size;
|
||||
|
||||
public MEMORY_Cell(MEMORY_Type MType, int Addr, int SubAddr, int Sz)
|
||||
public MEMORY_CELL(MEMORY_Type MType, int Addr, int SubAddr, int Sz)
|
||||
{
|
||||
MemType = MType;
|
||||
Address = Addr;
|
||||
@@ -1177,17 +1189,40 @@ namespace CMS_CORE
|
||||
}
|
||||
|
||||
//Lingua CN
|
||||
internal MEMORY_Cell PARAM_LING_FANUC = new MEMORY_Cell(MEMORY_Type.Null, 3281, 0, 1);
|
||||
internal MEMORY_CELL PARAM_LING_FANUC = new MEMORY_CELL(MEMORY_Type.Null, 3281, 0, 1);
|
||||
|
||||
//Matricola Macchina
|
||||
internal MEMORY_Cell MATR_MACCH_OSAI = new MEMORY_Cell(MEMORY_Type.Osai_MW, 3403, 0, 1);
|
||||
internal MEMORY_Cell MATR_MACCH_FANUC = new MEMORY_Cell(MEMORY_Type.Fanuc_D, 4018, 0, 1);
|
||||
internal MEMORY_Cell MATR_MACCH_SIEMENS = new MEMORY_Cell(MEMORY_Type.Siemens_DB, 255, 0, 1);
|
||||
internal MEMORY_CELL MATR_MACCH_OSAI = new MEMORY_CELL(MEMORY_Type.Osai_MW, 3403, 0, 1);
|
||||
internal MEMORY_CELL MATR_MACCH_FANUC = new MEMORY_CELL(MEMORY_Type.Fanuc_D, 4018, 0, 1);
|
||||
internal MEMORY_CELL MATR_MACCH_SIEMENS = new MEMORY_CELL(MEMORY_Type.Siemens_DB, 255, 0, 1);
|
||||
|
||||
//Messaggi PLC
|
||||
internal MEMORY_Cell PLC_MESS_OSAI = new MEMORY_Cell(MEMORY_Type.Osai_MW, 12000, 0, 64);
|
||||
internal MEMORY_CELL PLC_MESS_OSAI = new MEMORY_CELL(MEMORY_Type.Osai_MW, 12000, 0, 64);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
internal void AddAlarmToList(uint id, string message, List<AlarmModel> alarms)
|
||||
{
|
||||
alarms.Add(new AlarmModel()
|
||||
{
|
||||
id = id,
|
||||
message = message,
|
||||
isWarning = false,
|
||||
process = 0
|
||||
});
|
||||
}
|
||||
|
||||
internal void AddAlarmToList(uint id, string message, int process, List<AlarmModel> alarms)
|
||||
{
|
||||
alarms.Add(new AlarmModel()
|
||||
{
|
||||
id = id,
|
||||
message = message,
|
||||
isWarning = false,
|
||||
process = process
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace CMS_CORE.Osai
|
||||
private ushort timeOutConn;
|
||||
private EndpointAddress endPointAddress;
|
||||
private BasicHttpBinding HttpBinding;
|
||||
private static String[] PlcMessages;
|
||||
private static Dictionary<int,string> PlcMessages;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -61,7 +61,6 @@ namespace CMS_CORE.Osai
|
||||
//Read Plc Messages
|
||||
if (PlcMessages == null)
|
||||
{
|
||||
PlcMessages = new string[] { };
|
||||
ReadPlcMessages();
|
||||
}
|
||||
}
|
||||
@@ -238,18 +237,23 @@ namespace CMS_CORE.Osai
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_RWPrePowerOnFunctions(bool bWrite, ref PrePowerOnModel prePowerOnData)
|
||||
public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_WPowerOnData(uint id, bool value)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
//Get the PLC Active Alarms
|
||||
public override CmsError PLC_RActiveMessages(ref List<String> Alarms)
|
||||
public override CmsError PLC_RActiveMessages(ref List<AlarmModel> alarms)
|
||||
{
|
||||
List<ushort> list = new List<ushort>();
|
||||
BitArray Bits;
|
||||
int Index;
|
||||
Alarms.Clear();
|
||||
int index;
|
||||
alarms.Clear();
|
||||
|
||||
//Execute the method
|
||||
CmsError cmsError = MEM_RWWordList(R, 0, PLC_MESS_OSAI.MemType, PLC_MESS_OSAI.Address, PLC_MESS_OSAI.Size, ref list);
|
||||
@@ -264,11 +268,19 @@ namespace CMS_CORE.Osai
|
||||
Bits = new BitArray(BitConverter.GetBytes(list[i]));
|
||||
for (int j = 0; j < Bits.Count; j++)
|
||||
{
|
||||
Index = (i * 16) + (j);
|
||||
if (Bits[j] && Index < PlcMessages.Length)
|
||||
index = (i * 16) + j + 1;
|
||||
string message = "";
|
||||
// If bit == true
|
||||
if (Bits[j])
|
||||
{
|
||||
Alarms.Add(PlcMessages[Index].Trim());
|
||||
bool messageKeyFound = PlcMessages.TryGetValue(index, out message);
|
||||
if (messageKeyFound && !string.IsNullOrWhiteSpace(message))
|
||||
AddAlarmToList((uint)index, message.Trim(), alarms); // Add message to list
|
||||
else
|
||||
AddAlarmToList((uint)index, "PLC Message not found, PLC error code : " + index, alarms); // Add message not found with error code
|
||||
}
|
||||
// Find key
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +340,7 @@ namespace CMS_CORE.Osai
|
||||
|
||||
|
||||
//Get the Nc Alarm
|
||||
public override CmsError NC_RActiveAlarms(ref List<string> Alarms)
|
||||
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> alarms)
|
||||
{
|
||||
//Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
@@ -343,7 +355,7 @@ namespace CMS_CORE.Osai
|
||||
try
|
||||
{
|
||||
//Clear the OLD Message
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
|
||||
//Execute the method
|
||||
nReturn = OpenNC.ReadCurrentEmergMsg(0, out errEmgy, out errorClass, out errorNum);
|
||||
@@ -357,12 +369,12 @@ namespace CMS_CORE.Osai
|
||||
{
|
||||
MESSAGE_TEXT MessageEmgy = new MESSAGE_TEXT();
|
||||
Cndex.MSG_EMERGENCY CndexErrorEmgy = ConverToCndexMessage(errEmgy);
|
||||
|
||||
|
||||
//Translate using OSAI .DLL (a new one!)
|
||||
OSAIErrorManagerLibrary.TranslateEmergMsg(ref CndexErrorEmgy, ref MessageEmgy);
|
||||
|
||||
//Build the new String Message
|
||||
Alarms.Add(OsaiToStepMessage(MessageEmgy));
|
||||
//Add alarm to list with the new converted string message
|
||||
AddAlarmToList((uint)CndexErrorEmgy.Code_Err, OsaiToStepMessage(MessageEmgy), alarms);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -373,8 +385,6 @@ namespace CMS_CORE.Osai
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Get the process status
|
||||
public override CmsError PROC_RStatus(ushort Number, ref PROC_Status Status)
|
||||
{
|
||||
@@ -445,7 +455,7 @@ namespace CMS_CORE.Osai
|
||||
|
||||
|
||||
//Get the process Alarm
|
||||
public override CmsError PROC_RActiveAlarms(ushort Number, ref List<String> Alarms)
|
||||
public override CmsError PROC_RActiveAlarms(ushort procNumber, ref List<AlarmModel> alarms)
|
||||
{
|
||||
//Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
@@ -460,10 +470,10 @@ namespace CMS_CORE.Osai
|
||||
try
|
||||
{
|
||||
//Clear the OLD Message
|
||||
Alarms.Clear();
|
||||
alarms.Clear();
|
||||
|
||||
//Execute the method
|
||||
nReturn = OpenNC.ReadCurrentErrorMsg(Number, out err, out errorClass, out errorNum);
|
||||
nReturn = OpenNC.ReadCurrentErrorMsg(procNumber, out err, out errorClass, out errorNum);
|
||||
|
||||
//If there's an error launch exception
|
||||
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
|
||||
@@ -480,8 +490,7 @@ namespace CMS_CORE.Osai
|
||||
OSAIErrorManagerLibrary.TranslateErrorMsg(ref CndexError, ref Message);
|
||||
|
||||
//Build the new String Message
|
||||
Alarms.Add(OsaiToStepMessage(Message));
|
||||
|
||||
AddAlarmToList((uint)CndexError.Code_Err, OsaiToStepMessage(Message), procNumber, alarms);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1630,19 +1639,13 @@ namespace CMS_CORE.Osai
|
||||
String Path;
|
||||
try
|
||||
{
|
||||
PlcMessages = new Dictionary<int, string>();
|
||||
|
||||
//Setup the Path
|
||||
Path = OSAI_PlcMessagesPath + @"Messaggi_" + OsaiLanguages + @".txt";
|
||||
|
||||
//Read From Files
|
||||
PlcMessages = File.ReadAllLines(Path);
|
||||
|
||||
//Delete the first part of the string
|
||||
for (int i = 0; i < PlcMessages.Length; i++)
|
||||
{
|
||||
SPlitted = PlcMessages[i].Split(',');
|
||||
if (SPlitted.Length > 1)
|
||||
PlcMessages[i] = SPlitted[1];
|
||||
}
|
||||
PlcMessages = File.ReadAllLines(Path).Select(line => line.Split(',')).ToDictionary(line => Convert.ToInt32(line[0]), line => line[1]);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -245,7 +245,12 @@ namespace CMS_CORE.Siemens
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_RWPrePowerOnFunctions(bool bWrite, ref PrePowerOnModel prePowerOnData)
|
||||
public override CmsError Nc_RPowerOnData(ref PreAndPostPowerOnModel powerOnModel)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError Nc_WPowerOnData(uint id, bool value)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
@@ -409,12 +414,15 @@ namespace CMS_CORE.Siemens
|
||||
|
||||
|
||||
//Get the Nc Active Alarms
|
||||
public override CmsError NC_RActiveAlarms(ref List<string> Alarms)
|
||||
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> Alarms)
|
||||
{
|
||||
if (SiemensAlarms == null)
|
||||
return null;
|
||||
|
||||
Alarms = SiemensAlarms.Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel)).Select(x => x.Message).ToList();
|
||||
Alarms = SiemensAlarms.
|
||||
Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel))
|
||||
.Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = 0 })
|
||||
.ToList();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -422,9 +430,12 @@ namespace CMS_CORE.Siemens
|
||||
|
||||
|
||||
//Get the PLC Active Messages
|
||||
public override CmsError PLC_RActiveMessages(ref List<string> Alarms)
|
||||
public override CmsError PLC_RActiveMessages(ref List<AlarmModel> alarms)
|
||||
{
|
||||
Alarms = SiemensAlarms.Where(x => x.Id >= IDMinPLCMessage && x.Id <= IDMaxPLCMessage).Select(x => x.Message).ToList();
|
||||
alarms = SiemensAlarms
|
||||
.Where(x => x.Id >= IDMinPLCMessage && x.Id <= IDMaxPLCMessage)
|
||||
.Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = 0})
|
||||
.ToList();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -432,9 +443,12 @@ namespace CMS_CORE.Siemens
|
||||
|
||||
|
||||
//Get the process Active Alarms
|
||||
public override CmsError PROC_RActiveAlarms(ushort ProcNumber, ref List<string> Alarms)
|
||||
public override CmsError PROC_RActiveAlarms(ushort procNumber, ref List<AlarmModel> alarms)
|
||||
{
|
||||
Alarms = SiemensAlarms.Where(x => x.Id >= IDMinChannel && x.Id <= IDMaxChannel && x.Parameters[0].Equals(ProcNumber.ToString())).Select(x => x.Message).ToList();
|
||||
alarms = SiemensAlarms
|
||||
.Where(x => x.Id >= IDMinChannel && x.Id <= IDMaxChannel && x.Parameters[0].Equals(procNumber.ToString()))
|
||||
.Select(x => new AlarmModel() { id = (uint)x.Id, message = x.Message, isWarning = false, process = procNumber })
|
||||
.ToList();
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Data.SQLite;
|
||||
using System.Net;
|
||||
using System.ServiceModel;
|
||||
using System.ServiceModel.Web;
|
||||
using System.Text;
|
||||
using Nc_Demo_Application.Database.Models;
|
||||
using static Nc_Demo_Application.Constants;
|
||||
|
||||
@@ -55,7 +56,7 @@ namespace Nc_Demo_Application.Database
|
||||
// Setup a new database connection
|
||||
private void SetConnection()
|
||||
{
|
||||
if(sqlConnection == null)
|
||||
if (sqlConnection == null)
|
||||
sqlConnection = new SQLiteConnection("Data Source=" + RUNNING_PATH_DIR + DATABASE_FILE_NAME + ";Version=3;New=False;");
|
||||
}
|
||||
|
||||
@@ -86,8 +87,8 @@ namespace Nc_Demo_Application.Database
|
||||
}
|
||||
|
||||
#region Nc Data Methods
|
||||
public NcDataModel ReadNcData ()
|
||||
{
|
||||
public NcDataModel ReadNcData()
|
||||
{
|
||||
try
|
||||
{
|
||||
ReadDataFromDatabase(READ_NC_DATA_QUERY, ref ncDatatable);
|
||||
@@ -101,7 +102,7 @@ namespace Nc_Demo_Application.Database
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public NcDataModel GetNcData()
|
||||
{
|
||||
NcDataModel ncDataModel = new NcDataModel();
|
||||
@@ -154,7 +155,7 @@ namespace Nc_Demo_Application.Database
|
||||
// Close the connection with database
|
||||
sqlConnection.Close();
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("ReadNcData exception: " + ex.Message);
|
||||
}
|
||||
@@ -371,7 +372,7 @@ namespace Nc_Demo_Application.Database
|
||||
ReadDataFromDatabase(READ_BINARY_MEMORY_QUERY, ref BinaryMemory);
|
||||
|
||||
SetBinaryMemoryDataTableData();
|
||||
|
||||
|
||||
return BinaryMemory;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -466,7 +467,7 @@ namespace Nc_Demo_Application.Database
|
||||
|
||||
string integer = "";
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Get N byte of integer value
|
||||
integer = GetBinaryByteValue(index + i) + integer;
|
||||
@@ -474,6 +475,21 @@ namespace Nc_Demo_Application.Database
|
||||
return integer;
|
||||
}
|
||||
|
||||
public void PutBooleanValue(int index, int bit, bool value)
|
||||
{
|
||||
ValidateIndex(index);
|
||||
if (bit > 8)
|
||||
throw new WebFaultException(HttpStatusCode.BadRequest);
|
||||
|
||||
string binary = GetBinaryByteValue(index);
|
||||
|
||||
StringBuilder sb = new StringBuilder(binary);
|
||||
sb[7 - bit] = value ? '1' : '0';
|
||||
binary = sb.ToString();
|
||||
|
||||
PutByteValue(index, Convert.ToByte(binary,2));
|
||||
}
|
||||
|
||||
public void PutByteValue(int index, byte value)
|
||||
{
|
||||
ValidateIndex(index);
|
||||
@@ -518,7 +534,7 @@ namespace Nc_Demo_Application.Database
|
||||
|
||||
// Convert to binary the new integer value
|
||||
string binaryValue = Convert.ToString(value, 2).PadLeft(32, '0');
|
||||
for(int i = 0; i < 4; i++)
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Find next byte position (24-16-8-0)
|
||||
int startByte = 32 - (8 * (i + 1));
|
||||
@@ -547,7 +563,7 @@ namespace Nc_Demo_Application.Database
|
||||
|
||||
private void ValidateIndex(int index)
|
||||
{
|
||||
if(index > BinaryMemory.Rows.Count)
|
||||
if (index > BinaryMemory.Rows.Count)
|
||||
{
|
||||
throw new WebFaultException(HttpStatusCode.BadRequest);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Nc_Demo_Application.Database.Models
|
||||
[DataContract]
|
||||
class BinaryMemoryModel
|
||||
{
|
||||
[DataMember]
|
||||
public bool boolean;
|
||||
[DataMember]
|
||||
public byte binary;
|
||||
[DataMember]
|
||||
|
||||
@@ -83,7 +83,10 @@ namespace Nc_Demo_Application.Server.Service
|
||||
[WebGet(UriTemplate = "binary_memory/integer/{index}", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
|
||||
void GetInteger(string index, out int value);
|
||||
|
||||
[WebInvoke(Method = "PUT", UriTemplate = "binary_memory/byte/{index}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
|
||||
[WebInvoke(Method = "PUT", UriTemplate = "binary_memory/boolean/{index}/{bit}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
|
||||
void PutBoolean(string index, string bit, BinaryMemoryModel body);
|
||||
|
||||
[WebInvoke(Method = "PUT", UriTemplate = "binary_memory/byte/{index}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
|
||||
void PutByte(string index, BinaryMemoryModel body);
|
||||
|
||||
[WebInvoke(Method = "PUT", UriTemplate = "binary_memory/word/{index}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
|
||||
|
||||
@@ -135,6 +135,16 @@ namespace Nc_Demo_Application.Server.Service
|
||||
value = Convert.ToInt32(DatabaseController.getInstance().GetIntegerValue(Convert.ToInt32(index)), 2);
|
||||
}
|
||||
|
||||
public void PutBoolean(string index, string bit, BinaryMemoryModel body)
|
||||
{
|
||||
if (body == null)
|
||||
{
|
||||
throw new WebFaultException(HttpStatusCode.BadRequest);
|
||||
}
|
||||
// Edit boolean
|
||||
DatabaseController.getInstance().PutBooleanValue(Convert.ToInt32(index), Convert.ToInt32(bit), body.boolean);
|
||||
}
|
||||
|
||||
public void PutByte(string index, BinaryMemoryModel body)
|
||||
{
|
||||
if (body == null)
|
||||
|
||||
Reference in New Issue
Block a user