WIP Fix Siemens/Nc_Siemens.cs

This commit is contained in:
Lucio Maranta
2019-03-04 16:23:57 +00:00
parent d2ffa50b5b
commit d0f259c2eb
8 changed files with 391 additions and 153 deletions
+5 -6
View File
@@ -108,18 +108,17 @@ namespace CMS_CORE_Application
N.PLC_ROperatorInputIsNeeded(ref b);
////////////////////////////////////////// TEST
////////////////////////////////////////////////////////////// TEST
Stopwatch st = new Stopwatch();
sw.Restart();
ActiveProgramDataModel active = new ActiveProgramDataModel();
string name = "";
N.PROC_RSelectedPPName(1, ref name);
cmsError = N.FILES_RActiveProgramData(1, ref active);
SelectedProcessData selected = new SelectedProcessData();
cmsError = N.PROC_RSelectedProcessData(1, ref selected);
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
/////////////////////////////////////////// END TEST
////////////////////////////////////////////////////////////// END TEST
if (!this.IsDisposed && this.InvokeRequired)
{
this.Invoke((ThreadStart)delegate ()
+5
View File
@@ -1604,6 +1604,11 @@ namespace CMS_CORE_Library.Demo
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError MEM_RWByteList(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, int MemByteStart, int Number, ref List<byte> Value)
{
return MEM_RWByteList(bWrite, Process, MemType, MemIndex, MemByteStart, Number, ref Value);
+100 -16
View File
@@ -861,20 +861,44 @@ namespace CMS_CORE_Library.Fanuc
// Parse line & get parameters
parameters = ExtractM155ParametersFromNcCodeLine(actualLine, '(', ')');
byte i = 1;
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x);
value.Add(new M155InputIsNeededModel()
if (parameters[0].ToUpper().Trim() == "SHOWVAL")
{
Process = (uint)processId,
IsNeeded = bits[processId - 1],
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(2)?.ToDictionary(x => i++, x => x);
// Read value from custom macro
double macroVal = 0;
ReadMacroValue((int)processId, 955, true, ref macroVal);
value.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bits[processId - 1],
Message = parameters[1] ?? "",
Type = M155_TYPE.SHOW_VAL, // if there aren't buttons is a simple request
Value = macroVal,
Buttons = buttons
});
}
else
{
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x);
value.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bits[processId - 1],
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
}
}
}
@@ -883,23 +907,47 @@ namespace CMS_CORE_Library.Fanuc
public override CmsError PLC_WOperatorInputResponse(int processId, double responseVal)
{
CmsError cmsError = WriteMacroValue(processId, responseVal);
CmsError cmsError = WriteMacroValue(processId, 955, responseVal);
if (cmsError.IsError())
return cmsError;
return PLC_WStrobe(M155_INPUT_ACK, M155_INPUT_STROBE, (uint)processId);
}
private CmsError WriteMacroValue(int processId, double val)
private CmsError WriteMacroValue(int processId, int memIndex, double val)
{
int num = 1;
short nReturn = Focas1.cnc_wrmacror2(nLibHandle[processId - 1], 955, ref num, val);
short nReturn = Focas1.cnc_wrmacror2(nLibHandle[processId - 1], memIndex, ref num, val);
if (nReturn != 0)
return GetNcError(nReturn);
return NO_ERROR;
}
private CmsError ReadMacroValue(int processId, int memIndex, bool isCustom, ref double val)
{
if (isCustom)
{
// Read custom machine variable
int num = 1;
short nReturn = Focas1.cnc_rdmacror2(nLibHandle[processId - 1], memIndex, ref num, val);
if (nReturn != 0)
return GetNcError(nReturn);
}
else
{
// Read custom machine variable
ODBPM readVal = new ODBPM();
short nReturn = Focas1.cnc_rdpmacro(nLibHandle[processId - 1], memIndex, readVal);
if (nReturn != 0)
return GetNcError(nReturn);
val = readVal.mcr_val * Math.Pow(10 , (-1 * readVal.dec_val));
}
return NO_ERROR;
}
public override CmsError PLC_RM154Data(ref List<M154DataModel> data, ref bool MTCOnOff)
{
MTCOnOff = false;
@@ -1270,8 +1318,6 @@ namespace CMS_CORE_Library.Fanuc
//Execute the method
nReturn = Focas1.cnc_statinfo(nLibHandle[path], statusInfo);
//Throw Exception if there's an error
if (nReturn != 0)
return GetNcError(nReturn);
@@ -1366,6 +1412,39 @@ namespace CMS_CORE_Library.Fanuc
public override CmsError PROC_RSelectedProcessData(int processId, ref SelectedProcessData processData)
{
short number = 1;
ODBGCD odb = new ODBGCD();
// Read active origin
short nReturn = Focas1.cnc_rdgcode(nLibHandle[processId - 1], 13, 1, ref number, odb);
if (nReturn != 0)
return GetNcError(nReturn);
short origin = 0;
short offsetId = 0;
if(odb.gcd0.code != "")
// Convert fanuc string "G(N)" into a int
origin = Convert.ToInt16(odb.gcd0.code.TrimStart('G'));
// Read if there is an active offset
nReturn = Focas1.cnc_rdgcode(nLibHandle[processId - 1], 7, 1, ref number, odb);
if (nReturn != 0)
return GetNcError(nReturn);
// If G != G49 there is a active offset
if(!odb.gcd0.code.Contains("49"))
{
double macroVal = 0;
// Read offset id
ReadMacroValue(processId, 4111, false, ref macroVal);
offsetId = (short)macroVal;
}
processData = new SelectedProcessData()
{
ActiveOffsetId = offsetId,
Origin = origin
};
return NO_ERROR;
}
@@ -1878,6 +1957,11 @@ namespace CMS_CORE_Library.Fanuc
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value)
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
//--------------------------------------------------------------------------------------------------------------------------
// Siemens Version of Memory-Access Methods
+3 -1
View File
@@ -139,7 +139,8 @@ namespace CMS_CORE_Library.Models
public enum M155_TYPE
{
REAL = 0,
MULTIPLE_BUTTONS = 1
MULTIPLE_BUTTONS = 1,
SHOW_VAL = 2
}
public enum SCADA_MEM_TYPE
@@ -295,6 +296,7 @@ namespace CMS_CORE_Library.Models
public bool IsNeeded;
public M155_TYPE Type;
public string Message;
public double Value;
public Dictionary<byte, string> Buttons;
}
+1 -1
View File
@@ -114,7 +114,7 @@ namespace CMS_CORE_Library.Models
public POSITION_TYPE PhysicalType;
public int Type;
public bool Disabled;
public bool UsedBySpindle;
public bool Occupied;
}
public class EdgeConfigModel
+2
View File
@@ -984,6 +984,8 @@ namespace CMS_CORE_Library
public abstract CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memIndex, ref double value);
public abstract CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value);
#endregion MEMORY Low-level function: single valiable in memory (to override)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+66 -35
View File
@@ -827,20 +827,46 @@ namespace CMS_CORE_Library.Osai
// Parse line & get parameters
parameters = ExtractM155ParametersFromNcCodeLine(actualLine);
byte i = 1;
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x);
value.Add(new M155InputIsNeededModel()
if (parameters[0].ToUpper().Trim() == "SHOWVAL")
{
Process = processId,
IsNeeded = bits[processId - 1],
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(2)?.ToDictionary(x => i++, x => x);
double responseVal = 0;
// Read machine variable
cmsError = MEM_RWDouble(R, 0, MEMORY_TYPE.Osai_GD, 900 + (int)processId - 1, ref responseVal);
if (cmsError.IsError())
return cmsError;
value.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bits[processId - 1],
Message = parameters[1] ?? "",
Type = M155_TYPE.SHOW_VAL,
Value = val,
Buttons = buttons
});
}
else
{
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(2)?.ToDictionary(x => i++, x => x);
value.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bits[processId - 1],
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
}
}
}
@@ -1947,6 +1973,30 @@ namespace CMS_CORE_Library.Osai
return NO_ERROR;
}
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memIndex, ref double value)
{
ushort nReturn;
doublearray val = new doublearray() { value };
if (bWrite)
{
nReturn = OpenNC.WriteVarDouble((ushort)memType, (ushort)process, (ushort)memIndex, 1, val, out uint errorClass, out uint errorNum);
// If there is an error
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
return GetNCError(errorClass, errorNum);
}
else
{
nReturn = OpenNC.ReadVarDouble((ushort)memType, (ushort)process, (ushort)memIndex, 1, out val, out uint errorClass, out uint errorNum);
// If there is an error
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
return GetNCError(errorClass, errorNum);
value = val.FirstOrDefault();
}
return NO_ERROR;
}
//Write a Word-Value inside the NC. In writing-mode the field "Number" is not required
public override CmsError MEM_RWDWord(bool bWrite, int Process, MEMORY_TYPE MemType, int MemIndex, ref uint Value)
{
@@ -2007,28 +2057,9 @@ namespace CMS_CORE_Library.Osai
return MEM_RWInteger(bWrite, Process, MemType, MemIndex, MemIndex, ref Value);
}
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memIndex, ref double value)
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value)
{
ushort nReturn;
doublearray val = new doublearray() { value };
if (bWrite)
{
nReturn = OpenNC.WriteVarDouble((ushort)memType, (ushort)process, (ushort)memIndex, 1, val, out uint errorClass, out uint errorNum);
// If there is an error
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
return GetNCError(errorClass, errorNum);
}
else
{
nReturn = OpenNC.ReadVarDouble((ushort)memType, (ushort)process, (ushort)memIndex, 1, out val, out uint errorClass, out uint errorNum);
// If there is an error
if (errorClass != 0 || errorNum != 0 || nReturn == 0)
return GetNCError(errorClass, errorNum);
value = val.FirstOrDefault();
}
return NO_ERROR;
return FUNCTION_NOT_ALLOWED_ERROR;
}
#endregion NC Low-level function: variables List in memory
@@ -4173,8 +4204,8 @@ namespace CMS_CORE_Library.Osai
internal static MEMORY_CELL M155_INPUT_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4310, 1);
internal static MEMORY_CELL M154_SWITCH_ONOFF = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4000, 1, 2);
internal static MEMORY_CELL M154_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4312, 1);
internal static MEMORY_CELL M154_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4314, 1);
internal static MEMORY_CELL M154_STROBE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4312, 1);
internal static MEMORY_CELL M154_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4314, 1);
internal static MEMORY_CELL AXES_BUTTON_VISIBLE = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 4320, 16);
+209 -94
View File
@@ -3,14 +3,12 @@ using Siemens.Sinumerik.Operate.Services;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Linq;
using static CMS_CORE_Library.Models.DataStructures;
using static CMS_CORE_Library.Nc;
@@ -25,6 +23,7 @@ namespace CMS_CORE_Library.Siemens
{
// Global Constants
private const string OptionHMINotRunning = "P66";
private const string HMIDllName = "Wrapper.dll";
private const string NcNotFound = "Missing response";
@@ -77,6 +76,7 @@ namespace CMS_CORE_Library.Siemens
// Alarms Handler
private AlarmSvc SiemensAlmSvc = null;
private Alarm[] SiemensAlarms;
// Tool table listeners
@@ -129,10 +129,10 @@ namespace CMS_CORE_Library.Siemens
private static DataSvc SelectedProcessSvc;
private static ushort SelectedProcess = 0;
private static Dictionary<string, double> MachineAxesPosition = new Dictionary<string, double>();
private static Dictionary<string, double> ToGoAxesPosition = new Dictionary<string, double>();
private static Dictionary<string, double> InterpAxesPosition = new Dictionary<string, double>();
private static Dictionary<string, double> ProgrammedAxisPosition = new Dictionary<string, double>();
private static Hashtable MachineAxesPosition = new Hashtable();
private static Hashtable ToGoAxesPosition = new Hashtable();
private static Hashtable InterpAxesPosition = new Hashtable();
private static Hashtable ProgrammedAxisPosition = new Hashtable();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -215,36 +215,44 @@ namespace CMS_CORE_Library.Siemens
private void ManageSelectedProcess(Guid guid, Item[] item, DataSvcStatus[] status)
{
SelectedProcess = 0;
// Set selectedProcess
for (int i = 0; i < item.Count(); i++)
{
if (Convert.ToBoolean(item[i].Value))
SelectedProcess = (ushort)(i + 1);
if (status[i].Ok)
{
if (Convert.ToBoolean(item[i].Value))
SelectedProcess = (ushort)(i + 1);
}
}
List<AxisModel> axesConf = new List<AxisModel>();
// Clean listener
AxesSvc.UnSubscribe(ManageAxes);
AXES_RAxesNames(SelectedProcess, ref AxesData);
List<Item> axesData = new List<Item>();
foreach (var conf in AxesData)
if (SelectedProcess > 0)
{
// Setup the items to be subscribed
// Machine
axesData.Add(new Item() { Path = string.Format("/Nck/{0}[u{1},{2}]", "MachineAxis/actToolBasePos", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
// Programmed
axesData.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", "GeometricAxis/actProgPos", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
// Interp
axesData.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", "GeometricAxis/actToolEdgeCenterPos", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
// Dist to go
axesData.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", "MachineAxis/toolBaseDistToGo", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
}
List<AxisModel> axesConf = new List<AxisModel>();
if (axesData.Count() > 0)
// Subscribe to axis changes
AxesSvc.Subscribe(ManageAxes, axesData.ToArray());
AXES_RAxesNames(SelectedProcess, ref AxesData);
List<Item> axesData = new List<Item>();
foreach (var conf in AxesData)
{
// Setup the items to be subscribed
// Machine
axesData.Add(new Item() { Path = string.Format("/Nck/{0}[u{1},{2}]", "MachineAxis/actToolBasePos", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
// Programmed
axesData.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", "GeometricAxis/actProgPos", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
// Interp
axesData.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", "GeometricAxis/actToolEdgeCenterPos", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
// Dist to go
axesData.Add(new Item() { Path = string.Format("/Channel/{0}[u{1},{2}]", "MachineAxis/toolBaseDistToGo", SelectedProcess, conf.Id), SymbolicName = conf.Id.ToString() });
}
if (axesData.Count() > 0)
// Subscribe to axis changes
AxesSvc.Subscribe(ManageAxes, axesData.ToArray());
}
}
private void ManageAxes(Guid guid, Item[] item, DataSvcStatus[] status)
@@ -256,10 +264,14 @@ namespace CMS_CORE_Library.Siemens
for (int i = 0; i < AxesData.Count(); i++)
{
MachineAxesPosition.Add(item[i * 4].SymbolicName, Convert.ToDouble(item[i * 4].Value));
ProgrammedAxisPosition.Add(item[i * 4 + 1].SymbolicName, Convert.ToDouble(item[i * 4 + 1].Value));
InterpAxesPosition.Add(item[i * 4 + 2].SymbolicName, Convert.ToDouble(item[i * 4 + 2].Value));
ToGoAxesPosition.Add(item[i * 4 + 3].SymbolicName, Convert.ToDouble(item[i * 4 + 3].Value));
if(status[i * 4].Ok)
MachineAxesPosition.Add(item[i * 4].SymbolicName, Convert.ToDouble(item[i * 4].Value));
if(status[i * 4 + 1].Ok)
ProgrammedAxisPosition.Add(item[i * 4 + 1].SymbolicName, Convert.ToDouble(item[i * 4 + 1].Value));
if (status[i * 4 + 2].Ok)
InterpAxesPosition.Add(item[i * 4 + 2].SymbolicName, Convert.ToDouble(item[i * 4 + 2].Value));
if (status[i * 4 + 3].Ok)
ToGoAxesPosition.Add(item[i * 4 + 3].SymbolicName, Convert.ToDouble(item[i * 4 + 3].Value));
}
}
@@ -271,17 +283,17 @@ namespace CMS_CORE_Library.Siemens
if (SiemensToolSvc != null)
{
SiemensToolSvc.UnSubscribe(ToolMngmtSvcHandler);
SiemensToolSvc.Dispose();
// SiemensToolSvc.Dispose();
}
if (MagazinePositionSvc != null)
{
MagazinePositionSvc.UnSubscribe(MagazinePositionEnabled_OnChange);
MagazinePositionSvc.Dispose();
// MagazinePositionSvc.Dispose();
}
if (MagazineActionsSvc != null)
{
MagazineActionsSvc.UnSubscribe(MagazineAction_OnChange);
MagazineActionsSvc.Dispose();
// MagazineActionsSvc.Dispose();
}
return NO_ERROR;
@@ -999,7 +1011,7 @@ namespace CMS_CORE_Library.Siemens
OverrideEditable = (readValues[headOffset + 10] & 4) != 0, // bit 2
Tool = new ToolInSpindleModel()
{
ChildId = tool == null ? 0 : tool.ChildId,
ChildId = tool == null ? 0 : tool.ChildId,
ToolName = tool == null ? "" : tool.FamilyName,
}
});
@@ -1070,18 +1082,53 @@ namespace CMS_CORE_Library.Siemens
parameters = ExtractM155ParametersFromNcCodeLine(actualLine);
byte i = 1;
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x);
data.Add(new M155InputIsNeededModel()
if (parameters[0].ToUpper().Trim() == "SHOWVAL")
{
Process = processId,
IsNeeded = bit,
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
try
{
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(2)?.ToDictionary(x => i++, x => x);
// Read machine variable
DataSvc dataSvc = new DataSvc();
Item item = new Item()
{
Path = string.Format("/channel/parameter/r[c{0} , 155]", processId),
};
dataSvc.Read(item);
data.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bits[processId - 1],
Message = parameters[1] ?? "",
Type = M155_TYPE.SHOW_VAL, // if there aren't buttons is a simple request,
Value = Convert.ToDouble(item.Value),
Buttons = buttons
});
}
catch (Exception ex)
{
return ManageException(ex);
}
}
else
{
// Skip first parameter because it's the message string
// Set button with -> id = 1..5 -> value = parameter value
Dictionary<byte, string> buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x);
data.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bit,
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
}
}
// Next path
@@ -1104,7 +1151,7 @@ namespace CMS_CORE_Library.Siemens
dataSvc.Write(item);
return PLC_WStrobe(M155_INPUT_ACK, M155_INPUT_STROBE,(uint)process);
return PLC_WStrobe(M155_INPUT_ACK, M155_INPUT_STROBE, (uint)process);
}
catch (Exception ex)
{
@@ -1147,7 +1194,6 @@ namespace CMS_CORE_Library.Siemens
IsNeeded = bits[processId - 1],
Parameters = parameters
});
}
}
@@ -1163,45 +1209,44 @@ namespace CMS_CORE_Library.Siemens
{
string[] index = memIndex.Split('.');
CmsError cmsError = NO_ERROR;
if (index.Count() == 0)
if (index.Count() == 0 || index.Count() == 1)
return INCORRECT_PARAMETERS_ERROR;
else if (index.Count() == 1)
else if (index.Count() == 2)
{
if (memType == SCADA_MEM_TYPE.INT)
{
// read INT
int val = 0;
cmsError = MEM_RWInteger(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), ref val);
cmsError = MEM_RWInteger(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
value = val;
}
else if (memType == SCADA_MEM_TYPE.WORD)
{ // read WORD
ushort val = 0;
cmsError = MEM_RWWord(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), ref val);
cmsError = MEM_RWWord(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
value = val;
}
else if (memType == SCADA_MEM_TYPE.REAL)
{ // read DOUBLE
double val = 0;
cmsError = MEM_RWDouble(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), ref val);
cmsError = MEM_RWDouble(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
value = val;
}
else
{ // read BYTE
byte val = 0;
cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), 0, ref val);
cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), 0, ref val);
value = val;
}
}
else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL)
else if (index.Count() == 3 && memType == SCADA_MEM_TYPE.BOOL)
{ // read BOOL
bool val = false;
cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Siemens_DB, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), Convert.ToInt32(index[2]), ref val);
value = val;
}
@@ -1215,7 +1260,6 @@ namespace CMS_CORE_Library.Siemens
CmsError cmsError = NO_ERROR;
if (index.Count() == 0)
return INCORRECT_PARAMETERS_ERROR;
else if (index.Count() == 1)
{
if (memType == SCADA_MEM_TYPE.INT)
@@ -1331,7 +1375,7 @@ namespace CMS_CORE_Library.Siemens
return cmsError;
}
private CmsError PLC_ManageActiveAck(int strobeByte, int strobeSubByte, int strobeBit, int ackByte, int ackSubByte, int ackBit, MEMORY_TYPE memType)
{
int n = 1200; // 30 seconds
@@ -1339,7 +1383,7 @@ namespace CMS_CORE_Library.Siemens
bool writeValue = true;
bool ok = false;
// Set ack to 1
CmsError cmsError = MEM_RWBoolean(W, 0, memType, ackByte, ackSubByte , ackBit, ref writeValue);
CmsError cmsError = MEM_RWBoolean(W, 0, memType, ackByte, ackSubByte, ackBit, ref writeValue);
if (cmsError.IsError())
return cmsError;
@@ -1592,7 +1636,7 @@ namespace CMS_CORE_Library.Siemens
processData.IsSelected = bits[2];
processData.IsInAlarm = bits[3];
processData.CanLoadProgram = bits[4];
// Choose process status
if (bytes[1] == 1)
processData.Status = "HOLD";
@@ -1692,7 +1736,7 @@ namespace CMS_CORE_Library.Siemens
return NO_ERROR;
}
private CmsError PROC_ReadActiveLine(uint processId, ref string line)
{
try
@@ -1729,9 +1773,9 @@ namespace CMS_CORE_Library.Siemens
axes = new Dictionary<string, double>();
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in InterpAxesPosition.ToList())
foreach (DictionaryEntry axis in InterpAxesPosition)
{
axes.Add(axis.Key, axis.Value);
axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value));
}
// axes = InterpAxesPosition.ToDictionary(x => x.Key, x => x.Value); This throws exceptions
}
@@ -1751,9 +1795,9 @@ namespace CMS_CORE_Library.Siemens
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in MachineAxesPosition.ToList())
foreach (DictionaryEntry axis in MachineAxesPosition)
{
axes.Add(axis.Key, axis.Value);
axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value));
}
// axes = MachineAxesPosition.ToDictionary(x => x.Key, x => x.Value);
}
@@ -1773,9 +1817,9 @@ namespace CMS_CORE_Library.Siemens
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in ProgrammedAxisPosition.ToList())
foreach (DictionaryEntry axis in ProgrammedAxisPosition)
{
axes.Add(axis.Key, axis.Value);
axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value));
}
// axes = ProgrammedAxisPosition.ToDictionary(x => x.Key, x => x.Value);
}
@@ -1795,9 +1839,9 @@ namespace CMS_CORE_Library.Siemens
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in InterpAxesPosition.ToList())
foreach (DictionaryEntry axis in InterpAxesPosition)
{
axes.Add(axis.Key, axis.Value);
axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value));
}
// axes = MachineAxesPosition.ToDictionary(x => x.Key, x => x.Value);
}
@@ -1817,9 +1861,9 @@ namespace CMS_CORE_Library.Siemens
// Cycle between axes
// The dictionary is written asynchronously so i have to create a copy of the dictionary with .ToList() to avoid exceptions
foreach (var axis in ToGoAxesPosition.ToList())
foreach (DictionaryEntry axis in ToGoAxesPosition)
{
axes.Add(axis.Key, axis.Value);
axes.Add(axis.Key.ToString(), Convert.ToDouble(axis.Value));
}
// axes = ToGoAxesPosition.ToDictionary(x => x.Key, x => x.Value);
}
@@ -2087,6 +2131,48 @@ namespace CMS_CORE_Library.Siemens
return NO_ERROR;
}
public override CmsError MEM_RWDouble(bool bWrite, int process, MEMORY_TYPE memType, int memTable, int memIndex, ref double value)
{
// Check if the NC is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
// Try to get information
try
{
// Setup variables
DataSvc Data = new DataSvc
{
Timeout = TimeoutConn,
PriorityFlag = SlPriority.highPriority
};
cmsError = ConvertMemToPath(memType, memTable, memIndex, 0, 1, 'D', out string itemString);
if (cmsError.IsError())
return cmsError;
Item item = new Item(itemString);
// Read-Write Data
if (bWrite)
{
item.Value = value;
Data.Write(item);
}
else
{
Data.Read(item);
value = Convert.ToDouble(item.Value);
}
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
//Write a Int-Value inside the NC. In writing-mode the field "Number" is not required
public override CmsError MEM_RWInteger(bool bWrite, int Process, MEMORY_TYPE MemType, int MemTable, int MemIndex, ref int Value)
{
@@ -2466,7 +2552,7 @@ namespace CMS_CORE_Library.Siemens
foreach (Node element in nodeArray)
{
PreviewFileModel file = new PreviewFileModel();
if(path == "\\\\")
if (path == "\\\\")
{
if (rootFolders.Contains(element.Name))
{
@@ -3530,6 +3616,9 @@ namespace CMS_CORE_Library.Siemens
if (position == null || position.Disabled)
return INCORRECT_PARAMETERS_ERROR;
if (position.Occupied)
return MAGAZINE_POSITION_OCCUPIED_ERROR;
// Get tool data
var tool = GetToolOrMultitool(newMagazineTool.ToolId);
if (tool == null)
@@ -3554,8 +3643,8 @@ namespace CMS_CORE_Library.Siemens
// Check if near positions are disabled
var posizionDisabled = MagazinePositionsData.Where(x => x.MagazineId == magazineId && x.Disabled == true &&
( x.PositionId <= (tool as SiemensToolModel).PositionId + (tool as SiemensToolModel).RightSize/2.0
|| (tool as SiemensToolModel).PositionId + x.PositionId >= (tool as SiemensToolModel).LeftSize/2.0)).ToList();
(x.PositionId <= (tool as SiemensToolModel).PositionId + (tool as SiemensToolModel).RightSize / 2.0
|| (tool as SiemensToolModel).PositionId + x.PositionId >= (tool as SiemensToolModel).LeftSize / 2.0)).ToList();
if (posizionDisabled.Count() > 0)
return MAGAZINE_POSITION_OCCUPIED_ERROR;
@@ -4109,12 +4198,12 @@ namespace CMS_CORE_Library.Siemens
{
var a = ex.GetType();
//Catch the Siemens exceptions
if (ex is OperateMissingOptionException && ex.Message.Contains(OptionHMINotRunning))
if (ex is OperateMissingOptionException && ex.Message.Contains(OptionHMINotRunning) || ex.Message.Contains("CORBA"))
{
Connected = false;
return SIEMENS_HMI_NOT_RUNNING_ERROR;
}
else if(ex is FileNotFoundException && ex.Message.Contains(HMIDllName))
else if (ex is FileNotFoundException && ex.Message.Contains(HMIDllName))
{
return SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR;
}
@@ -4157,9 +4246,9 @@ namespace CMS_CORE_Library.Siemens
Item ItemMaxChannelNo = new Item(MAX_CHANNEL_NO_PATH);
Item ItemConfChannelNo = new Item(CONF_CHANNEL_NO_PATH);
Item ItemLanguage = new Item(LANGUAGE_PATH);
Item ItemSerialNumber = new Item(SERIAL_NO_PATH);
Item ItemSerialNumber = new Item(SERIAL_NO_PATH);
Item ItemUnitOfMeasure = new Item(UNIT_OF_MEASURE);
cmsError = ConvertMemToPath(MATR_MACCH_SIEMENS.MemType, MATR_MACCH_SIEMENS.Address, MATR_MACCH_SIEMENS.SubAddress, 0, 1, 'W', out string itemString);
cmsError = ConvertMemToPath(MATR_MACCH_SIEMENS.MemType, MATR_MACCH_SIEMENS.Address, MATR_MACCH_SIEMENS.SubAddress, 0, 1, 'W', out string itemString);
if (cmsError.IsError())
return cmsError;
@@ -4361,23 +4450,29 @@ namespace CMS_CORE_Library.Siemens
private void MagazinePositionEnabled_OnChange(Guid guid, Item[] items, DataSvcStatus[] status)
{
int i = 0;
// Parse each new item
foreach (Item item in items)
{
// Get Ids
string[] ids = item.SymbolicName.Split('_');
int magazineId = Convert.ToInt32(ids[0]);
int positionId = Convert.ToInt32(ids[1]);
foreach (PositionModel pos in MagazinePositionsData)
if (status[i].Ok)
{
// Find position
if (pos.PositionId == positionId && pos.MagazineId == magazineId)
// Get Ids
string[] ids = item.SymbolicName.Split('_');
int magazineId = Convert.ToInt32(ids[0]);
int positionId = Convert.ToInt32(ids[1]);
foreach (PositionModel pos in MagazinePositionsData)
{
// Set Value
pos.Disabled = GetBitValue(Convert.ToInt32(item.Value), 1);
// Find position
if (pos.PositionId == positionId && pos.MagazineId == magazineId)
{
// Set Value
pos.Disabled = GetBitValue(Convert.ToInt32(item.Value), 1);
}
}
}
i++;
}
}
@@ -4728,6 +4823,7 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_MOP6":
{
SiemensToolModel tool = ToolTableData[toolIndex];
@@ -4739,6 +4835,7 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_MOP15":
{
SiemensToolModel tool = ToolTableData[toolIndex];
@@ -4750,6 +4847,7 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_MOP5":
{
SiemensToolModel tool = ToolTableData[toolIndex];
@@ -4761,6 +4859,7 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_DP2":
case "$TC_DP3":
case "$TC_DP4":
@@ -4870,7 +4969,7 @@ namespace CMS_CORE_Library.Siemens
if (index >= 0)
{
MagazinePositionsData[index].Disabled = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 1);
MagazinePositionsData[index].UsedBySpindle = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 2);
MagazinePositionsData[index].Occupied = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 3);
}
}
break;
@@ -4985,6 +5084,7 @@ namespace CMS_CORE_Library.Siemens
case "$TC_TP9":
outputTool.LifeType = (SIEMENS_LIFE_TYPE)Convert.ToInt32(actualString.Split('=').LastOrDefault());
break;
case "$TC_TP_MAX_VELO":
outputTool.MaxSpeed = Convert.ToDouble(actualString.Split('=').LastOrDefault(), numberFormat);
break;
@@ -5097,6 +5197,7 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_MOP6":
{
if (outputTool.LifeType == SIEMENS_LIFE_TYPE.WEAR)
@@ -5117,6 +5218,7 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_MOP5":
{
if (outputTool.LifeType == SIEMENS_LIFE_TYPE.WEAR)
@@ -5180,10 +5282,11 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
case "$TC_DP25":
{
// Sets tool values with first edge value
if(outputTool.EdgesData[edgeIndex].Id == 1)
if (outputTool.EdgesData[edgeIndex].Id == 1)
{
// Get tool general information
var toolInfo = Convert.ToInt32(actualString.Split('=').LastOrDefault());
@@ -5202,7 +5305,6 @@ namespace CMS_CORE_Library.Siemens
}
}
break;
}
}
}
@@ -5380,7 +5482,7 @@ namespace CMS_CORE_Library.Siemens
string[] toolsStrings = ReadToolTableFile();
SiemensToolModel newTool = CreateToolFromId((int)toolInfo.tNo, toolsStrings);
if (newTool != null)
{
ToolTableData.Add(newTool);
@@ -5454,6 +5556,7 @@ namespace CMS_CORE_Library.Siemens
}
MountToolToMagazineList((int)toolInfo.tNo, magazineId, positionId);
// moved MULTITOOL handler, add when Siemens Library bugs have been fixed
//*SHANK FIX*catch (Exception ex)
//{
@@ -5490,7 +5593,7 @@ namespace CMS_CORE_Library.Siemens
MagazineMountedTools.RemoveAll(mountTool => PositionContainsTool(mountTool, toolId));
// If load magazine != 0, add new tool
if (magazineId != 0)
if (magazineId != 0 && positionId != 0)
{
// Find if position exist
MountedToolModel mounted = MagazineMountedTools
@@ -5502,12 +5605,25 @@ namespace CMS_CORE_Library.Siemens
// Find tool by id
var tool = GetToolOrMultitool(toolId);
if (tool != null)
{
if(magazineId == 9998)
{
// Set magazine position as occupied
}
else
{
// Free a position
}
// Add tool to list
MagazineMountedTools.Add(new MountedToolModel()
{
MagazineId = magazineId,
PositionId = positionId,
ToolId = toolId
});
}
}
}
@@ -5630,7 +5746,6 @@ namespace CMS_CORE_Library.Siemens
#endregion Siemens Tool private functions
#region Multitool Private region
private void MultitoolsNumber_OnChange(Guid guid, Item item, DataSvcStatus status)