Fix osai tool manager

This commit is contained in:
Lucio Maranta
2018-07-20 11:36:19 +00:00
parent 41dab23ecb
commit 13cbb12d0e
5 changed files with 136 additions and 132 deletions
+27 -17
View File
@@ -30,6 +30,7 @@
{
this.Connect = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.NetworkReadButton = new System.Windows.Forms.Button();
this.writeFileBtn = new System.Windows.Forms.Button();
this.readFileBtn = new System.Windows.Forms.Button();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
@@ -81,7 +82,7 @@
this.label7 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.Error = new System.Windows.Forms.TextBox();
this.NetworkReadButton = new System.Windows.Forms.Button();
this.pathTextBox = new System.Windows.Forms.TextBox();
this.panel1.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout();
@@ -116,6 +117,7 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.pathTextBox);
this.panel1.Controls.Add(this.NetworkReadButton);
this.panel1.Controls.Add(this.writeFileBtn);
this.panel1.Controls.Add(this.readFileBtn);
@@ -131,6 +133,16 @@
this.panel1.Size = new System.Drawing.Size(650, 128);
this.panel1.TabIndex = 1;
//
// NetworkReadButton
//
this.NetworkReadButton.Location = new System.Drawing.Point(188, 13);
this.NetworkReadButton.Name = "NetworkReadButton";
this.NetworkReadButton.Size = new System.Drawing.Size(75, 23);
this.NetworkReadButton.TabIndex = 9;
this.NetworkReadButton.Text = "Leggi rete";
this.NetworkReadButton.UseVisualStyleBackColor = true;
this.NetworkReadButton.Click += new System.EventHandler(this.NetworkReadButton_Click);
//
// writeFileBtn
//
this.writeFileBtn.Location = new System.Drawing.Point(102, 13);
@@ -382,7 +394,7 @@
this.tableLayoutPanel1.ColumnCount = 3;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.76253F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 49.23747F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 292F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 293F));
this.tableLayoutPanel1.Controls.Add(this.groupBox2, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.groupBox1, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.groupBox4, 2, 0);
@@ -403,7 +415,7 @@
this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.groupBox2.Location = new System.Drawing.Point(160, 3);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(147, 265);
this.groupBox2.Size = new System.Drawing.Size(146, 265);
this.groupBox2.TabIndex = 28;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Plc";
@@ -417,7 +429,7 @@
this.TXTMsg.Multiline = true;
this.TXTMsg.Name = "TXTMsg";
this.TXTMsg.ReadOnly = true;
this.TXTMsg.Size = new System.Drawing.Size(136, 238);
this.TXTMsg.Size = new System.Drawing.Size(135, 238);
this.TXTMsg.TabIndex = 18;
//
// groupBox1
@@ -452,9 +464,9 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBox4.Controls.Add(this.tabControl1);
this.groupBox4.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.groupBox4.Location = new System.Drawing.Point(313, 3);
this.groupBox4.Location = new System.Drawing.Point(312, 3);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(287, 265);
this.groupBox4.Size = new System.Drawing.Size(288, 265);
this.groupBox4.TabIndex = 29;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "Path";
@@ -468,7 +480,7 @@
this.tabControl1.Location = new System.Drawing.Point(6, 21);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(274, 238);
this.tabControl1.Size = new System.Drawing.Size(275, 238);
this.tabControl1.TabIndex = 0;
//
// tabPage1
@@ -477,7 +489,7 @@
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(266, 212);
this.tabPage1.Size = new System.Drawing.Size(267, 212);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Path 1";
this.tabPage1.UseVisualStyleBackColor = true;
@@ -491,7 +503,7 @@
this.TXTAlm.Multiline = true;
this.TXTAlm.Name = "TXTAlm";
this.TXTAlm.ReadOnly = true;
this.TXTAlm.Size = new System.Drawing.Size(254, 203);
this.TXTAlm.Size = new System.Drawing.Size(255, 203);
this.TXTAlm.TabIndex = 18;
//
// groupBox3
@@ -705,15 +717,12 @@
this.Error.Size = new System.Drawing.Size(462, 20);
this.Error.TabIndex = 27;
//
// NetworkReadButton
// pathTextBox
//
this.NetworkReadButton.Location = new System.Drawing.Point(286, 51);
this.NetworkReadButton.Name = "NetworkReadButton";
this.NetworkReadButton.Size = new System.Drawing.Size(75, 23);
this.NetworkReadButton.TabIndex = 9;
this.NetworkReadButton.Text = "Leggi rete";
this.NetworkReadButton.UseVisualStyleBackColor = true;
this.NetworkReadButton.Click += new System.EventHandler(this.NetworkReadButton_Click);
this.pathTextBox.Location = new System.Drawing.Point(19, 51);
this.pathTextBox.Name = "pathTextBox";
this.pathTextBox.Size = new System.Drawing.Size(244, 20);
this.pathTextBox.TabIndex = 10;
//
// Form1
//
@@ -811,6 +820,7 @@
private System.Windows.Forms.Button writeFileBtn;
private System.Windows.Forms.Button readFileBtn;
private System.Windows.Forms.Button NetworkReadButton;
private System.Windows.Forms.TextBox pathTextBox;
}
}
+12 -6
View File
@@ -208,10 +208,10 @@ namespace CMS_CORE_Application
error = true;
SetError(Lines, cmsError);
}
N.TOOLS_WStartEditData();
cmsError = N.TOOLS_WStartEditTooling(1);
cmsError = N.TOOLS_WRestoreBackup();
cmsError = N.FILES_CopyProgram("C:\\TO_INI.INI", @"test\\OEM\\CMS\\SYS\\STEP\\testLocal", true);
// N.TOOLS_WStartEditData();
// cmsError = N.TOOLS_WStartEditTooling(1);
// cmsError = N.TOOLS_WRestoreBackup();
// cmsError = N.FILES_CopyProgram("C:\\TO_INI.INI", @"test\\OEM\\CMS\\SYS\\STEP\\testLocal", true);
//cmsError = N.TOOLS_WStopEditTooling(1);
// cmsError = N.TOOLS_WAddShank(ref newShank);
// List<MountedToolModel> a = new List<MountedToolModel>() ;
@@ -473,7 +473,8 @@ namespace CMS_CORE_Application
{
TXTip.Enabled = true;
TXTport.Enabled = true;
TXTip.Text = "192.168.157.2";
TXTip.Text = "192.168.139.1";
// TXTip.Text = "192.168.157.2";
TXTport.Text = "8080";
}
else if (NcCombo.SelectedItem.ToString().Equals("Demo"))
@@ -534,11 +535,16 @@ namespace CMS_CORE_Application
{
using (FileStream fileStream = new FileStream("C:\\test.csv", FileMode.OpenOrCreate))
{
CmsError cms = N.FILES_RProgramToFile(@"test\\OEM\\CMS\\SYS\\STEP\\Tools.csv", fileStream);
CmsError cms = N.FILES_RProgramToFile(pathTextBox.Text, fileStream);
if (cms.IsError())
{
MessageBox.Show(cms.localizationKey);
}
else
{
string text = File.ReadAllText("C:\\test.csv");
MessageBox.Show(text);
}
}
}
+8 -6
View File
@@ -703,21 +703,23 @@ namespace CMS_CORE_Library
{
public ushort Id { get; set; }
public ushort OffsetLength { get; set; }
public ushort ResidualLife { get; set; }
public ushort ResidualRevive { get; set; }
public int FamilyId { get; set; }
public int ShankId { get; set; }
public byte Status { get; set; }
public ushort OffsetLength { get; set; }
public ushort ResidualLife { get; set; }
public int OffsetId1 { get; set; }
public int OffsetId2 { get; set; }
public int OffsetId3 { get; set; }
public ushort ResidualRevive { get; set; }
}
public class NcShankModel
+66 -94
View File
@@ -37,7 +37,7 @@ namespace CMS_CORE.Osai
private BasicHttpBinding HttpBinding;
private static Dictionary<int, string> PlcMessages;
private const string TOOL_MANAGER_DIRECTORY_PATH = @"test\\OEM\\CMS\\SYS\\STEP\\";
private const string TOOL_MANAGER_DIRECTORY_PATH = @"TEST\\SYS\\STEP\\";
private const string FAMILIES_FILE_NAME = @"Families";
private const string FAM_SIZE_FILE_NAME = @"Fam_Sizes";
private const string MAG_POSITION_FILE_NAME = @"Mag_Positions";
@@ -2136,6 +2136,7 @@ namespace CMS_CORE.Osai
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
ushort status = 0;
// Read tool manager status
cmsError = MEM_RWWord(R, 0, TOOL_MANAGER_STATUS.MemType, TOOL_MANAGER_STATUS.Address, ref status);
@@ -2156,21 +2157,14 @@ namespace CMS_CORE.Osai
if (cmsError.IsError())
return cmsError;
try
{
Stopwatch sw = new Stopwatch();
sw.Start();
Stopwatch sw = new Stopwatch();
sw.Start();
cmsError = CreateBackup();
if (cmsError.IsError())
return cmsError;
cmsError = CreateBackup();
if (cmsError.IsError())
return cmsError;
Console.WriteLine("Backup" + sw.ElapsedMilliseconds);
}
catch (Exception ex)
{
return ManageException(ex);
}
Console.WriteLine("Backup" + sw.ElapsedMilliseconds);
return NO_ERROR;
}
@@ -2182,24 +2176,17 @@ namespace CMS_CORE.Osai
if (cmsError.IsError())
return cmsError;
try
{
// Write busy tool manager status
bool write = true;
cmsError = MEM_RWBoolean(W, 0, TOOL_MANAGER_COMMAND.MemType, TOOL_MANAGER_COMMAND.Address, 0, ref write);
if (cmsError.IsError())
return cmsError;
// Set reload command to 1
bool write = true;
cmsError = MEM_RWBoolean(W, 0, TOOL_MANAGER_COMMAND.MemType, TOOL_MANAGER_COMMAND.Address, 0, ref write);
if (cmsError.IsError())
return cmsError;
cmsError = DeleteBackup();
if (cmsError.IsError())
return cmsError;
cmsError = DeleteBackup();
if (cmsError.IsError())
return cmsError;
return NO_ERROR;
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
public override CmsError TOOLS_WStartEditTooling(int magazineId)
@@ -2209,31 +2196,25 @@ namespace CMS_CORE.Osai
if (cmsError.IsError())
return cmsError;
bool status = false;
// Read tool manager status
bool status = false;
cmsError = MEM_RWBoolean(R, 0, MAGAZINES_ENABLED_COMMAND.MemType, MAGAZINES_ENABLED_COMMAND.Address, magazineId - 1, ref status);
if (cmsError.IsError())
return cmsError;
// If magazine is busy
if (!status)
return MAGAZINE_BUSY_ERROR;
// Write busy
// Write busy
bool write = true;
cmsError = MEM_RWBoolean(W, 0, MAGAZINES_TOOLING_COMMAND.MemType, MAGAZINES_TOOLING_COMMAND.Address, magazineId - 1, ref write);
if (cmsError.IsError())
return cmsError;
try
{
cmsError = CreateBackup();
if (cmsError.IsError())
return cmsError;
}
catch (Exception ex)
{
return ManageException(ex);
}
// Create backup files
cmsError = CreateBackup();
if (cmsError.IsError())
return cmsError;
return NO_ERROR;
}
@@ -2245,56 +2226,49 @@ namespace CMS_CORE.Osai
if (cmsError.IsError())
return cmsError;
// Write busy
// Write busy
bool write = false;
cmsError = MEM_RWBoolean(W, 0, MAGAZINES_TOOLING_COMMAND.MemType, MAGAZINES_TOOLING_COMMAND.Address, magazineId - 1, ref write);
if (cmsError.IsError())
return cmsError;
try
{
cmsError = DeleteBackup();
if(cmsError.IsError())
return cmsError;
}
catch (Exception ex)
{
return ManageException(ex);
}
// Delete backup files
cmsError = DeleteBackup();
if (cmsError.IsError())
return cmsError;
// Set reload command to 1
write = true;
cmsError = MEM_RWBoolean(W, 0, TOOL_MANAGER_COMMAND.MemType, TOOL_MANAGER_COMMAND.Address, 0, ref write);
if (cmsError.IsError())
return cmsError;
return NO_ERROR;
}
private CmsError CreateBackup()
{
try
{
string filePath = TOOL_MANAGER_DIRECTORY_PATH + "{0}.csv";
string backupFilePath = TOOL_MANAGER_DIRECTORY_PATH + "{0}_bak.csv";
string filePath = TOOL_MANAGER_DIRECTORY_PATH + "{0}.csv";
string backupFilePath = TOOL_MANAGER_DIRECTORY_PATH + "{0}_bak.csv";
// Create tool manager backup file
CmsError cmsError = FILES_CopyProgram(string.Format(filePath, FAMILIES_FILE_NAME), string.Format(backupFilePath, FAMILIES_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
// Create tool manager backup file
CmsError cmsError = FILES_CopyProgram(string.Format(filePath, FAMILIES_FILE_NAME), string.Format(backupFilePath, FAMILIES_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
cmsError = FILES_CopyProgram(string.Format(filePath, FAM_SIZE_FILE_NAME), string.Format(backupFilePath, FAM_SIZE_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
cmsError = FILES_CopyProgram(string.Format(filePath, FAM_SIZE_FILE_NAME), string.Format(backupFilePath, FAM_SIZE_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
cmsError = FILES_CopyProgram(string.Format(filePath, MAG_POSITION_FILE_NAME), string.Format(backupFilePath, MAG_POSITION_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
cmsError = FILES_CopyProgram(string.Format(filePath, MAG_POSITION_FILE_NAME), string.Format(backupFilePath, MAG_POSITION_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
cmsError = FILES_CopyProgram(string.Format(filePath, SHANKS_FILE_NAME), string.Format(backupFilePath, SHANKS_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
cmsError = FILES_CopyProgram(string.Format(filePath, SHANKS_FILE_NAME), string.Format(backupFilePath, SHANKS_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
return FILES_CopyProgram(string.Format(filePath, TOOLS_FILE_NAME), string.Format(backupFilePath, TOOLS_FILE_NAME), false);
}
catch (Exception ex)
{
return ManageException(ex);
}
return FILES_CopyProgram(string.Format(filePath, TOOLS_FILE_NAME), string.Format(backupFilePath, TOOLS_FILE_NAME), false);
}
private CmsError DeleteBackup()
@@ -2302,8 +2276,8 @@ namespace CMS_CORE.Osai
try
{
string backupFilePath = "{0}_bak.csv";
// Delete tool manager backup file
// Delete tool manager backup file
CmsError cmsError = FILES_DeleteProgram(TOOL_MANAGER_DIRECTORY_PATH, string.Format(backupFilePath, FAMILIES_FILE_NAME));
if (cmsError.IsError())
return cmsError;
@@ -2319,7 +2293,7 @@ namespace CMS_CORE.Osai
cmsError = FILES_DeleteProgram(TOOL_MANAGER_DIRECTORY_PATH, string.Format(backupFilePath, SHANKS_FILE_NAME));
if (cmsError.IsError())
return cmsError;
return FILES_DeleteProgram(TOOL_MANAGER_DIRECTORY_PATH, string.Format(backupFilePath, TOOLS_FILE_NAME));
}
catch (Exception ex)
@@ -2329,7 +2303,7 @@ namespace CMS_CORE.Osai
}
public override CmsError TOOLS_WRestoreBackup()
{
{
//Check if the NC is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
@@ -2339,8 +2313,8 @@ namespace CMS_CORE.Osai
string filePath = TOOL_MANAGER_DIRECTORY_PATH + "{0}.csv";
string backupFilePath = TOOL_MANAGER_DIRECTORY_PATH + "{0}_bak.csv";
// Create tool manager backup file
cmsError = FILES_CopyProgram( string.Format(backupFilePath, FAMILIES_FILE_NAME), string.Format(filePath, FAMILIES_FILE_NAME), false);
// Create tool manager backup file
cmsError = FILES_CopyProgram(string.Format(backupFilePath, FAMILIES_FILE_NAME), string.Format(filePath, FAMILIES_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
// FamilySize
@@ -2348,7 +2322,7 @@ namespace CMS_CORE.Osai
if (cmsError.IsError())
return cmsError;
// Mag positions
cmsError = FILES_CopyProgram( string.Format(backupFilePath, MAG_POSITION_FILE_NAME), string.Format(filePath, MAG_POSITION_FILE_NAME), false);
cmsError = FILES_CopyProgram(string.Format(backupFilePath, MAG_POSITION_FILE_NAME), string.Format(filePath, MAG_POSITION_FILE_NAME), false);
if (cmsError.IsError())
return cmsError;
// Shanks
@@ -2391,14 +2365,14 @@ namespace CMS_CORE.Osai
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateFamilies(List<NcFamilyModel> families)
{
//Check if the NC is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
string filePath = TOOL_MANAGER_DIRECTORY_PATH + FAMILIES_FILE_NAME + ".csv";
try
@@ -2416,7 +2390,6 @@ namespace CMS_CORE.Osai
cmsError = UpdateToolManagerFile(filePath, familiesSizeData);
if (cmsError.IsError())
return cmsError;
}
catch (Exception ex)
{
@@ -2449,14 +2422,14 @@ namespace CMS_CORE.Osai
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateMagazinePositions(List<NcMagazinePositionModel> positions)
public override CmsError TOOLS_WUpdateMagazinePositions(List<NcMagazinePositionModel> positions)
{
//Check if the NC is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
string filePath = TOOL_MANAGER_DIRECTORY_PATH + MAG_POSITION_FILE_NAME + ".csv";
try
@@ -2465,7 +2438,6 @@ namespace CMS_CORE.Osai
cmsError = UpdateToolManagerFile(filePath, positions);
if (cmsError.IsError())
return cmsError;
}
catch (Exception ex)
{
@@ -2484,7 +2456,7 @@ namespace CMS_CORE.Osai
try
{
Stopwatch sw = new Stopwatch();sw.Start();
Stopwatch sw = new Stopwatch(); sw.Start();
List<string> lines = new List<string>();
@@ -2495,7 +2467,7 @@ namespace CMS_CORE.Osai
// Write into local file
File.WriteAllLines("C:\\test.csv", lines);
// Update file
// Update file
using (FileStream fileStream = new FileStream("C:\\test.csv", FileMode.OpenOrCreate))
{
// Write NcFile
@@ -2535,7 +2507,7 @@ namespace CMS_CORE.Osai
}
return output;
}
public override CmsError TOOLS_ROffset(short offsetId, ref OffsetModel offset)
{
//Check if the NC is Connected
+23 -9
View File
@@ -1,5 +1,4 @@
using CMS_CORE.Utils;
using CMS_CORE_Library.Siemens;
using CMS_CORE_Library.Siemens;
using Siemens.Sinumerik.Operate.Services;
using System;
using System.Collections;
@@ -2888,11 +2887,12 @@ namespace CMS_CORE.Siemens
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError TOOLS_WStopEditData()
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError TOOLS_WUpdateTools(List<NcToolModel> list)
{
return FUNCTION_NOT_ALLOWED_ERROR;
@@ -2903,7 +2903,6 @@ namespace CMS_CORE.Siemens
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError TOOLS_WUpdateShanks(List<NcShankModel> list)
{
return FUNCTION_NOT_ALLOWED_ERROR;
@@ -2913,6 +2912,7 @@ namespace CMS_CORE.Siemens
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError TOOLS_WStartEditTooling(int magazineId)
{
return FUNCTION_NOT_ALLOWED_ERROR;
@@ -2927,6 +2927,7 @@ namespace CMS_CORE.Siemens
{
return FUNCTION_NOT_ALLOWED_ERROR;
}
#endregion Nc Tool Manager
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -3307,6 +3308,7 @@ namespace CMS_CORE.Siemens
};
}
break;
case 2:
case 3:
{
@@ -3356,14 +3358,27 @@ namespace CMS_CORE.Siemens
{
// Read tool id
dataSvc = new DataSvc();
readedItem = new Item("$AC_TC_TNO");
readedItem = new Item("/Channel/State/aTcTno");
dataSvc.Read(readedItem);
toolId = Convert.ToInt32(readedItem.Value);
// Set destination indexes
destinationMagIndex = 4;
destinationPosIndex = 5;
if (magAction == MAGAZINE_ACTIONS.UNLOADING)
{
// Set source indexes
sourceMagIndex = 2;
sourcePosIndex = 3;
// Set destination indexes
destinationMagIndex = 0;
destinationPosIndex = 1;
}
else
{
// Set destination indexes
destinationMagIndex = 4;
destinationPosIndex = 5;
}
}
// Read position and tool data
@@ -3394,7 +3409,6 @@ namespace CMS_CORE.Siemens
// IsMultitool = false
// }).FirstOrDefault();
// // If not found in the tools list, check in the multitools list
// if (tool == null)
// tool = MultitoolsData.Where(x => x.Id == toolId)?.Select(x => new MagazineActionToolModel