Fix siemens

FIx Fanuc
This commit is contained in:
Lucio Maranta
2019-01-28 08:15:55 +00:00
parent 795c281f36
commit 439a61cd59
5 changed files with 111 additions and 48 deletions
+4 -2
View File
@@ -104,8 +104,10 @@ namespace CMS_CORE_Application
if (cmsError.IsError()){ error = true; SetError(Lines, cmsError); }
Dictionary<int, string> dictionary = new Dictionary<int, string>();
cmsError = N.NC_GetTranslatedPlcMessages("it", ref dictionary);
List<AxisModel> axes = new List<AxisModel>();
List<M155InputIsNeededModel> b = new List<M155InputIsNeededModel>();
N.PLC_ROperatorInputIsNeeded(ref b);
////////////////////////////////////////// TEST
Stopwatch st = new Stopwatch();
sw.Restart();
+1 -3
View File
@@ -319,7 +319,6 @@ namespace CMS_CORE_Library.Demo
return NO_ERROR;
}
// Get NC unit of measure
public override CmsError NC_RUnitOfMeasure(ref string unitOfMeasure)
{
@@ -855,8 +854,7 @@ namespace CMS_CORE_Library.Demo
{
return NO_ERROR;
}
public override CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value)
{
string[] index = memIndex.Split('.');
+39 -7
View File
@@ -830,15 +830,36 @@ namespace CMS_CORE_Library.Fanuc
return cmsError;
bool[] bits = ByteToBits(val);
uint i = 0;
value = bits
.Select(x => new M155InputIsNeededModel()
uint processId = 1;
foreach(bool bit in bits)
{
if (bit)
{
Process = i++,
IsNeeded = x
})
.ToList();
string actualLine = "";
// Read active program line
cmsError = PROC_ReadActiveLine(processId, ref actualLine);
if (cmsError.IsError())
return cmsError;
// Extract parameters
string[] parameters = ExtractM155ParametersFromNcCodeLine(actualLine);
byte i = 0;
// Populate buttons
Dictionary<byte, string> buttons = parameters.Skip(1)?.ToDictionary(x => i++, x => x);
// Create output model
value.Add(new M155InputIsNeededModel()
{
Process = processId,
IsNeeded = bit,
Message = parameters[0] ?? "",
Type = parameters.Count() > 1 ? M155_TYPE.MULTIPLE_BUTTONS : M155_TYPE.REAL, // if there aren't buttons is a simple request
Buttons = buttons
});
}
processId++;
}
return NO_ERROR;
}
@@ -1196,6 +1217,17 @@ namespace CMS_CORE_Library.Fanuc
return NO_ERROR;
}
private CmsError PROC_ReadActiveLine(uint processId, ref string line)
{
uint lineL = 1;
uint txtL = 50;
short nReturn = Focas1.cnc_rdprogline2(nLibHandle[(int)processId - 1], 0, 1, line, ref lineL, ref txtL);
if (nReturn != 0)
return GetNcError(nReturn);
return NO_ERROR;
}
#endregion PROCESS (PATH) High-level data
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+7 -7
View File
@@ -3115,7 +3115,7 @@ namespace CMS_CORE_Library.Osai
// 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);
cmsError = MEM_RWIntegerList(R, 0, TOOL_STATUS_UPDATED_CMD.MemType, TOOL_STATUS_UPDATED_CMD.Address, 3, ref readInt);
if (cmsError.IsError())
return cmsError;
@@ -3130,11 +3130,11 @@ namespace CMS_CORE_Library.Osai
for (int i = 0; i < bits.Length; i++)
{
if (bits[i])
if (i < 32 && i > 62 && bits[i])
{
int bitIndex = i;
if (i >= 32) // 32 status bit and 32 lives bit
bitIndex -= 32;
if (i >= 64) // 32 status bit and 32 lives bit
bitIndex -= 64;
// First tool id + actual head index
int headIndex = (HEADS_DATA.Address + 2) + (bitIndex * 5);
@@ -3160,7 +3160,7 @@ namespace CMS_CORE_Library.Osai
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
int lifeIndex = TOOL_LIFE_UPDATED_DATA.Address + (bitIndex * 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;
@@ -3171,8 +3171,8 @@ namespace CMS_CORE_Library.Osai
// Setup ack/strobe indexes
// if i > (32) + 15 then index = next 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;
strobeByteIndex = i > 69 ? TOOL_LIFE_UPDATED_CMD.Address + 1 : TOOL_LIFE_UPDATED_CMD.Address;
ackByteIndex = i > 69 ? TOOL_LIFE_UPDATED_ACK.Address + 1 : TOOL_LIFE_UPDATED_CMD.Address;
}
// Manage ack and strobe
+60 -29
View File
@@ -1054,7 +1054,7 @@ namespace CMS_CORE_Library.Siemens
if (bit)
{
// Read active program line
cmsError = ReadActiveLine(processId, ref actualLine);
cmsError = PROC_ReadActiveLine(processId, ref actualLine);
if (cmsError.IsError())
return cmsError;
@@ -1096,6 +1096,8 @@ namespace CMS_CORE_Library.Siemens
dataSvc.Write(item);
return PLC_WStrobe(M155_INPUT_ACK, M155_INPUT_STROBE,(uint)process);
}
catch (Exception ex)
@@ -1120,7 +1122,7 @@ namespace CMS_CORE_Library.Siemens
foreach (bool bit in bits)
{
// Read active program line
cmsError = ReadActiveLine(processId, ref tmpStr);
cmsError = PROC_ReadActiveLine(processId, ref tmpStr);
if (cmsError.IsError())
return cmsError;
@@ -1196,30 +1198,7 @@ namespace CMS_CORE_Library.Siemens
return NO_ERROR;
}
private CmsError ReadActiveLine(uint path, ref string line)
{
try
{
Item item = new Item();
if (path == 0)
item.Path = "/Channel/ProgramInfo/actBlock[u1,1]"; // Default
else
item.Path = "/Channel/ProgramInfo/actBlock[u" + path + ",1]";
DataSvc dataSvc = new DataSvc();
dataSvc.Read(item);
line = item.Value.ToString();
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
private CmsError PLC_WStrobe(MEMORY_CELL ackCell, MEMORY_CELL strobeCell, uint id)
{
CmsError cmsError;
@@ -1567,6 +1546,29 @@ namespace CMS_CORE_Library.Siemens
return NO_ERROR;
}
private CmsError PROC_ReadActiveLine(uint processId, ref string line)
{
try
{
Item item = new Item();
if (processId == 0)
item.Path = "/Channel/ProgramInfo/actBlock[u1,1]"; // Default
else
item.Path = "/Channel/ProgramInfo/actBlock[u" + processId + ",1]";
DataSvc dataSvc = new DataSvc();
dataSvc.Read(item);
line = item.Value.ToString();
}
catch (Exception ex)
{
return ManageException(ex);
}
return NO_ERROR;
}
#endregion PROCESS (PATH) High-level data
@@ -2264,6 +2266,7 @@ namespace CMS_CORE_Library.Siemens
public override CmsError FILES_RGetFileList(string path, ref List<PreviewFileModel> files)
{
string[] rootFolders = { "WKS.DIR", "MPF.DIR", "SPF.DIR" };
try
{
string tmpPath = FormatPath(path);
@@ -2277,18 +2280,46 @@ namespace CMS_CORE_Library.Siemens
// Go through the array of file nodes
foreach (Node element in nodeArray)
{
if (element.AccessRights.List == AccessLevel.KEY_0)
PreviewFileModel file = new PreviewFileModel();
if(path == "\\\\")
{
var file = new PreviewFileModel()
if (rootFolders.Contains(element.Name))
{
file = new PreviewFileModel()
{
Path = path + "\\" + element.Name,
IsDirectory = element.IsDirNode,
Name = element.Name,
AbsolutePath = element.LogicalPath
};
files.Add(file);
}
}
else
{
file = new PreviewFileModel()
{
Path = path + "\\" + element.Name,
IsDirectory = element.IsDirNode,
Name = element.Name,
AbsolutePath = element.LogicalPath
};
files.Add(file);
}
// ACCESS LEVEL CHECK (REMOVED TEMPORARILY)
//if (element.AccessRights.List == AccessLevel.KEY_0)
//{
// var file = new PreviewFileModel()
// {
// Path = path + "\\" + element.Name,
// IsDirectory = element.IsDirNode,
// Name = element.Name,
// AbsolutePath = element.LogicalPath
// };
// files.Add(file);
//}
}
}
catch (Exception ex)