Fix siemens and demo library

This commit is contained in:
Lucio Maranta
2018-05-24 15:41:42 +00:00
parent 8ee9d6915a
commit 7f6dcbbde3
13 changed files with 131 additions and 65 deletions
+6 -4
View File
@@ -209,6 +209,7 @@ namespace CMS_CORE_Application
error = true;
SetError(Lines, cmsError);
}
// cmsError = N.TOOLS_WAddShank(ref newShank);
// cmsError = N.TOOLS_WDeleteShank(4);
//cmsError = N.TOOLS_WUpdateEdge(1, ref newEdge);
@@ -223,7 +224,7 @@ namespace CMS_CORE_Application
// PositionId = 1
//});
// cmsError = N.TOOLS_WUnloadToolInMagazine(1, 1);
// cmsError = N.TOOLS_WLoadToolInMagazine(1, new NewToolInMagazineModel() { PositionId = 2, ToolId = 19 });
// cmsError = N.TOOLS_WLoadToolInMagazine(1, new NewToolInMagazineModel() { PositionId = 31, ToolId = 3 });
//cmsError = N.PLC_WRefreshAllMessages();
//cmsError = N.PLC_RHeadsData(headsTest, 1);
@@ -233,10 +234,11 @@ namespace CMS_CORE_Application
//cmsError = N.TOOLS_RShanksData(ref shanks);
//cmsError = N.TOOLS_RFamilyData(ref famiies);
//cmsError = N.TOOLS_RMagazinePositions(ref positions);
// cmsError = N.TOOLS_WAddTool(ref newTool);
cmsError = N.TOOLS_WAddTool(ref newTool);
//ShankModel shank = new ShankModel();
//cmsError = N.TOOLS_WAddShank(ref shank);
newShank.Name = newShank.Name + "1";
cmsError = N.TOOLS_WAddShank(ref newShank);
//FamilyModel family = new FamilyModel
//{
// Name = "Da demo"
@@ -420,7 +422,7 @@ namespace CMS_CORE_Application
{
this.Invoke((ThreadStart)delegate ()
{
Error.Text = cmsError.message;
Error.Text = cmsError.localizationKey;
TXTPPLines.Text = String.Join(Environment.NewLine, Lines);
Connect.Enabled = true;
+19 -17
View File
@@ -286,12 +286,12 @@ namespace CMS_CORE_Library
public class CmsError
{
public CMS_ERROR_CODES errorCode;
public string message;
public string localizationKey;
public CmsError(CMS_ERROR_CODES errorCode, string message)
{
this.errorCode = errorCode;
this.message = message;
this.localizationKey = message;
}
public bool IsError()
@@ -331,24 +331,26 @@ namespace CMS_CORE_Library
MAX_EDGES_PER_TOOL_REACHED = 13,
MAX_FAMILY_REACHED = 14,
MAX_MULTITOOL_REACHED = 15,
MAX_TOOLS_PER_MULTITOOL_REACHED = 16
MAX_TOOLS_PER_MULTITOOL_REACHED = 16,
MAG_POS_OCCUPIED = 17
}
internal static CmsError NO_ERROR = new CmsError(CMS_ERROR_CODES.OK, "");
internal static CmsError NOT_CONNECTED_ERROR = new CmsError(CMS_ERROR_CODES.NOT_CONNECTED, "CMS-Core-Error: Nc not Connected");
internal static CmsError PROC_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Function not allowed for this type of NC");
internal static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "CMS-Core-Error: Function not allowed for this type of NC");
internal static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BIT_NOT_IN_RANGE, "CMS-Core-Error: Bit - number must be between 0 and 7");
internal static CmsError BYTE_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BYTE_NOT_IN_RANGE, "CMS-Core-Error: Byte - number must be between 0 and 1");
internal static CmsError INCORRECT_PARAMETERS_ERROR = new CmsError(CMS_ERROR_CODES.INCORRECT_PARAMETERS, "CMS-Core-Error: Incorrect Parameters error");
internal static CmsError LANGUAGE_ERROR = new CmsError(CMS_ERROR_CODES.NC_LANGUAGE_ERROR, "CMS-Core-Error: Incorrect Language");
internal static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND, "CMS-Core-Error: Siemens Environment not found");
internal static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "CMS-Core-Error: Siemens HMI is not Running / Ready");
internal static CmsError MAX_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOL_REACHED, "Max tool number reached");
internal static CmsError MAX_EDGES_PER_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_EDGES_PER_TOOL_REACHED, "Max edges per tool number reached");
internal static CmsError MAX_FAMILY_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_FAMILY_REACHED, "Max family number reached");
internal static CmsError MAX_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_MULTITOOL_REACHED, "Max multitool number reached");
internal static CmsError MAX_TOOLS_PER_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOLS_PER_MULTITOOL_REACHED, "Max tool per multitool number reached");
internal static CmsError NOT_CONNECTED_ERROR = new CmsError(CMS_ERROR_CODES.NOT_CONNECTED, "error_not_connected");
internal static CmsError PROC_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_process_not_found");
internal static CmsError FUNCTION_NOT_ALLOWED_ERROR = new CmsError(CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED, "error_function_not_allowed");
internal static CmsError BIT_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BIT_NOT_IN_RANGE, "error_bit_not_in_range");
internal static CmsError BYTE_NOT_IN_RANGE_ERROR = new CmsError(CMS_ERROR_CODES.BYTE_NOT_IN_RANGE, "error_byte_not_in_range");
internal static CmsError INCORRECT_PARAMETERS_ERROR = new CmsError(CMS_ERROR_CODES.INCORRECT_PARAMETERS, "error_incorrect_parameters");
internal static CmsError INCORRECT_LANGUAGE_ERROR = new CmsError(CMS_ERROR_CODES.NC_LANGUAGE_ERROR, "error_invalid_language");
internal static CmsError SIEMENS_ENVIRONMENT_NOT_FOUND_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND, "error_siemens_enviroment_not_found_error");
internal static CmsError SIEMENS_HMI_NOT_RUNNING_ERROR = new CmsError(CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING, "error_siemens_hmi_not_running");
internal static CmsError MAX_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOL_REACHED, "error_max_tool_reached");
internal static CmsError MAX_EDGES_PER_TOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_EDGES_PER_TOOL_REACHED, "error_max_edges_per_tool_reached");
internal static CmsError MAX_FAMILY_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_FAMILY_REACHED, "error_max_family_reached");
internal static CmsError MAX_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_MULTITOOL_REACHED, "error_max_multitools_reached");
internal static CmsError MAX_TOOLS_PER_MULTITOOL_REACHED_ERROR = new CmsError(CMS_ERROR_CODES.MAX_TOOLS_PER_MULTITOOL_REACHED, "error_max_tools_per_multitool_reached");
internal static CmsError MAG_POS_OCCUPIED_ERROR = new CmsError(CMS_ERROR_CODES.MAG_POS_OCCUPIED, "error_mag_pos_occupied");
#endregion Cms Errors Codes
+3 -2
View File
@@ -184,8 +184,9 @@ 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 = "PUT", UriTemplate = "tool_table/shank/{shankId}/positionId/{positionId}/tool/{toolId}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void UpdateToolShank(string shankId, string positionId, string toolId);
[WebInvoke(Method = "DELETE", UriTemplate = "tool_table/tool/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void DeleteTool(string id);
+3 -3
View File
@@ -2375,7 +2375,7 @@ namespace CMS_CORE.Demo
try
{
serverService.UpdateToolShank(shankId.ToString(), toolId.ToString());
serverService.UpdateToolShank(shankId.ToString(), positionId.ToString(), toolId.ToString());
}
catch (Exception ex)
{
@@ -2385,7 +2385,7 @@ namespace CMS_CORE.Demo
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId)
{
// Check if the NC Demo is Connected
CmsError cmsError = CheckConnection();
@@ -2394,7 +2394,7 @@ namespace CMS_CORE.Demo
try
{
serverService.UpdateToolShank(0.ToString(), toolId.ToString());
serverService.UpdateToolShank(shankId.ToString(), positionId.ToString(), 0.ToString());
}
catch (Exception ex)
{
+2 -2
View File
@@ -1779,7 +1779,7 @@ namespace CMS_CORE.Fanuc
{
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId)
{
return NO_ERROR;
}
@@ -1934,7 +1934,7 @@ namespace CMS_CORE.Fanuc
cmsError = NC_RParam((short)PARAM_LING_FANUC.Address, ref FanucLanguage);
if (cmsError.IsError())
{
MessageBox.Show(cmsError.message);
MessageBox.Show(cmsError.localizationKey);
return cmsError;
}
+1 -1
View File
@@ -1370,7 +1370,7 @@ namespace CMS_CORE
public abstract CmsError TOOLS_WLoadToolIntoShank(int shankId, int positionId, int toolId);
public abstract CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId);
public abstract CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId);
public abstract CmsError TOOLS_GetMagazinesStatus(ref MagazineActionModel magazineAction);
+1 -1
View File
@@ -2149,7 +2149,7 @@ namespace CMS_CORE.Osai
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId)
{
return NO_ERROR;
}
+60 -30
View File
@@ -244,7 +244,7 @@ namespace CMS_CORE.Siemens
//Setup the path of NC alarms translations file
filePath = PlcMessagesFilePath + "cmsalarm_" + cultureInfo.ThreeLetterISOLanguageName.ToUpper() + ".ts";
if (!File.Exists(filePath))
return LANGUAGE_ERROR;
return INCORRECT_LANGUAGE_ERROR;
// Open file reader
XDocument xmlTranslationsFile;
@@ -1875,8 +1875,6 @@ namespace CMS_CORE.Siemens
return cmsError;
try
{
tool.Id = GetNextToolId();
//Create Tools
string[] piArgs = new string[6];
piArgs[0] = "/NC";
@@ -1888,6 +1886,10 @@ namespace CMS_CORE.Siemens
PiSvc pi = new PiSvc(piArgs);
pi.Start();
// Get new tool id
tool.Id = GetLastToolId();
// Update new tool
cmsError = TOOLS_WUpdateTool(ref tool);
if (cmsError.IsError())
@@ -2066,8 +2068,6 @@ namespace CMS_CORE.Siemens
if (MultitoolsData.Count >= MAX_MULTITOOLS_NUMBER)
return INCORRECT_PARAMETERS_ERROR;
// Find new tool id
shank.Id = GetNextToolId();
//Create Shank with NC Pi service
string[] piArgs = new string[8];
@@ -2084,6 +2084,8 @@ namespace CMS_CORE.Siemens
PiSvc pi = new PiSvc(piArgs);
pi.Start();
// Find new tool id
shank.Id = GetLastMultitoolId();
// Update data
CmsError cmsError = TOOLS_WUpdateShank(ref shank);
if (cmsError.IsError())
@@ -2349,6 +2351,11 @@ namespace CMS_CORE.Siemens
public override CmsError TOOLS_WLoadToolInMagazine(int magazineId, NewToolInMagazineModel newMagazineTool)
{
// Check if magazine position is occupied
PositionModel magPos = MagazineMountedTools.Where(x => x.MagazineId == magazineId && x.PositionId == newMagazineTool.PositionId).FirstOrDefault();
if (magPos != null)
return MAG_POS_OCCUPIED_ERROR;
try
{
//Load tool in magazine
@@ -2431,7 +2438,7 @@ namespace CMS_CORE.Siemens
return NO_ERROR;
}
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId, int toolId)
public override CmsError TOOLS_WUnloadToolFromShank(int shankId, int positionId)
{
try
{
@@ -3680,32 +3687,55 @@ namespace CMS_CORE.Siemens
}
}
private int GetNextToolId()
private int GetLastToolId()
{
// Get tool ids
List<int> toolIds = ToolTableData.Select(x => x.Id).ToList();
// Sort tools ids array
toolIds.Sort((x, y) => x.CompareTo(y));
if (toolIds.Count == 0)
return 1;
for (int i = 0; i < toolIds.Count - 1; i++)
Item item = new Item()
{
// If next id is different than previus + 1, there is an empty space in the array of numbers
if (toolIds[i] + 1 != toolIds[i + 1])
{
// Check if the empty space is a multitool
ShankModel shank = MultitoolsData.Where(x => x.Id == (toolIds[i] + 1)).FirstOrDefault();
if (shank == null)
{
// return new id
return toolIds[i] + 1;
}
}
}
// If there isn't an empty space return max id + 1
return toolIds[toolIds.Count - 1] + 1;
Path = "/Tool/Catalogue/TnumWZV"
};
DataSvc dataSvc = new DataSvc();
dataSvc.Read(item);
return Convert.ToInt32(item.Value);
//// Get tool ids
//List<int> toolIds = ToolTableData.Select(x => x.Id).ToList();
//// Sort tools ids array
//toolIds.Sort((x, y) => x.CompareTo(y));
//if (toolIds.Count == 0)
// return 1;
//for (int i = 0; i < toolIds.Count - 1; i++)
//{
// // If next id is different than previus + 1, there is an empty space in the array of numbers
// if (toolIds[i] + 1 != toolIds[i + 1])
// {
// // Check if the empty space is a multitool
// ShankModel shank = MultitoolsData.Where(x => x.Id == (toolIds[i] + 1)).FirstOrDefault();
// if (shank == null)
// {
// // return new id
// return toolIds[i] + 1;
// }
// }
//}
//// If there isn't an empty space return max id + 1
//return toolIds[toolIds.Count - 1] + 1;
}
private int GetLastMultitoolId()
{
Item item = new Item()
{
Path = "/Tool/MTCatalogue/MTnumWZV"
};
DataSvc dataSvc = new DataSvc();
dataSvc.Read(item);
return Convert.ToInt32(item.Value);
}
private void AddOrUpdateFamilyChild(string familyName)
@@ -187,8 +187,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 ToolsDataModel 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 = "PUT", UriTemplate = "tool_table/shank/{shankId}/positionId/{positionId}/tool/{toolId}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void UpdateToolShank(string shankId, string positionId, string toolId);
[WebInvoke(Method = "DELETE", UriTemplate = "tool_table/tool/{id}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
void DeleteTool(string id);
@@ -513,9 +513,27 @@ namespace Nc_Demo_Application.Server.Service
DatabaseController.getInstance().DeleteTool(Convert.ToInt32(id));
}
public void UpdateToolShank(string shankId, string toolId)
public void UpdateToolShank(string shankId, string positionId , string toolId)
{
DatabaseController.getInstance().UpdateToolShank(Convert.ToInt32(shankId), Convert.ToInt32(toolId));
if(Convert.ToInt32(toolId) != 0)
{
DatabaseController.getInstance().UpdateToolShank(Convert.ToInt32(shankId), Convert.ToInt32(toolId));
}
else
{
GetTools(out List<ToolsDataModel> tools);
tools = tools.Where(x => x.ShanksId == Convert.ToInt32(shankId)).ToList();
if(tools == null)
throw new WebFaultException(HttpStatusCode.NotFound);
if(tools.Count < Convert.ToInt32(positionId))
throw new WebFaultException(HttpStatusCode.BadRequest);
tools[Convert.ToInt32(positionId) - 1].ShanksId = 0;
DatabaseController.getInstance().UpdateToolData(tools[Convert.ToInt32(positionId) - 1]);
}
}
#endregion Tools
@@ -228,6 +228,7 @@ namespace Nc_Demo_Application
this.removeTool = new System.Windows.Forms.ToolStripButton();
this.addTool = new System.Windows.Forms.ToolStripButton();
this.stopServer = new System.Windows.Forms.Button();
this.versionLabel = new System.Windows.Forms.Label();
this.ncDataPage.SuspendLayout();
this.toolStrip5.SuspendLayout();
this.ncTabControl.SuspendLayout();
@@ -2046,11 +2047,22 @@ namespace Nc_Demo_Application
this.stopServer.UseVisualStyleBackColor = true;
this.stopServer.Click += new System.EventHandler(this.StopServer_Click);
//
// versionLabel
//
this.versionLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.versionLabel.AutoSize = true;
this.versionLabel.Location = new System.Drawing.Point(843, 696);
this.versionLabel.Name = "versionLabel";
this.versionLabel.Size = new System.Drawing.Size(57, 13);
this.versionLabel.TabIndex = 11;
this.versionLabel.Text = "Version:26";
//
// DemoApplicationForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1008, 730);
this.Controls.Add(this.versionLabel);
this.Controls.Add(this.serverStatusLabel);
this.Controls.Add(this.ncTabControl);
this.Controls.Add(this.stopServer);
@@ -2304,6 +2316,7 @@ namespace Nc_Demo_Application
private System.Windows.Forms.TextBox magActionOrigMag;
private System.Windows.Forms.Label label21;
private System.Windows.Forms.ComboBox magActionAction;
private System.Windows.Forms.Label versionLabel;
}
}
@@ -41,7 +41,7 @@ namespace Nc_Demo_Application
private void ShowServer(bool visible)
{
ncTabControl.Visible = stopServer.Visible = serverStatusLabel.Visible = visible;
ncTabControl.Visible = stopServer.Visible = serverStatusLabel.Visible = versionLabel.Visible = visible;
startupPanel.Visible = !visible;
}