Fix Siemens library, removed SHANKS

This commit is contained in:
Lucio Maranta
2018-10-31 16:58:51 +00:00
parent 9acab46c8e
commit 4bc228c131
8 changed files with 652 additions and 231 deletions
+4 -9
View File
@@ -134,14 +134,8 @@ namespace CMS_CORE_Application
////////////// SPEED TEST
Stopwatch st = new Stopwatch();
sw.Restart();
List<AlarmModel> b = new List<AlarmModel>();
cmsError = N.PROC_RActiveAlarms(1, ref b);
cmsError = N.PROC_RActiveAlarms(2, ref b);
cmsError = N.PROC_RActiveAlarms(3, ref b);
cmsError = N.PROC_RActiveAlarms(4, ref b);
cmsError = N.PROC_RActiveAlarms(5, ref b);
cmsError = N.PROC_RActiveAlarms(6, ref b);
cmsError = N.FILES_WDeactivateProgram(1);
Console.WriteLine("ICON" + sw.ElapsedMilliseconds);
sw.Stop();
@@ -246,7 +240,8 @@ namespace CMS_CORE_Application
if (t != null)
t.Abort();
N.NC_Disconnect();
if(N != null)
N.NC_Disconnect();
}
private void Disconnect_Click(object sender, EventArgs e)
+206 -24
View File
@@ -14,6 +14,7 @@ using static CMS_CORE_Library.Fanuc.MEMORY_ADDRESS;
using static CMS_CORE_Library.Models.DataStructures;
using static CMS_CORE_Library.Nc;
using static CMS_CORE_Library.Utils.Nc_Utils;
using static CMS_CORE_Library.ToolConfigurations;
using static Focas1;
#pragma warning disable 1591
@@ -2203,7 +2204,7 @@ namespace CMS_CORE_Library.Fanuc
public override CmsError FILES_WDeactivateProgram(int processId)
{
return NO_ERROR;
return FUNCTION_NOT_ALLOWED_ERROR;
}
public override CmsError FILES_UploadPartProgram(string localPath, string name, ref string newFilePath)
@@ -2211,6 +2212,7 @@ namespace CMS_CORE_Library.Fanuc
// Open file
FileStream fileStream = new FileStream(localPath + "\\" + name, FileMode.Open);
newFilePath = NC_PROGRAM_UPLOAD_PATH + name;
// Transfer file on NC
CmsError cmsError = FILES_WProgramFromFile(newFilePath, fileStream);
if (cmsError.IsError())
@@ -2370,6 +2372,50 @@ namespace CMS_CORE_Library.Fanuc
public override CmsError TOOLS_RConfiguration(ref ToolTableConfiguration config)
{
// Set limits
config.MaxTools = NC_MAX_TOOL_NUMER;
config.MaxEdgesPerTools = NC_MAX_EDGES_PER_TOOL;
config.MaxToolsPerFamily = NC_MAX_TOOLS_PER_FAMILY;
config.MaxMultitools = NC_MAX_MULTITOOLS_NUMBER;
config.MaxToolsPerMultitools = NC_MAX_TOOLS_PER_MULTITOOL;
// Set options
//config.MultitoolOptionActive = MULTITOOL_OPTION_ACTIVE;
//config.FamilyOptionActive = true;
//config.MagPositionOptionActive = true;
// Set fields configurations
config.ToolsConfiguration = NcToolFieldsConfig;
config.FamiliesConfiguration = NcFamilyFieldsConfig;
config.ShanksConfiguration = NcShankFieldsConfig;
config.MagazinePosConfiguration = NcMagazinePosFieldsConfig;
config.EdgesConfiguration = NcOffsetFieldsConfiguration;
config.MagPositionOptionActive = true;
config.MaxOffsets = 10;
// Setup magazine list
List<NcMagazineConfigModel> conf = new List<NcMagazineConfigModel>();
CmsError cmsError = TOOLS_RMagazineConfig(ref conf);
if (cmsError.IsError())
return cmsError;
// Get magazine status
Dictionary<int, bool> magazineStatus = new Dictionary<int, bool>();
cmsError = TOOLS_RMagazineStatus(ref magazineStatus);
if (cmsError.IsError())
return cmsError;
config.Magazines = conf.Select(x => new SiemensMagazineConfigModel()
{
Id = x.Id,
Type = ConvertToSiemensMagazineType(x.Type),
Name = x.Id.ToString(),
LoadingIsActive = magazineStatus[x.Id],
MaxPositions = x.MaxPositions
}).ToList();
config.EdgesConfiguration.EdgesAdditionalParamsConfiguration = new Dictionary<int, List<string>>();
return NO_ERROR;
}
@@ -2501,6 +2547,34 @@ namespace CMS_CORE_Library.Fanuc
public override CmsError TOOLS_RMagazineConfig(ref List<NcMagazineConfigModel> config)
{
// Check if the NC is Connected
CmsError cmsError = CheckConnection();
if (cmsError.IsError())
return cmsError;
// Read data -> 10 status, 10 magazine position numbers
List<ushort> readShorts = new List<ushort>();
cmsError = MEM_RWWordList(R, 0, MAGAZINE_TYPES.MemType, MAGAZINE_TYPES.Address, 20, ref readShorts);
if (cmsError.IsError())
return cmsError;
List<byte> types = new List<byte>();
// Convert into list o fbytes
types = readShorts.SelectMany(BitConverter.GetBytes).ToList();
config = new List<NcMagazineConfigModel>();
for (int i = 0; i < 10; i++)
{
// Check if there are positions
if (types[i + 20] > 0)
config.Add(new NcMagazineConfigModel()
{
Id = (byte)(i + 1),
MaxPositions = types[i + 20],
Type = (NC_MAGAZINE_TYPE)types[i]
});
}
return NO_ERROR;
}
@@ -2617,18 +2691,57 @@ namespace CMS_CORE_Library.Fanuc
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateFamilies(List<NcFamilyModel> list)
public override CmsError TOOLS_WUpdateFamilies(List<NcFamilyModel> familyList)
{
foreach(NcFamilyModel fam in familyList)
{
// Get the offset of the id in the memory
CmsError cmsError = TOOLS_RPositionId(fam.FamilyId, FAMILY_TABLE_INDEX.Address, out int offset);
if (cmsError.IsError())
return cmsError;
// Write object in memory
cmsError = TOOLS_WObjectInMemory(fam, FAMILY_TABLE_INDEX.Address, offset);
if (cmsError.IsError())
return cmsError;
}
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateShanks(List<NcShankModel> list)
public override CmsError TOOLS_WUpdateShanks(List<NcShankModel> shankList)
{
foreach (NcShankModel shank in shankList)
{
// Get the offset of the id in the memory
CmsError cmsError = TOOLS_RPositionId(shank.ShankId, SHANK_TABLE_INDEX.Address, out int offset);
if (cmsError.IsError())
return cmsError;
// Write object in memory
cmsError = TOOLS_WObjectInMemory(shank, SHANK_TABLE_INDEX.Address, offset);
if (cmsError.IsError())
return cmsError;
}
return NO_ERROR;
}
public override CmsError TOOLS_WUpdateMagazinePositions(List<NcMagazinePositionModel> list)
public override CmsError TOOLS_WUpdateMagazinePositions(List<NcMagazinePositionModel> magPosList)
{
foreach (NcMagazinePositionModel pos in magPosList)
{
// Get the offset of the id in the memory
CmsError cmsError = TOOLS_RPositionId(pos.PositionId, SHANK_TABLE_INDEX.Address, out int offset);
if (cmsError.IsError())
return cmsError;
// Write object in memory
cmsError = TOOLS_WObjectInMemory(pos, SHANK_TABLE_INDEX.Address, offset);
if (cmsError.IsError())
return cmsError;
}
return NO_ERROR;
}
@@ -2662,9 +2775,9 @@ namespace CMS_CORE_Library.Fanuc
return NO_ERROR;
}
private CmsError TOOLS_RPositionId(int id, int startIndex, out int index)
private CmsError TOOLS_RPositionId(int id, int startIndex, out int offset)
{
index = 0;
offset = 0;
// Read 300 bytes
List<int> ints = new List<int>();
@@ -2673,31 +2786,88 @@ namespace CMS_CORE_Library.Fanuc
return cmsError;
ushort[] bytes = new ushort[300];
// Copy into ushorts
Buffer.BlockCopy(ints.ToArray(), 0, bytes, 0, ints.Count * sizeof(ushort));
index = Array
// Find id
offset = Array
.FindIndex(bytes, x => x == id);
return NO_ERROR;
}
public CmsError TOOLS_WObjectInMemory<T>(List<T> items, int tableIndex, int objIndex) where T : class
public CmsError TOOLS_WObjectInMemory<T>(T item, int startTableIndex, int objOffset) where T : class
{
PropertyInfo[] properties = typeof(T).GetProperties();
CmsError cmsError = NO_ERROR;
int nextFieldIndex = tableIndex;
int nextFieldIndex = startTableIndex;
foreach (PropertyInfo property in properties)
{
// Get the size of the property
int size = Marshal.SizeOf(property.PropertyType);
// Add obj index to the parameter memory
int currentFieldIndex = nextFieldIndex + objOffset * size;
// Write based on the size
switch (size)
{
case 1:
{
byte b = Convert.ToByte(property.GetValue(item));
cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, 0, ref b);
if (cmsError.IsError())
return cmsError;
}
break;
case 2:
{
ushort u = Convert.ToUInt16(property.GetValue(item));
cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref u);
if (cmsError.IsError())
return cmsError;
}
break;
case 4:
{
uint w = Convert.ToUInt32(property.GetValue(item));
cmsError = MEM_RWDWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref w);
if (cmsError.IsError())
return cmsError;
}
break;
default:
break;
}
// Calculate the starting index of the next field
nextFieldIndex += size * TOOL_OFFSET;
}
return cmsError;
}
public CmsError TOOLS_WObjectsInMemory<T>(List<T> items, int startTableIndex) where T : class
{
PropertyInfo[] properties = typeof(T).GetProperties();
CmsError cmsError = NO_ERROR;
int nextFieldIndex = startTableIndex;
// Index of the
int objOffset = 0;
foreach (T item in items)
{
{
foreach (PropertyInfo property in properties)
{
// Get the size of the property
int size = Marshal.SizeOf(property.PropertyType);
// Add obj index to the parameter memory
int currentFieldIndex = nextFieldIndex + objIndex * size;
// Write
int currentFieldIndex = nextFieldIndex + objOffset * size;
// Write based on the size
switch (size)
{
case 1:
@@ -2706,21 +2876,24 @@ namespace CMS_CORE_Library.Fanuc
cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, 0, ref b);
if (cmsError.IsError())
return cmsError;
} break;
}
break;
case 2:
{
ushort u = Convert.ToUInt16(property.GetValue(item));
cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref u);
if (cmsError.IsError())
return cmsError;
} break;
}
break;
case 4:
{
uint w = Convert.ToUInt32(property.GetValue(item));
cmsError = MEM_RWDWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref w);
if (cmsError.IsError())
return cmsError;
} break;
}
break;
default:
break;
}
@@ -2728,11 +2901,14 @@ namespace CMS_CORE_Library.Fanuc
// Calculate the starting index of the next field
nextFieldIndex += size * TOOL_OFFSET;
}
// Increment offset
objOffset++;
}
return cmsError;
}
private string GenerateCsvStringFromModel<T>(List<T> items) where T : class
{
var output = "";
@@ -3458,12 +3634,18 @@ namespace CMS_CORE_Library.Fanuc
internal static MEMORY_CELL MAGAZINES_ENABLED_CMD = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13082, 2);
internal static MEMORY_CELL MAGAZINES_TOOLING_CMD = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13084, 2);
internal static MEMORY_CELL TOOL_STATUS_UPDATED_CMD = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13003, 2);
internal static MEMORY_CELL TOOL_LIFE_UPDATED_CMD = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13005, 2);
internal static MEMORY_CELL TOOL_STATUS_UPDATED_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13007, 2);
internal static MEMORY_CELL TOOL_LIFE_UPDATED_ACK = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13009, 2);
internal static MEMORY_CELL TOOL_STATUS_UPDATED_CMD = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13003, 2);
internal static MEMORY_CELL TOOL_LIFE_UPDATED_CMD = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13005, 2);
internal static MEMORY_CELL TOOL_STATUS_UPDATED_ACK = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13007, 2);
internal static MEMORY_CELL TOOL_LIFE_UPDATED_ACK = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13009, 2);
internal static MEMORY_CELL TOOL_STATUS_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13011, 10);
internal static MEMORY_CELL TOOL_LIFE_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Osai_MW, 13022, 40);
internal static MEMORY_CELL TOOL_STATUS_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13011, 10);
internal static MEMORY_CELL TOOL_LIFE_UPDATED_DATA = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 13022, 40);
// Tool table indexes
internal static MEMORY_CELL TOOL_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 35000, 6900);
internal static MEMORY_CELL FAMILY_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 42000, 7500);
internal static MEMORY_CELL SHANK_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 49600, 2100);
internal static MEMORY_CELL MAG_POS_TABLE_INDEX = new MEMORY_CELL(MEMORY_TYPE.Fanuc_R, 51800, 900);
}
}
@@ -307,6 +307,7 @@ namespace CMS_CORE_Library.Models
PART_PROGRAM = 1,
JOB = 2
}
public static IFormatProvider numberFormat = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
#region Cms Errors Codes
+1 -1
View File
@@ -190,7 +190,7 @@ namespace CMS_CORE_Library.Models
public class SiemensMagazineConfigModel
{
public byte Id;
public short Id;
public SIEMENS_MAGAZINE_TYPE Type;
public int MaxPositions;
public string Name;
+2 -1
View File
@@ -2348,7 +2348,7 @@ namespace CMS_CORE_Library.Osai
config.Magazines = conf.Select(x => new SiemensMagazineConfigModel()
{
Id = x.Id,
Type = (SIEMENS_MAGAZINE_TYPE)x.Type,
Type = ConvertToSiemensMagazineType(x.Type),
Name = x.Id.ToString(),
LoadingIsActive = magazineStatus[x.Id],
MaxPositions = x.MaxPositions
@@ -2503,6 +2503,7 @@ namespace CMS_CORE_Library.Osai
config = new List<NcMagazineConfigModel>();
for (int i = 0; i < 10; i++)
{
// Check if there are positions
if (types[i + 20] > 0)
config.Add(new NcMagazineConfigModel()
{
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -101,7 +101,7 @@ namespace CMS_CORE_Library
new FieldsConfiguration{ Name = "inFixedPlace", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "isMeasured", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "inChangeTool", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "inUse", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "isInUse", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "preAlarm", Type = "boolean", SelectValues = null, Category = "state", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "cooling1", Type = "boolean", SelectValues = null, Category = "cooling", ReadOnly = false, MinValue = 0, MaxValue = 0},
new FieldsConfiguration{ Name = "cooling2", Type = "boolean", SelectValues = null, Category = "cooling" , ReadOnly = false, MinValue = 0, MaxValue = 0},
+15 -13
View File
@@ -156,7 +156,7 @@ namespace CMS_CORE_Library.Utils
return fileContent;
}
// Get a substring from the beginning until the specified character
public static string GetUntilOrEmpty(string text, string stopAt = "[")
{
// Get string unti
@@ -185,29 +185,31 @@ namespace CMS_CORE_Library.Utils
return "";
}
public static IEnumerable<TSource> DistinctBy<TSource, TKey> (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
// Convert one integer in array of bools
public static bool[] IntToBool(int val)
{
return IntToBool(new int[] { val });
}
// Convert array of integers in an array of bools
public static bool[] IntToBool(int[] val)
{
return new BitArray(val.ToArray())
.Cast<bool>()
.ToArray();
}
public static SIEMENS_MAGAZINE_TYPE ConvertToSiemensMagazineType(NC_MAGAZINE_TYPE type)
{
switch (type)
{
case NC_MAGAZINE_TYPE.CHAIN: return SIEMENS_MAGAZINE_TYPE.CHAIN;
case NC_MAGAZINE_TYPE.BOX_MAGAZINE: return SIEMENS_MAGAZINE_TYPE.BOX_MAGAZINE;
case NC_MAGAZINE_TYPE.DISK: return SIEMENS_MAGAZINE_TYPE.REVOLVER;
}
return SIEMENS_MAGAZINE_TYPE.BOX_MAGAZINE;
}
}
}