This commit is contained in:
@@ -2682,9 +2682,9 @@ namespace CMS_CORE_Library.Fanuc
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Read data -> 10 status, 10 magazine position numbers
|
||||
// Read data -> 5 status word (10 byte), 10 magazine max position word
|
||||
List<ushort> readShorts = new List<ushort>();
|
||||
cmsError = MEM_RWWordList(R, 0, MAGAZINE_TYPES.MemType, MAGAZINE_TYPES.Address, 20, ref readShorts);
|
||||
cmsError = MEM_RWWordList(R, 0, MAGAZINE_TYPES.MemType, MAGAZINE_TYPES.Address, 15, ref readShorts);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
@@ -2695,12 +2695,12 @@ namespace CMS_CORE_Library.Fanuc
|
||||
config = new List<NcMagazineConfigModel>();
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
// Check if there are positions
|
||||
if (types[i + 20] > 0)
|
||||
// Check if there are positions (skip the 5 status word)
|
||||
if (readShorts[i + 5] > 0)
|
||||
config.Add(new NcMagazineConfigModel()
|
||||
{
|
||||
Id = (byte)(i + 1),
|
||||
MaxPositions = types[i + 20],
|
||||
MaxPositions = readShorts[i + 5],
|
||||
Type = (NC_MAGAZINE_TYPE)types[i]
|
||||
});
|
||||
}
|
||||
@@ -2870,26 +2870,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
List<int> newMemoryValues = TOOLS_CreateNewToolTableMemoryData(toolsList, TOOL_TABLE_INDEX);
|
||||
// Write in memory
|
||||
return MEM_RWIntegerList(W, 0, TOOL_TABLE_INDEX.MemType, TOOL_TABLE_INDEX.Address, newMemoryValues.Count(), ref newMemoryValues);
|
||||
|
||||
//List<int> zeros = Enumerable.Repeat(0, TOOL_TABLE_INDEX.Size / 4).ToList();
|
||||
//CmsError cmsError = MEM_RWIntegerList(W, 0, TOOL_TABLE_INDEX.MemType, TOOL_TABLE_INDEX.Address, TOOL_TABLE_INDEX.Size / 4, ref zeros);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//foreach (NcToolModel tool in toolsList)
|
||||
//{
|
||||
// // Get the offset of the id in the memory
|
||||
// cmsError = TOOLS_RPositionOfNextShortId(tool.ToolId, TOOL_TABLE_INDEX.Address, out int offset);
|
||||
// if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
// // Write object in memory
|
||||
// cmsError = TOOLS_WObjectInMemory(tool, TOOL_TABLE_INDEX.Address, offset);
|
||||
// if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
//}
|
||||
|
||||
//return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_WUpdateFamilies(List<NcFamilyModel> familyList)
|
||||
@@ -2903,26 +2883,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
List<int> newMemoryValues = TOOLS_CreateNewToolTableMemoryData(familyList, FAMILY_TABLE_INDEX);
|
||||
|
||||
return MEM_RWIntegerList(W, 0, FAMILY_TABLE_INDEX.MemType, FAMILY_TABLE_INDEX.Address, newMemoryValues.Count(), ref newMemoryValues);
|
||||
|
||||
//List<int> zeros = Enumerable.Repeat(0, FAMILY_TABLE_INDEX.Size / 4).ToList();
|
||||
//CmsError cmsError = MEM_RWIntegerList(W, 0, FAMILY_TABLE_INDEX.MemType, FAMILY_TABLE_INDEX.Address, FAMILY_TABLE_INDEX.Size / 4, ref zeros);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//foreach (NcFamilyModel fam in familyList)
|
||||
//{
|
||||
// // Get the offset of the id in the memory
|
||||
// cmsError = TOOLS_RPositionOfNextShortId(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> shankList)
|
||||
@@ -2937,26 +2897,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
|
||||
// Write in memory
|
||||
return MEM_RWIntegerList(W, 0, SHANK_TABLE_INDEX.MemType, SHANK_TABLE_INDEX.Address, newMemoryValues.Count(), ref newMemoryValues);
|
||||
|
||||
//List<int> zeros = Enumerable.Repeat(0, SHANK_TABLE_INDEX.Size / 4).ToList();
|
||||
//CmsError cmsError = MEM_RWIntegerList(W, 0, SHANK_TABLE_INDEX.MemType, SHANK_TABLE_INDEX.Address, SHANK_TABLE_INDEX.Size / 4, ref zeros);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//foreach (NcShankModel shank in shankList)
|
||||
//{
|
||||
// // Get the offset of the id in the memory
|
||||
// cmsError = TOOLS_RPositionOfNextShortId(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> magPosList)
|
||||
@@ -2968,28 +2908,9 @@ namespace CMS_CORE_Library.Fanuc
|
||||
return cmsError;
|
||||
// Create new values of the magazine positions table
|
||||
List<int> newMemoryValues = TOOLS_CreateNewToolTableMemoryData(magPosList, MAG_POS_TABLE_INDEX);
|
||||
|
||||
// Write in memory
|
||||
return MEM_RWIntegerList(W, 0, MAG_POS_TABLE_INDEX.MemType, MAG_POS_TABLE_INDEX.Address, newMemoryValues.Count(), ref newMemoryValues);
|
||||
|
||||
//List<int> zeros = Enumerable.Repeat(0, SHANK_TABLE_INDEX.Size / 4).ToList();
|
||||
//CmsError cmsError = MEM_RWIntegerList(W, 0, MAG_POS_TABLE_INDEX.MemType, MAG_POS_TABLE_INDEX.Address, MAG_POS_TABLE_INDEX.Size / 4, ref zeros);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
//foreach (NcMagazinePositionModel pos in magPosList)
|
||||
//{
|
||||
// // Get the offset of the id in the memory
|
||||
// cmsError = TOOLS_RPositionOfNextByteId(pos.PositionId, MAG_POS_TABLE_INDEX.Address, out int offset);
|
||||
// if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
|
||||
// // Write object in memory
|
||||
// cmsError = TOOLS_WObjectInMemory(pos, MAG_POS_TABLE_INDEX.Address, offset);
|
||||
// if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
//}
|
||||
|
||||
//return NO_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError TOOLS_WStartEditTooling(int magazineId)
|
||||
@@ -3056,6 +2977,82 @@ namespace CMS_CORE_Library.Fanuc
|
||||
|
||||
public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary<int, byte> updatedStatus, ref Dictionary<int, uint> updatedLives)
|
||||
{
|
||||
// Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
updatedStatus = new Dictionary<int, byte>();
|
||||
updatedLives = new Dictionary<int, uint>();
|
||||
|
||||
// Read 20 bit of status, read 20 bit of tool life
|
||||
List<int> readInt = new List<int>();
|
||||
cmsError = MEM_RWIntegerList(R, 0, TOOL_STATUS_UPDATED_CMD.MemType, TOOL_STATUS_UPDATED_CMD.Address, 2, ref readInt);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Convert int into to true/false array
|
||||
bool[] bits = IntToBits(readInt.ToArray());
|
||||
ushort toolId = 0;
|
||||
byte status = 0;
|
||||
uint life = 0;
|
||||
|
||||
int strobeByteIndex = 0;
|
||||
int ackByteIndex = 0;
|
||||
|
||||
for (int i = 0; i < bits.Length; i++)
|
||||
{
|
||||
if (bits[i])
|
||||
{
|
||||
// If i >= 32 reset bit index
|
||||
int bitIndex = i >= 32 ? i - 32 : i;
|
||||
|
||||
// mountedToolIndex =
|
||||
int mountedToolIndex = (HEADS_DATA.Address + 4) + (bitIndex * 12);
|
||||
cmsError = MEM_RWWord(R, 0, HEADS_DATA.MemType, mountedToolIndex, ref toolId);
|
||||
|
||||
if (i < 32)
|
||||
{
|
||||
// Read new status value
|
||||
int statusByteIndex = i % 2;
|
||||
int statusIndex = TOOL_STATUS_UPDATED_DATA.Address + (i / 2); // Index = starting address + (headIndex / 2) -> because Osai uses 16bit format
|
||||
cmsError = MEM_RWByte(R, 0, TOOL_STATUS_UPDATED_DATA.MemType, statusIndex, statusByteIndex, ref status);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Insert into the list
|
||||
updatedStatus.Add(toolId, status);
|
||||
|
||||
// Setup ack/strobe indexes
|
||||
// if i > 15 then index = next word
|
||||
strobeByteIndex = i > 15 ? TOOL_STATUS_UPDATED_CMD.Address + 1 : TOOL_STATUS_UPDATED_CMD.Address;
|
||||
ackByteIndex = i > 15 ? TOOL_STATUS_UPDATED_ACK.Address + 1 : TOOL_STATUS_UPDATED_ACK.Address;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read new life value
|
||||
int lifeIndex = TOOL_LIFE_UPDATED_DATA.Address + ((i - 32) * 2); // Index = starting address + (headIndex * 2) -> because Osai uses 16bit format
|
||||
cmsError = MEM_RWDWord(R, 0, TOOL_LIFE_UPDATED_DATA.MemType, lifeIndex, ref life);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Insert into the new lives list
|
||||
updatedLives.Add(toolId, life);
|
||||
|
||||
// Setup ack/strobe indexes
|
||||
// if i > (32) + 15 then StrobeAckIndex is in the second word
|
||||
strobeByteIndex = i > 47 ? TOOL_LIFE_UPDATED_CMD.Address + 1 : TOOL_LIFE_UPDATED_CMD.Address;
|
||||
ackByteIndex = i > 47 ? TOOL_LIFE_UPDATED_ACK.Address + 1 : TOOL_LIFE_UPDATED_CMD.Address;
|
||||
}
|
||||
|
||||
// Manage ack and strobe
|
||||
bitIndex = bitIndex % 16;
|
||||
cmsError = ManageActivePLCAcknowledge(strobeByteIndex, bitIndex, ackByteIndex, bitIndex, MEMORY_TYPE.Osai_MW);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -3131,6 +3128,7 @@ namespace CMS_CORE_Library.Fanuc
|
||||
Buffer.BlockCopy(ints.ToArray(), 0, bytes, 0, ints.Count * sizeof(ushort));
|
||||
|
||||
offset = 0;
|
||||
// Search last populated value
|
||||
for (int i = 0; i < bytes.Count(); i++)
|
||||
if (bytes[i] != 0)
|
||||
offset = i + 1;
|
||||
@@ -3221,10 +3219,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
{
|
||||
byte b = Convert.ToByte(property.GetValue(item));
|
||||
values[currentFieldIndex] = b;
|
||||
|
||||
// cmsError = MEM_RWByte(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, 0, ref b);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -3236,10 +3230,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
// Overwrite bytes with new values
|
||||
values[currentFieldIndex] = bytesVal[0];
|
||||
values[currentFieldIndex + 1] = bytesVal[1];
|
||||
|
||||
// cmsError = MEM_RWWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref u);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -3253,10 +3243,6 @@ namespace CMS_CORE_Library.Fanuc
|
||||
values[currentFieldIndex + 1] = bytesVal[1];
|
||||
values[currentFieldIndex + 2] = bytesVal[2];
|
||||
values[currentFieldIndex + 3] = bytesVal[3];
|
||||
|
||||
//cmsError = MEM_RWDWord(W, 0, MEMORY_TYPE.Fanuc_R, currentFieldIndex, ref w);
|
||||
//if (cmsError.IsError())
|
||||
// return cmsError;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -3299,6 +3285,58 @@ namespace CMS_CORE_Library.Fanuc
|
||||
return output;
|
||||
}
|
||||
|
||||
private CmsError ManageActivePLCAcknowledge(int strobeByte, int strobeBit, int ackByte, int ackBit, MEMORY_TYPE memType)
|
||||
{
|
||||
int n = 1200; // 30 seconds
|
||||
bool readValue = false;
|
||||
bool writeValue = true;
|
||||
bool ok = false;
|
||||
// Set ack to 1
|
||||
CmsError cmsError = MEM_RWBoolean(W, 0, memType, ackByte, ackBit, ref writeValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
do
|
||||
{
|
||||
// Check strobe
|
||||
cmsError = MEM_RWBoolean(R, 0, memType, strobeByte, strobeBit, ref readValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// If true reset acknowledge
|
||||
if (!readValue)
|
||||
{
|
||||
writeValue = false;
|
||||
// Reset acknowledge
|
||||
cmsError = MEM_RWBoolean(W, 0, memType, ackByte, ackBit, ref writeValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
// Exit from cycle
|
||||
n = 0;
|
||||
ok = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decrement
|
||||
n--;
|
||||
// Wait befor next cycle
|
||||
Thread.Sleep(25);
|
||||
}
|
||||
} while (n > 0);
|
||||
|
||||
// If loop timeout goes in timeout
|
||||
if (!ok)
|
||||
{
|
||||
// Reset acknowledge
|
||||
writeValue = false;
|
||||
cmsError = MEM_RWBoolean(W, 0, memType, ackByte, ackBit, ref writeValue);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
#endregion Nc Tool Manager
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -881,7 +881,7 @@ namespace CMS_CORE_Library.Osai
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
private CmsError ManageAcknowledge(int strobeByte, int strobeBit, int ackByte, int ackBit, MEMORY_TYPE memType)
|
||||
private CmsError ManageActivePLCAcknowledge(int strobeByte, int strobeBit, int ackByte, int ackBit, MEMORY_TYPE memType)
|
||||
{
|
||||
int n = 1200; // 30 seconds
|
||||
bool readValue = false;
|
||||
@@ -2960,7 +2960,7 @@ namespace CMS_CORE_Library.Osai
|
||||
|
||||
public override CmsError TOOLS_RUpdatedToolsData(ref Dictionary<int, byte> updatedStatus, ref Dictionary<int, uint> updatedLives)
|
||||
{
|
||||
//Check if the NC is Connected
|
||||
// Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
@@ -3031,7 +3031,7 @@ namespace CMS_CORE_Library.Osai
|
||||
|
||||
// Manage ack and strobe
|
||||
bitIndex = bitIndex % 16;
|
||||
cmsError = ManageAcknowledge(strobeByteIndex, bitIndex, ackByteIndex, bitIndex, MEMORY_TYPE.Osai_MW);
|
||||
cmsError = ManageActivePLCAcknowledge(strobeByteIndex, bitIndex, ackByteIndex, bitIndex, MEMORY_TYPE.Osai_MW);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user