This commit is contained in:
Lucio Maranta
2018-05-17 17:17:21 +00:00
parent beec03905d
commit 3f48a6a1de
7 changed files with 378 additions and 161 deletions
+2
View File
@@ -184,6 +184,8 @@ namespace Nc_Demo_Application.Server.Service
[WebInvoke(Method = "PUT", UriTemplate = "tool_table/tool", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void PutTool(ref SiemensToolModel tool);
[WebInvoke(Method = "PUT", UriTemplate = "tool_table/shank/{shankId}/tool/{toolId}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void UpdateToolShank(string shankId, string toolId);
[WebInvoke(Method = "DELETE", UriTemplate = "tool_table/tool/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void DeleteTool(string id);
+54 -11
View File
@@ -300,7 +300,7 @@ namespace CMS_CORE.Demo
#region PLC High-level data
public override CmsError PLC_RActiveMessages(ref List<PlcAlarmModel> alarms)
public override CmsError PLC_RActiveMessages(ref List<PlcAlarmModel> alarms)
{
alarms.Clear();
List<int> readValues = new List<int>();
@@ -1648,7 +1648,14 @@ namespace CMS_CORE.Demo
config.ShanksConfiguration = SiemensShanksConfig;
config.MagazinePosConfiguration = SiemensMagazinePosConfig;
config.EdgesConfiguration = SiemensEdgesConfiguration;
config.MaxTools = 100;
config.MaxEdgesPerTools = 3;
config.MaxToolsPerFamily = 100;
config.MaxMultitools = 4;
config.MaxToolsPerMultitools = 3;
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration = new Dictionary<int, List<string>>();
// Remove path and set only names
foreach (int key in DemoEdgesConfiguration.EdgesConfig.Keys)
@@ -1660,7 +1667,7 @@ namespace CMS_CORE.Demo
}
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration.Add(key, tmpNames);
}
config.Magazines = new List<MagazineModel>()
{
new MagazineModel{Id = 1, Type = MAGAZINE_TYPE.MAGAZINE},
@@ -1835,7 +1842,7 @@ namespace CMS_CORE.Demo
if (demoTool == null)
return INCORRECT_PARAMETERS_ERROR;
// Get the configuration of the tool type
var toolTypeConfig = DemoEdgesConfiguration.EdgesConfig[demoTool.ToolType];
@@ -2193,11 +2200,10 @@ namespace CMS_CORE.Demo
foreach (DemoMagPosDataModel demoPos in demoMagazinePositions)
{
if(demoPos.IsMultiTool == false)
if (demoPos.IsMultiTool == false)
{
if(demoPos.ChildTools != null)
if (demoPos.ChildTools != null)
{
// Create Tool Model
PositionWithToolModel pos = new PositionWithToolModel()
{
@@ -2246,10 +2252,10 @@ namespace CMS_CORE.Demo
}
}
}
return NO_ERROR;
}
catch(Exception ex)
}
catch (Exception ex)
{
return ManageException(ex);
}
@@ -2298,7 +2304,7 @@ namespace CMS_CORE.Demo
try
{
serverService.UpdateMagazine(magazine.ToString(), new List<NewToolInMagazineModel> { newMagazineTool });
return NO_ERROR;
}
catch (Exception ex)
@@ -2332,6 +2338,43 @@ namespace CMS_CORE.Demo
}
}
public override CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId)
{
// Check if the NC Demo is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
try
{
serverService.UpdateToolShank(shankId.ToString(), toolId.ToString());
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
{
// Check if the NC Demo is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
try
{
serverService.UpdateToolShank(0.ToString(), toolId.ToString());
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
#endregion ToolTable
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+8
View File
@@ -1775,6 +1775,14 @@ namespace CMS_CORE.Fanuc
return NO_ERROR;
}
public override CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId)
{
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
{
return NO_ERROR;
}
#endregion Tools Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+4
View File
@@ -1342,6 +1342,10 @@ namespace CMS_CORE
public abstract CmsError TOOLS_WUnloadToolInMagazine(int magazineId, int positionId);
public abstract CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId);
public abstract CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId);
#endregion Tool Table
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+10
View File
@@ -2145,6 +2145,16 @@ namespace CMS_CORE.Osai
return NO_ERROR;
}
public override CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId)
{
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
{
return NO_ERROR;
}
#endregion Tools Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+284 -134
View File
@@ -11,6 +11,7 @@ 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.Nc;
using static CMS_CORE.Siemens.MEMORY_ADDRESS;
@@ -72,9 +73,11 @@ namespace CMS_CORE.Siemens
// Alarms Handler
private AlarmSvc SiemensAlmSvc;
// Tool table
// Tool table listeners
private static ToolMngmntSvc SiemensToolSvc = null;
private static DataSvc MagazinePositionSvc = null;
private static DataSvc MagazineActionsSvc = null;
private Guid ToolMngmtListGuid = Guid.Empty;
// Magazine config parameters
@@ -89,16 +92,16 @@ namespace CMS_CORE.Siemens
private static string PlcMessagesFilePath = "C:\\Program Files (x86)\\Siemens\\MotionControl\\oem\\sinumerik\\hmi\\lng\\";
private const string AXES_FILE_PATH = "C:\\CMS\\axes.xml";
private SiemensEdgesConfiguration AdditionalEdgesParamConfig = new SiemensEdgesConfiguration();
private SiemensEdgesConfiguration Add_Edges_Param_Config = new SiemensEdgesConfiguration();
// Tool table static data
private static List<SiemensToolModel> ToolTableData = new List<SiemensToolModel>();
private static List<PositionModel> MagazinePositions = new List<PositionModel>();
private static List<ShankModel> Multitools = new List<ShankModel>();
private static List<PositionModel> MagazineAndTools = new List<PositionModel>();
public static List<FamilyModel> Families = new List<FamilyModel>();
//private static List<MountedMultiToolModel> MountedMultiTools = new List<MountedMultiToolModel>();
//public static List<MountedToolModel> MountedTools = new List<MountedToolModel>();
private static List<PositionModel> MagazinePositionsData = new List<PositionModel>();
private static List<ShankModel> MultitoolsData = new List<ShankModel>();
private static List<PositionModel> MagazineMountedTools = new List<PositionModel>();
public static List<FamilyModel> FamiliesData = new List<FamilyModel>();
public static bool MagazineActionInProgess;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#region Contructor & global methods
@@ -148,8 +151,11 @@ namespace CMS_CORE.Siemens
if (SiemensToolSvc == null)
{
SiemensToolSvc = new ToolMngmntSvc(1);
MagazinePositionSvc = new DataSvc();
MagazineActionsSvc = new DataSvc();
ToolMngmtListGuid = SiemensToolSvc.Subscribe(TOOLS_UpdateToolsData);
PopulateToolTable();
SetupToolTableData();
}
}
catch (Exception ex)
@@ -170,6 +176,61 @@ namespace CMS_CORE.Siemens
return NO_ERROR;
}
private void SetupToolTableData()
{
DataSvc dataSvc = new DataSvc();
// Read max tool number
Item itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MM_NUM_TOOL");
dataSvc.Read(itemToRead);
MAX_TOOL_NUMER = (int)itemToRead.Value;
// Read max edge per tool number
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MM_MAX_CUTTING_EDGE_PERTOOL");
dataSvc.Read(itemToRead);
MAX_EDGES_PER_TOOL = (int)itemToRead.Value;
// Read max tools per family
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MAXNUM_REPLACEMENT_TOOLS");
dataSvc.Read(itemToRead);
MAX_TOOLS_PER_FAMILY = (int)itemToRead.Value;
// Read max multitools number
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MM_NUM_MULTITOOL");
dataSvc.Read(itemToRead);
MAX_MULTITOOLS_NUMBER = (int)itemToRead.Value;
// Read max tools per multitools
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MAX_TOOLS_PER_MULTITOOL");
dataSvc.Read(itemToRead);
MAX_TOOLS_PER_MULTITOOLS = (int)itemToRead.Value;
// Read file
string[] toolsStrings = ReadToolTableFile();
// Parse file
PopulateToolsTableFromFileStrings(toolsStrings);
// Setup magazine positions update listener
List<Item> magPosItems = new List<Item>();
foreach (var position in MagazinePositionsData)
{
int paramId = ((position.PositionId - 1) * 11) + 5;
magPosItems.Add(new Item()
{
Path = string.Format("/Tool/Magazine/placeData[c{0} , {1}]", position.MagazineId, paramId),
SymbolicName = position.MagazineId + "_" + position.PositionId
});
}
// Subscribe
MagazinePositionSvc.Subscribe(MagazinePosition_OnChange, magPosItems.ToArray());
// Setup magazine actions listener
Item magActionsItem = new Item()
{
Path = "DB71.DBB0"
};
MagazineActionsSvc.Subscribe(MagazineAction_OnChange, magActionsItem);
}
public override CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary<int, string> messages)
{
string filePath;
@@ -377,17 +438,6 @@ namespace CMS_CORE.Siemens
#region PLC High-level data
////Get the PLC Active Messages
//public override CmsError PLC_RActiveMessages(ref List<PlcAlarmModel> alarms)
//{
// alarms = SiemensAlarms
// .Where(x => x.Id >= IDMinPLCMessage && x.Id <= IDMaxPLCMessage)
// .Select(x => new PlcAlarmModel() { Id = (uint)x.Id, IsWarning = false, Process = new List<int>() { 1 } }) // TODO
// .ToList();
// return NO_ERROR;
//}
public override CmsError PLC_RActiveMessages(ref List<PlcAlarmModel> alarms)
{
try
@@ -1782,10 +1832,10 @@ namespace CMS_CORE.Siemens
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration = new Dictionary<int, List<string>>();
// Remove path and set only names as additionalParams
foreach (int key in AdditionalEdgesParamConfig.EdgesConfig.Keys)
foreach (int key in Add_Edges_Param_Config.EdgesConfig.Keys)
{
List<string> tmpNames = new List<string>();
foreach (var conf in AdditionalEdgesParamConfig.EdgesConfig[key])
foreach (var conf in Add_Edges_Param_Config.EdgesConfig[key])
{
tmpNames.Add(conf.Name);
}
@@ -1793,7 +1843,7 @@ namespace CMS_CORE.Siemens
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration.Add(key, tmpNames);
}
config.Magazines = new List<MagazineModel>();
foreach(PositionModel pos in MagazinePositions)
foreach(PositionModel pos in MagazinePositionsData)
{
var tmp = config.Magazines.Where(x => x.Id == pos.MagazineId).FirstOrDefault();
if (tmp == null)
@@ -1827,43 +1877,38 @@ namespace CMS_CORE.Siemens
return File.ReadAllLines(LOCALE_TOOL_FILE_PATH);
}
private void PopulateToolTable()
private void MagazinePosition_OnChange(Guid guid, Item[] items, DataSvcStatus[] status)
{
DataSvc dataSvc = new DataSvc();
// Read max tool number
Item itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MM_NUM_TOOL");
dataSvc.Read(itemToRead);
MAX_TOOL_NUMER = (int)itemToRead.Value;
// 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]);
// Read max edge per tool number
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MM_MAX_CUTTING_EDGE_PERTOOL");
dataSvc.Read(itemToRead);
MAX_EDGES_PER_TOOL = (int)itemToRead.Value;
foreach ( PositionModel pos in MagazinePositionsData)
{
// Find position
if(pos.PositionId == positionId && pos.MagazineId == magazineId)
{
// Set Value
pos.Disabled = GetBitValue(Convert.ToInt32(item.Value), 1);
}
}
}
}
// Read max tools per family
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MAXNUM_REPLACEMENT_TOOLS");
dataSvc.Read(itemToRead);
MAX_TOOLS_PER_FAMILY = (int)itemToRead.Value;
// Read max multitools number
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MM_NUM_MULTITOOL");
dataSvc.Read(itemToRead);
MAX_MULTITOOLS_NUMBER = (int)itemToRead.Value;
// Read max tools per multitools
itemToRead = new Item("/NC/_N_NC_TEA_ACX/$MN_MAX_TOOLS_PER_MULTITOOL");
dataSvc.Read(itemToRead);
MAX_TOOLS_PER_MULTITOOLS = (int)itemToRead.Value;
// Read file
string[] toolsStrings = ReadToolTableFile();
// Parse file
PopulateToolsTableFromFileStrings(toolsStrings);
private void MagazineAction_OnChange(Guid guid, Item item, DataSvcStatus status)
{
MessageBox.Show(item.Value.ToString());
}
private void TOOLS_UpdateToolsData(Guid guid, ToolInfo[] toolInfos)
{
try
{
// For each new action
for (int i = 0; i < toolInfos.Count(); i++)
{
TOOLS_ChooseActions(toolInfos[i]);
@@ -1875,7 +1920,7 @@ namespace CMS_CORE.Siemens
}
}
private CmsError TOOLS_ChooseActions(ToolInfo toolInfo)
private void TOOLS_ChooseActions(ToolInfo toolInfo)
{
string[] toolsStrings = ReadToolTableFile();
@@ -1893,9 +1938,9 @@ namespace CMS_CORE.Siemens
else
{
// if tool not exist, find into shanks
ShankModel shank = Multitools.SingleOrDefault(t => t.Id == toolInfo.tNo);
ShankModel shank = MultitoolsData.SingleOrDefault(t => t.Id == toolInfo.tNo);
if (shank != null)
Multitools.Remove(shank);
MultitoolsData.Remove(shank);
}
}
break;
@@ -1931,7 +1976,7 @@ namespace CMS_CORE.Siemens
else
{
// Find if its a multitool
int multitoolIndex = Multitools.FindIndex(t => t.Id == toolInfo.tNo);
int multitoolIndex = MultitoolsData.FindIndex(t => t.Id == toolInfo.tNo);
if(multitoolIndex != -1)
{
@@ -1939,7 +1984,7 @@ namespace CMS_CORE.Siemens
ShankModel newShank = CreateMultitoolFromId((int)toolInfo.tNo, toolsStrings);
// Replace element
if (newShank != null)
Multitools[multitoolIndex] = newShank;
MultitoolsData[multitoolIndex] = newShank;
}
}
}
@@ -1947,7 +1992,23 @@ namespace CMS_CORE.Siemens
case ToolAction.TOOL_MOVED:
{
// Read magazine id from memory
DataSvc dataSvc = new DataSvc();
Item item = new Item() { Path = string.Format("/Tool/Data/toolInMag[{0}]", toolInfo.tNo) };
dataSvc.Read(item);
int magazineId = Convert.ToInt32(item.Value);
item = new Item() { Path = string.Format("/Tool/Data/toolInPlace[{0}]", toolInfo.tNo) };
dataSvc.Read(item);
int positionId = Convert.ToInt32(item.Value);
// Remove tool from list
MagazineMountedTools.RemoveAll(mountTool => PositionContainsTool(mountTool, (int)toolInfo.tNo));
// If load magazine != 0 and add new tool
if (magazineId != 0)
{
MountToolToList((int)toolInfo.tNo, magazineId, positionId);
}
} break;
}
}
@@ -1955,10 +2016,9 @@ namespace CMS_CORE.Siemens
{
Console.WriteLine(ex.Message);
}
return NO_ERROR;
}
// ------------- TODO IMPROVE
private SiemensToolModel CreateToolFromId(int toolId, string[] toolsStrings)
{
SiemensEdgesConfiguration toolEdgesConfig = new SiemensEdgesConfiguration();
@@ -2041,7 +2101,7 @@ namespace CMS_CORE.Siemens
return toolValues;
}
// ------------- TODO IMPROVE
private ShankModel CreateMultitoolFromId(int multitoolId, string[] toolsStrings)
{
SiemensEdgesConfiguration toolEdgesConfig = new SiemensEdgesConfiguration();
@@ -2054,7 +2114,7 @@ namespace CMS_CORE.Siemens
byte toolStatus = Convert.ToByte(toolStatusByte.Split('=').LastOrDefault());
// Find shank, in order to get childs
ShankModel oldShank = Multitools.Where(x => x.Id == multitoolId).FirstOrDefault();
ShankModel oldShank = MultitoolsData.Where(x => x.Id == multitoolId).FirstOrDefault();
// Create shank model
ShankModel shank = new ShankModel()
@@ -2098,7 +2158,7 @@ namespace CMS_CORE.Siemens
if (lastFirstId != firstId)
{
toolIndex = ToolTableData.FindIndex(x => x.Id == firstId);
multitoolIndex = Multitools.FindIndex(x => x.Id == firstId);
multitoolIndex = MultitoolsData.FindIndex(x => x.Id == firstId);
}
if (secondId == 0)
@@ -2122,9 +2182,9 @@ namespace CMS_CORE.Siemens
string familyName = actualString.Split('=').LastOrDefault().Replace("\"", "");
ToolTableData[toolIndex].FamilyName = familyName;
// Add new family
Families.Add(new FamilyModel()
FamiliesData.Add(new FamilyModel()
{
Id = Families.Count + 1,
Id = FamiliesData.Count + 1,
Name = familyName
});
}
@@ -2192,36 +2252,36 @@ namespace CMS_CORE.Siemens
case "$TC_MTPN":
{
// Insert new multitool
Multitools.Add(new ShankModel() {
MultitoolsData.Add(new ShankModel() {
Id = firstId,
MaxChilds = Convert.ToInt32(actualString.Split('=').LastOrDefault())
});
// Update Index
multitoolIndex = Multitools.Count - 1;
multitoolIndex = MultitoolsData.Count - 1;
}
break;
case "$TC_MTP2":
{
Multitools[multitoolIndex].Name = actualString.Split('=').LastOrDefault().Replace("\"", "");
MultitoolsData[multitoolIndex].Name = actualString.Split('=').LastOrDefault().Replace("\"", "");
}
break;
case "$TC_MTP3":
{
Multitools[multitoolIndex].LeftSize = Convert.ToInt32(actualString.Split('=').LastOrDefault());
MultitoolsData[multitoolIndex].LeftSize = Convert.ToInt32(actualString.Split('=').LastOrDefault());
}
break;
case "$TC_MTP4":
{
Multitools[multitoolIndex].RightSize = Convert.ToInt32(actualString.Split('=').LastOrDefault());
MultitoolsData[multitoolIndex].RightSize = Convert.ToInt32(actualString.Split('=').LastOrDefault());
}
break;
case "$TC_MTP7":
{
Multitools[multitoolIndex].MagazinePositionType = Convert.ToInt32(actualString.Split('=').LastOrDefault());
MultitoolsData[multitoolIndex].MagazinePositionType = Convert.ToInt32(actualString.Split('=').LastOrDefault());
}
break;
@@ -2230,11 +2290,11 @@ namespace CMS_CORE.Siemens
// Get tool status
byte toolStatus = Convert.ToByte(actualString.Split('=').LastOrDefault());
Multitools[multitoolIndex].IsEnabled = GetBitValue(toolStatus, 2);
Multitools[multitoolIndex].IsInhibited = GetBitValue(toolStatus, 3);
Multitools[multitoolIndex].InChangeTool = GetBitValue(toolStatus, 6);
Multitools[multitoolIndex].InFixedPlace = GetBitValue(toolStatus, 7);
Multitools[multitoolIndex].InUse = GetBitValue(toolStatus, 8);
MultitoolsData[multitoolIndex].IsEnabled = GetBitValue(toolStatus, 2);
MultitoolsData[multitoolIndex].IsInhibited = GetBitValue(toolStatus, 3);
MultitoolsData[multitoolIndex].InChangeTool = GetBitValue(toolStatus, 6);
MultitoolsData[multitoolIndex].InFixedPlace = GetBitValue(toolStatus, 7);
MultitoolsData[multitoolIndex].InUse = GetBitValue(toolStatus, 8);
}
break;
}
@@ -2244,7 +2304,7 @@ namespace CMS_CORE.Siemens
// If secondId is changed, change current edge id
if (lastSecondId != secondId && toolIndex >= 0)
edgeIndex = ToolTableData[toolIndex].EdgesData.FindIndex(x => x.Id == secondId);
switch (GetUntilOrEmpty(actualString))
{
case "$TC_DP1":
@@ -2377,7 +2437,7 @@ namespace CMS_CORE.Siemens
case "$TC_MPP1":
{
MagazinePositions.Add(new PositionModel()
MagazinePositionsData.Add(new PositionModel()
{
PositionId = secondId,
MagazineId = firstId,
@@ -2387,9 +2447,9 @@ namespace CMS_CORE.Siemens
break;
case "$TC_MPP4":
{
int index = MagazinePositions.FindIndex(x => x.PositionId == secondId && x.MagazineId == x.PositionId);
int index = MagazinePositionsData.FindIndex(x => x.PositionId == secondId && x.MagazineId == firstId);
if( index >= 0)
MagazinePositions[index].Disabled = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 1);
MagazinePositionsData[index].Disabled = GetBitValue(Convert.ToInt32(actualString.Split('=').LastOrDefault()), 1);
}
break;
case "$TC_MPP6":
@@ -2397,47 +2457,7 @@ namespace CMS_CORE.Siemens
int toolId = Convert.ToInt32(actualString.Split('=').LastOrDefault());
if (toolId != 0)
{
// Find tool by id
SiemensToolModel tool = ToolTableData.Where(x => x.Id == toolId).FirstOrDefault();
// Find position by id
PositionModel position = MagazinePositions.Where(x => x.MagazineId == firstId && x.PositionId == secondId).FirstOrDefault();
if (tool != null)
{
// Add new Magazine-Tool
MagazineAndTools.Add(new PositionWithToolModel()
{
PositionId = secondId,
MagazineId = firstId,
Type = position.Type,
ChildTool = new MountedToolModel()
{
Id = tool.Id,
FamilyName = tool.FamilyName,
ToolType = tool.ToolType
}
});
}
else
{
// Find shank by id
ShankModel shank = Multitools.Where(x => x.Id == toolId).FirstOrDefault();
if (shank != null)
{
// Add new Magazine-Multitool
MagazineAndTools.Add(new PositionWithMultiToolModel()
{
PositionId = secondId,
MagazineId = firstId,
Type = position.Type,
ChildShank = new MountedMultiToolModel()
{
Id = shank.Id,
Name = shank.Name,
ChildsTools = shank.ChildsTools
}
});
}
}
MountToolToList(toolId, firstId, secondId);
}
}
break;
@@ -2451,7 +2471,7 @@ namespace CMS_CORE.Siemens
// Find tool by id
SiemensToolModel tool = ToolTableData.Where(x => x.Id == toolId).First();
// Add new multitool child
Multitools[multitoolIndex].ChildsTools.Add(new ShankChildModel()
MultitoolsData[multitoolIndex].ChildsTools.Add(new ShankChildModel()
{
Id = toolId,
MultitoolId = secondId,
@@ -2549,13 +2569,13 @@ namespace CMS_CORE.Siemens
public override CmsError TOOLS_RShanksData(ref List<ShankModel> shanksData)
{
shanksData = Multitools;
shanksData = MultitoolsData;
return NO_ERROR;
}
public override CmsError TOOLS_RFamilyData(ref List<FamilyModel> families)
{
families = Families;
families = FamiliesData;
foreach (FamilyModel family in families)
{
// Get family childs tools
@@ -2578,7 +2598,7 @@ namespace CMS_CORE.Siemens
public override CmsError TOOLS_RMagazinePositions(ref List<PositionModel> positions)
{
positions = MagazinePositions;
positions = MagazinePositionsData;
return NO_ERROR;
}
@@ -2644,7 +2664,7 @@ namespace CMS_CORE.Siemens
if (shank.Name.Count() > 32)
shank.Name = shank.Name.Substring(0, 32);
if (Multitools.Count >= MAX_MULTITOOLS_NUMBER)
if (MultitoolsData.Count >= MAX_MULTITOOLS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
// Find new tool id
shank.Id = GetNextToolId();
@@ -2690,7 +2710,7 @@ namespace CMS_CORE.Siemens
if (toolIds[i] + 1 != toolIds[i + 1])
{
// Check if the empty space is a multitool
ShankModel shank = Multitools.Where(x => x.Id == (toolIds[i] + 1)).FirstOrDefault();
ShankModel shank = MultitoolsData.Where(x => x.Id == (toolIds[i] + 1)).FirstOrDefault();
if (shank == null)
{
// return new id
@@ -2712,13 +2732,16 @@ namespace CMS_CORE.Siemens
try
{
DataSvc dataSvc = new DataSvc();
int paramId = (position.PositionId * 11) + 5;
int paramId = ((position.PositionId - 1) * 11) + 5;
// TC_MTP2
Item item = new Item()
{
Path = string.Format("/Tool/Magazine/placeData[c{0} , {1}]", position.MagazineId, paramId),
Value = position.Disabled // TODO FIX
Path = string.Format("/Tool/Magazine/placeData[c{0} , {1}]", position.MagazineId, paramId)
};
dataSvc.Read(item);
item.Value = SetBitValue(Convert.ToInt32(item.Value), position.Disabled, 1);
dataSvc.Write(item);
}
catch (Exception ex)
{
@@ -2827,7 +2850,7 @@ namespace CMS_CORE.Siemens
public override CmsError TOOLS_WDeleteShank(int id)
{
// Find if exists
var multitool = Multitools.Where(x => x.Id == id).FirstOrDefault();
var multitool = MultitoolsData.Where(x => x.Id == id).FirstOrDefault();
if (multitool == null)
return INCORRECT_PARAMETERS_ERROR;
@@ -3009,7 +3032,7 @@ namespace CMS_CORE.Siemens
if (magazineId <= 0)
return INCORRECT_PARAMETERS_ERROR;
// Filter by magazine id
magazinePos = MagazineAndTools
magazinePos = MagazineMountedTools
.Where(x => x.MagazineId == magazineId)
.ToList();
@@ -3020,7 +3043,7 @@ namespace CMS_CORE.Siemens
{
List<int> mountedIds = new List<int>();
// Find ids of tools mounted in the magazines
foreach(var mounted in MagazineAndTools)
foreach(var mounted in MagazineMountedTools)
{
if(mounted is PositionWithMultiToolModel) // If multitool
{
@@ -3046,7 +3069,7 @@ namespace CMS_CORE.Siemens
.ToList();
// Filter multitools
multiTools = Multitools
multiTools = MultitoolsData
.Where(x => !mountedIds.Contains(x.Id))
.Select(x => new MountedMultiToolModel()
{
@@ -3115,6 +3138,51 @@ namespace CMS_CORE.Siemens
return NO_ERROR;
}
public override CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId)
{
try
{
DataSvc dataSvc = new DataSvc();
int paramId = ((positionId - 1) * 6) + 5;
// TC_MTP2
Item item = new Item()
{
Path = string.Format("/Tool/MTPlace/mtPlaceData[c{0},{1}]", shankId, paramId),
Value = toolId
};
dataSvc.Write(item);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
{
try
{
DataSvc dataSvc = new DataSvc();
int paramId = ((positionId - 1) * 6) + 5;
// TC_MTP2
Item item = new Item()
{
Path = string.Format("/Tool/MTPlace/mtPlaceData[c{0},{1}]", shankId, paramId),
Value = 0
};
dataSvc.Write(item);
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
#endregion Tool Management
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -3145,6 +3213,7 @@ namespace CMS_CORE.Siemens
return intVal & ~(1 << (bitIndex - 1));
}
//Manage the Mode
private PROC_MODE ConvertToSTEPMode(uint mode, uint JogMode, uint AdvMode)
{
@@ -3408,6 +3477,87 @@ namespace CMS_CORE.Siemens
return littleEndianValues;
}
private bool PositionContainsTool(PositionModel mounted, int toolId)
{
if (mounted is PositionWithMultiToolModel) // If multitool
{
var tmp = mounted as PositionWithMultiToolModel;
if(tmp.ChildShank.Id == toolId)
return true;
else
{
// Check if tool is a multitool child
int index = tmp.ChildShank.ChildsTools.FindIndex(x => x.Id == toolId);
if (index > 0)
return true;
}
}
else if (mounted is PositionWithToolModel) // If simple tool
{
var tmp = mounted as PositionWithToolModel;
// If ids are equal return true
if (tmp.ChildTool.Id == toolId)
return true;
}
return false;
}
private void MountToolToList(int toolId, int magazineId, int positionId)
{
// Find if position exist
PositionModel mounted = MagazineMountedTools
.Where(x => x.MagazineId == magazineId && x.PositionId == positionId)
.FirstOrDefault();
if (mounted != null)
return;
// Find tool by id
SiemensToolModel tool = ToolTableData.Where(x => x.Id == toolId).FirstOrDefault();
// Find position by id
PositionModel position = MagazinePositionsData.Where(x => x.MagazineId == magazineId && x.PositionId == positionId).FirstOrDefault();
if (tool != null)
{
// Add new Magazine-Tool
MagazineMountedTools.Add(new PositionWithToolModel()
{
MagazineId = magazineId,
PositionId = positionId,
Type = position.Type,
Disabled = position.Disabled,
ChildTool = new MountedToolModel()
{
Id = tool.Id,
FamilyName = tool.FamilyName,
ToolType = tool.ToolType
}
});
}
else
{
// Find shank by id
ShankModel shank = MultitoolsData.Where(x => x.Id == toolId).FirstOrDefault();
if (shank != null)
{
// Add new Magazine-Multitool
MagazineMountedTools.Add(new PositionWithMultiToolModel()
{
MagazineId = magazineId,
PositionId = positionId,
Type = position.Type,
Disabled = position.Disabled,
ChildShank = new MountedMultiToolModel()
{
Id = shank.Id,
Name = shank.Name,
ChildsTools = shank.ChildsTools
}
});
}
}
}
#endregion Subordinate Private Functions
}
+16 -16
View File
@@ -80,7 +80,7 @@ namespace CMS_CORE_Library
new FieldsConfiguration{Name = "inFixedPlace", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "isMeasured", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inChangeTool", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inUse", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inUse", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "preAlarm", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "cooling1", Type = "boolean", SelectValues = null, Category = "cooling", ReadOnly = false},
new FieldsConfiguration{Name = "cooling2", Type = "boolean", SelectValues = null, Category = "cooling" , ReadOnly = false},
@@ -109,23 +109,23 @@ namespace CMS_CORE_Library
{
ShankConfiguration = new List<FieldsConfiguration>()
{
new FieldsConfiguration{Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "name", Type = "string", SelectValues = null, Category = "general", ReadOnly = false },
new FieldsConfiguration{Name = "isEnabled", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "isInhibited", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inFixedPlace", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inChangeTool", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inUse", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "leftSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false},
new FieldsConfiguration{Name = "rightSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false},
new FieldsConfiguration{Name = "magazinePositionType", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false},
new FieldsConfiguration{Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "name", Type = "string", SelectValues = null, Category = "general", ReadOnly = false },
new FieldsConfiguration{Name = "isEnabled", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "isInhibited", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inFixedPlace", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inChangeTool", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "inUse", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false},
new FieldsConfiguration{Name = "leftSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false},
new FieldsConfiguration{Name = "rightSize", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false},
new FieldsConfiguration{Name = "magazinePositionType", Type = "int", SelectValues = null, Category = "magazine", ReadOnly = false},
},
ToolsConfiguration = new List<FieldsConfiguration>()
{
new FieldsConfiguration{Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "multitoolId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "familyName", Type = "string", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "toolType", Type = "select", SelectValues = toolTypeList, Category = "general", ReadOnly = true }
new FieldsConfiguration{Name = "id", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "multitoolId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "familyName", Type = "string", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "toolType", Type = "select", SelectValues = toolTypeList, Category = "general", ReadOnly = true }
}
};
@@ -134,7 +134,7 @@ namespace CMS_CORE_Library
new FieldsConfiguration{Name = "magazineId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "positionId", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "type", Type = "int", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "disabled", Type = "bool", SelectValues = null, Category = "general", ReadOnly = true },
new FieldsConfiguration{Name = "disabled", Type = "boolean", SelectValues = null, Category = "general", ReadOnly = true },
};
public static EdgesConfiguration SiemensEdgesConfiguration = new EdgesConfiguration()