WIP Fanuc RStoredData, read tools from fanuc memory
Added new magazine action to demo
This commit is contained in:
@@ -133,6 +133,11 @@ namespace CMS_CORE_Application
|
||||
//AssistedToolingModel ass = new AssistedToolingModel();
|
||||
//cmsError = N.PLC_RAssistedToolingData(ref ass);
|
||||
N.TOOLS_WStartEditData();
|
||||
|
||||
List<NcToolModel> tools = new List<NcToolModel>();
|
||||
List<NcFamilyModel> families = new List<NcFamilyModel>(); ;
|
||||
List<NcShankModel> shanks = new List<NcShankModel>();
|
||||
N.TOOLS_RStoredData(ref tools, ref families, ref shanks);
|
||||
cmsError = N.PROC_RSelectedProcessData(1, ref selected);
|
||||
|
||||
ProcessDataModel procData = new ProcessDataModel();
|
||||
|
||||
@@ -3224,7 +3224,7 @@ namespace CMS_CORE_Library.Demo
|
||||
}
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_RStoredData()
|
||||
public override CmsError TOOLS_RStoredData(ref List<NcToolModel> tools, ref List<NcFamilyModel> families, ref List<NcShankModel> shanks)
|
||||
{
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -547,40 +547,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
|
||||
////Check if the NC is Connected
|
||||
//CmsError cmsError = CheckConnection();
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//Focas1.OPMSG3 Messg = new Focas1.OPMSG3();
|
||||
//short nReturn = 0;
|
||||
//short count = FANUC_MAXMSGPMC;
|
||||
|
||||
////Execute the method
|
||||
//nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg);
|
||||
|
||||
////Throw Exception if there's an error
|
||||
//if (nReturn != 0)
|
||||
// return GetNcError(nReturn);
|
||||
|
||||
//// Add Alarm in List
|
||||
//alarms.Clear();
|
||||
|
||||
//if (count >= 1 && Messg.msg1.datano >= 0)
|
||||
// AddPlcAlarmsToList((ushort)Messg.msg1.datano, false, false, new List<int>() { 1 }, alarms);
|
||||
|
||||
//if (count >= 2 && Messg.msg2.datano >= 0)
|
||||
// AddPlcAlarmsToList((ushort)Messg.msg2.datano, false, false, new List<int>() { 1 }, alarms);
|
||||
|
||||
//if (count >= 3 && Messg.msg3.datano >= 0)
|
||||
// AddPlcAlarmsToList((ushort)Messg.msg3.datano, false, false, new List<int>() { 1 }, alarms);
|
||||
|
||||
//if (count >= 4 && Messg.msg4.datano >= 0)
|
||||
// AddPlcAlarmsToList((ushort)Messg.msg4.datano, false, false, new List<int>() { 1 }, alarms);
|
||||
|
||||
//if (count >= 5 && Messg.msg5.datano >= 0)
|
||||
// AddPlcAlarmsToList((ushort)Messg.msg5.datano, false, false, new List<int>() { 1 }, alarms);
|
||||
}
|
||||
|
||||
public override CmsError PLC_WRefreshMessage(uint id)
|
||||
@@ -1703,11 +1669,27 @@ namespace CMS_CORE_Library.Fanuc
|
||||
offsetId = (short)macroVal;
|
||||
}
|
||||
|
||||
// Read operator's message #3006 & #3017
|
||||
Focas1.OPMSG3 Messg = new Focas1.OPMSG3();
|
||||
short count = FANUC_MAXMSGPMC;
|
||||
|
||||
// Execute the method
|
||||
nReturn = Focas1.cnc_rdopmsg3(nLibHandle[0], -1, ref count, Messg);
|
||||
|
||||
// Check return value
|
||||
if (nReturn != 0)
|
||||
return GetNcError(nReturn);
|
||||
|
||||
string msg = "";
|
||||
// Check if message exist & if is an operator type (type == 4)
|
||||
if (count >= 5 && Messg.msg5.datano >= 0 && Messg.msg5.type == 4)
|
||||
msg = Messg.msg5.data;
|
||||
|
||||
processData = new SelectedProcessData()
|
||||
{
|
||||
ActiveOffsetId = offsetId,
|
||||
Origin = origin,
|
||||
ProcessMessage = ""
|
||||
ProcessMessage = msg
|
||||
};
|
||||
|
||||
return NO_ERROR;
|
||||
@@ -3750,11 +3732,88 @@ namespace CMS_CORE_Library.Fanuc
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_RStoredData()
|
||||
public override CmsError TOOLS_RStoredData(ref List<NcToolModel> tools, ref List<NcFamilyModel> families, ref List<NcShankModel> shanks)
|
||||
{
|
||||
List<int> readInt = new List<int>();
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 0, FAMILY_TABLE_INDEX.MemType, FAMILY_TABLE_INDEX.Address, FAMILY_TABLE_INDEX.Size/4, ref readInt);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Test
|
||||
FromMemoryToModels(readInt, out families);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
private void FromMemoryToModels<T>(List<int> ints, out List<T> models)
|
||||
{
|
||||
models = new List<T>();
|
||||
|
||||
PropertyInfo[] properties = typeof(T).GetProperties();
|
||||
List<byte> byteValues = IntsToBytes(ints);
|
||||
|
||||
// Index of the
|
||||
int objOffset = 0;
|
||||
|
||||
int propertyIndex = 0;
|
||||
// Start from the begin of the table
|
||||
for (int memoryIndex = 0; memoryIndex < byteValues.Count();)
|
||||
{
|
||||
// Get the size of the property
|
||||
int size = Marshal.SizeOf(properties[propertyIndex].PropertyType);
|
||||
|
||||
// Choose action based on the size
|
||||
switch (size)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
properties[propertyIndex].SetValue(models[objOffset], byteValues[memoryIndex]);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
short u = BitConverter.ToInt16(new byte[2] { byteValues[memoryIndex], byteValues[memoryIndex + 1] }, 0);
|
||||
// If is in the ID's memory range
|
||||
if (memoryIndex < TOOL_OFFSET)
|
||||
// Create TMP item with generic type declaration
|
||||
models.Add((T)Activator.CreateInstance(typeof(T)));
|
||||
|
||||
properties[propertyIndex].SetValue(models[objOffset], u);
|
||||
|
||||
memoryIndex += 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
{
|
||||
int i = BitConverter.ToInt32(new byte[4] { byteValues[memoryIndex], byteValues[memoryIndex + 1], byteValues[memoryIndex + 2], byteValues[memoryIndex + 3], }, 0);
|
||||
properties[propertyIndex].SetValue(models[objOffset], i);
|
||||
|
||||
memoryIndex += 4;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if there is another object
|
||||
if (objOffset + 1 >= models.Count())
|
||||
{
|
||||
objOffset = 0;
|
||||
// check if there is another property
|
||||
if (propertyIndex + 1 >= properties.Count())
|
||||
// if not, i wrote all the object's properties so exit from loop
|
||||
propertyIndex = byteValues.Count();
|
||||
else
|
||||
propertyIndex += 1;
|
||||
}
|
||||
else
|
||||
objOffset++;
|
||||
}
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_RMagazineBlock(ref List<int> ids)
|
||||
{
|
||||
ids = new List<int>();
|
||||
|
||||
@@ -84,7 +84,8 @@ namespace CMS_CORE_Library.Models
|
||||
READY = 1,
|
||||
LOADING = 2,
|
||||
UNLOADING = 3,
|
||||
EXCHANGE = 5
|
||||
EXCHANGE = 5,
|
||||
START_NEEDED = 7
|
||||
}
|
||||
|
||||
public enum SIEMENS_MAGAZINE_TYPE
|
||||
|
||||
@@ -1696,7 +1696,7 @@ namespace CMS_CORE_Library
|
||||
|
||||
public abstract CmsError TOOLS_RUpdatedToolsData(ref Dictionary<int, byte> updatedStatus, ref Dictionary<int, uint> updatedLives);
|
||||
|
||||
public abstract CmsError TOOLS_RStoredData();
|
||||
public abstract CmsError TOOLS_RStoredData(ref List<NcToolModel> tools, ref List<NcFamilyModel> families, ref List<NcShankModel> shanks);
|
||||
|
||||
public abstract CmsError TOOLS_RMagazineBlock(ref List<int> ids);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace CMS_CORE_Library.Osai
|
||||
private static List<string> EXT_IMG = new List<string>() { "PNG", "JPG", "JPEG" };
|
||||
private const uint MAX_ROWS_FILE_PREVIEW = 10; // massimo 10 righe
|
||||
|
||||
private const string TOOL_MANAGER_BACKUP_DIRECTORY_PATH = @"C:\CMS\Active\TMP\";
|
||||
private const string TOOL_MANAGER_BACKUP_DIRECTORY_PATH = @"\\";
|
||||
private const string FAMILIES_FILE_NAME = @"Families";
|
||||
private const string FAM_SIZE_FILE_NAME = @"Fam_Sizes";
|
||||
|
||||
@@ -3699,7 +3699,7 @@ namespace CMS_CORE_Library.Osai
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_RStoredData()
|
||||
public override CmsError TOOLS_RStoredData(ref List<NcToolModel> tools, ref List<NcFamilyModel> families, ref List<NcShankModel> shanks)
|
||||
{
|
||||
CmsError cmsError = CreateBackup();
|
||||
if (cmsError.IsError())
|
||||
@@ -3708,12 +3708,12 @@ namespace CMS_CORE_Library.Osai
|
||||
string backupFilePath = TOOL_MANAGER_BACKUP_DIRECTORY_PATH + "{0}.csv";
|
||||
if (File.Exists(string.Format(backupFilePath, FAMILIES_FILE_NAME)))
|
||||
{
|
||||
List<NcFamilyFileModel> families = File.ReadAllLines(string.Format(backupFilePath, FAMILIES_FILE_NAME)) // Read file
|
||||
families = File.ReadAllLines(string.Format(backupFilePath, FAMILIES_FILE_NAME)) // Read file
|
||||
.Where(x => x != string.Empty)
|
||||
.Select(x => x.Split(';')) // Split line
|
||||
.Select(x => new NcFamilyFileModel // Setup new model for each line
|
||||
.Select(x => new NcFamilyModel // Setup new model for each line
|
||||
{
|
||||
Id = int.Parse(x[0]),
|
||||
FamilyId = ushort.Parse(x[0]),
|
||||
ToolType = byte.Parse(x[1]),
|
||||
TcpTable = byte.Parse(x[2]),
|
||||
Gamma = byte.Parse(x[3]),
|
||||
@@ -3747,7 +3747,7 @@ namespace CMS_CORE_Library.Osai
|
||||
|
||||
if (File.Exists(string.Format(backupFilePath, TOOLS_FILE_NAME)))
|
||||
{
|
||||
List<NcToolModel> tools = File.ReadAllLines(string.Format(backupFilePath, TOOLS_FILE_NAME))
|
||||
tools = File.ReadAllLines(string.Format(backupFilePath, TOOLS_FILE_NAME))
|
||||
.Where(x => x != string.Empty)
|
||||
.Select(x => x.Split(';'))
|
||||
.Select(x => new NcToolModel
|
||||
@@ -3767,7 +3767,7 @@ namespace CMS_CORE_Library.Osai
|
||||
|
||||
if (File.Exists(string.Format(backupFilePath, SHANKS_FILE_NAME)))
|
||||
{
|
||||
List<NcShankModel> shanks = File.ReadAllLines(string.Format(backupFilePath, SHANKS_FILE_NAME))
|
||||
shanks = File.ReadAllLines(string.Format(backupFilePath, SHANKS_FILE_NAME))
|
||||
.Where(x => x != string.Empty)
|
||||
.Select(x => x.Split(';'))
|
||||
.Select(x => new NcShankModel
|
||||
@@ -3780,19 +3780,19 @@ namespace CMS_CORE_Library.Osai
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
if (File.Exists(string.Format(backupFilePath, MAG_POSITION_FILE_NAME)))
|
||||
{
|
||||
List<NcMagazinePositionModel> positions = File.ReadAllLines(string.Format(backupFilePath, MAG_POSITION_FILE_NAME))
|
||||
.Where(x => x != string.Empty)
|
||||
.Select(x => x.Split(';'))
|
||||
.Select(x => new NcMagazinePositionModel
|
||||
{
|
||||
MagazineId = byte.Parse(x[0]),
|
||||
PositionId = byte.Parse(x[1]),
|
||||
Type = byte.Parse(x[2]),
|
||||
// Disabled = byte.Parse(x[3]) > 0 ? (byte)1 : (byte)0
|
||||
}).ToList();
|
||||
}
|
||||
//if (File.Exists(string.Format(backupFilePath, MAG_POSITION_FILE_NAME)))
|
||||
//{
|
||||
// List<NcMagazinePositionModel> positions = File.ReadAllLines(string.Format(backupFilePath, MAG_POSITION_FILE_NAME))
|
||||
// .Where(x => x != string.Empty)
|
||||
// .Select(x => x.Split(';'))
|
||||
// .Select(x => new NcMagazinePositionModel
|
||||
// {
|
||||
// MagazineId = byte.Parse(x[0]),
|
||||
// PositionId = byte.Parse(x[1]),
|
||||
// Type = byte.Parse(x[2]),
|
||||
// // Disabled = byte.Parse(x[3]) > 0 ? (byte)1 : (byte)0
|
||||
// }).ToList();
|
||||
//}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -4274,7 +4274,7 @@ namespace CMS_CORE_Library.Siemens
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_RStoredData()
|
||||
public override CmsError TOOLS_RStoredData(ref List<NcToolModel> tools, ref List<NcFamilyModel> families, ref List<NcShankModel> shanks)
|
||||
{
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ namespace CMS_CORE_Library.Utils
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
// Convert a byte into an array of bools
|
||||
// Convert a generic number into an array of byte
|
||||
internal static byte[] NumberToByte(object val)
|
||||
{
|
||||
return BitConverter.GetBytes(Convert.ToInt32(val));
|
||||
|
||||
@@ -70,11 +70,13 @@ namespace Nc_Demo_Application
|
||||
|
||||
public enum MAGAZINE_ACTIONS
|
||||
{
|
||||
NONE = 0,
|
||||
LOADING = 1,
|
||||
UNLOADING = 2,
|
||||
NOT_READY = 0,
|
||||
NONE = 1,
|
||||
LOADING = 2,
|
||||
UNLOADING = 3,
|
||||
TRANSFER = 4,
|
||||
GENERIC = 5
|
||||
GENERIC = 5,
|
||||
START_NEEDED = 7
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user