Beta NC S7Net, da completare e testare
This commit is contained in:
@@ -139,8 +139,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
//Setup timeout
|
||||
TimeoutConn = ConnectionTimeOut;
|
||||
// FIXME: modificare in allarme generico bitmap?
|
||||
SiemensAlarms = new Alarm[] { };
|
||||
// mesasggi generici PLC
|
||||
PlcMessages = new Dictionary<int, string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +165,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
//Setup timeout
|
||||
TimeoutConn = ConnectionTimeOut;
|
||||
SiemensAlarms = new Alarm[] { };
|
||||
// mesasggi generici PLC
|
||||
PlcMessages = new Dictionary<int, string>();
|
||||
}
|
||||
|
||||
public override CmsError NC_Connect()
|
||||
@@ -632,30 +633,7 @@ namespace CMS_CORE_Library.S7Net
|
||||
// Get the Date-Time of the NC
|
||||
public override CmsError NC_RDateTime(ref DateTime ActualTime)
|
||||
{
|
||||
// Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
// Setup variables
|
||||
DataSvc Data = LowPriorityDataSvc();
|
||||
Item itemRead = new Item(NC_TIME_PATH);
|
||||
|
||||
// Read Data
|
||||
Data.Read(itemRead);
|
||||
|
||||
// Save Data
|
||||
ActualTime = (DateTime)itemRead.Value;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
// Check if the NC is in running state
|
||||
@@ -701,22 +679,28 @@ namespace CMS_CORE_Library.S7Net
|
||||
// Get the Nc Active Alarms
|
||||
public override CmsError NC_RActiveAlarms(ref List<AlarmModel> alarms)
|
||||
{
|
||||
// leggo bitmap allarmi e valorizzo con configurazione
|
||||
|
||||
// FIXME!!!!
|
||||
|
||||
#if false
|
||||
alarms = SiemensAlarms.
|
||||
Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel))
|
||||
.Select(x =>
|
||||
{
|
||||
uint id = x.Instance == 1 ? (uint)x.Id : Convert.ToUInt32((x.Id & 0xffff) | (x.Instance << 24));
|
||||
return new AlarmModel()
|
||||
{
|
||||
Id = id,
|
||||
Message = x.Message,
|
||||
IsWarning = false,
|
||||
Process = 0,
|
||||
DateTime = x.TimeStamp
|
||||
};
|
||||
})
|
||||
.GroupBy(x => x.Id).Select(x => x.First())
|
||||
.ToList();
|
||||
Where(x => (x.Id < IDMinPLCMessage || x.Id > IDMaxPLCMessage) && (x.Id < IDMinChannel || x.Id > IDMaxChannel))
|
||||
.Select(x =>
|
||||
{
|
||||
uint id = x.Instance == 1 ? (uint)x.Id : Convert.ToUInt32((x.Id & 0xffff) | (x.Instance << 24));
|
||||
return new AlarmModel()
|
||||
{
|
||||
Id = id,
|
||||
Message = x.Message,
|
||||
IsWarning = false,
|
||||
Process = 0,
|
||||
DateTime = x.TimeStamp
|
||||
};
|
||||
})
|
||||
.GroupBy(x => x.Id).Select(x => x.First())
|
||||
.ToList();
|
||||
#endif
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -1082,104 +1066,7 @@ namespace CMS_CORE_Library.S7Net
|
||||
|
||||
public override CmsError PLC_RHeadsData(List<HeadDataModel> heads, int number)
|
||||
{
|
||||
// Check parameters
|
||||
if (number > MAX_HEADS_NUMBER)
|
||||
return INCORRECT_PARAMETERS_ERROR;
|
||||
heads.Clear();
|
||||
|
||||
List<int> readInts = new List<int>();
|
||||
List<byte> readValues = new List<byte>();
|
||||
List<uint> readHours = new List<uint>();
|
||||
// Find the size of a single head
|
||||
int headsByte = (HEADS_DATA.Size / MAX_HEADS_NUMBER);
|
||||
double headsInts = Math.Ceiling((double)(headsByte / 4) + 1);
|
||||
|
||||
// Read data for N heads
|
||||
CmsError cmsError = MEM_RWIntegerList(R, 0,
|
||||
HEADS_DATA.MemType,
|
||||
HEADS_DATA.Address,
|
||||
HEADS_DATA.SubAddress,
|
||||
(int)headsInts * number,
|
||||
ref readInts);
|
||||
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
// Convert into list of byte
|
||||
readValues = readInts.SelectMany(BitConverter.GetBytes).ToList();
|
||||
|
||||
// Read Worked time heads
|
||||
cmsError = MEM_RWDWordList(R, 0, HEADS_WORKED_TIMES.MemType, HEADS_WORKED_TIMES.Address, HEADS_WORKED_TIMES.SubAddress, number, ref readHours);
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// Parse and format read data
|
||||
for (int i = 0; i < number; i++)
|
||||
{
|
||||
// Head address = posizion * size of single head in memory
|
||||
var headOffset = i * headsByte;
|
||||
short toolId = SwapShortEndianFormat(BitConverter.ToInt16(readValues.ToArray(), headOffset + 4));
|
||||
|
||||
double residualLife = 0;
|
||||
|
||||
// Find tool
|
||||
var tool = ToolTableData.Where(x => x.Id == toolId).FirstOrDefault();
|
||||
|
||||
// Check if process is selected
|
||||
if (readValues[headOffset] != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Read selected edge
|
||||
Item activeEdgeId = new Item { Path = "/Channel/State/actDNumber[u" + readValues[headOffset] + ",1]" }; // OffsetId
|
||||
DataSvc dataSvc = new DataSvc();
|
||||
dataSvc.Read(activeEdgeId);
|
||||
|
||||
if (Convert.ToInt32(activeEdgeId.Value) != 0)
|
||||
{
|
||||
// Find edge
|
||||
var edge = tool.EdgesData
|
||||
.Where(x => x.Id == Convert.ToInt32(activeEdgeId.Value))
|
||||
.FirstOrDefault();
|
||||
// Set residual life
|
||||
if (edge != null)
|
||||
residualLife = edge.ResidualLife;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
heads.Add(new HeadDataModel()
|
||||
{
|
||||
Id = (uint)i + 1,
|
||||
Process = readValues[headOffset],
|
||||
Override = readValues[headOffset + 1],
|
||||
Load_Abrasive = SwapShortEndianFormat(BitConverter.ToInt16(readValues.ToArray(), headOffset + 2)), // Uint 16 = 2byte
|
||||
MountedTool_Vacum = toolId, // Uint 16 = 2byte
|
||||
ActualSpeed_Pressure = SwapIntEndianFormat(BitConverter.ToInt32(readValues.ToArray(), headOffset + 6)), // Int32 = 4byte
|
||||
IsActive = (readValues[headOffset + 10] & 1) != 0, // bit 0
|
||||
IsSelected = (readValues[headOffset + 10] & 2) != 0, // bit 1
|
||||
OverrideEditable = (readValues[headOffset + 10] & 4) != 0, // bit 2
|
||||
Configured = (readValues[headOffset + 10] & 8) != 0,
|
||||
Rotation = (readValues[headOffset + 10] & 16) == 0 ? ROTATION.CLOCKWHISE : ROTATION.COUNTERCLOCKWHISE,
|
||||
WorkedTime = readHours[i],
|
||||
Tool = new ToolInSpindleModel()
|
||||
{
|
||||
ChildId = tool == null ? 0 : tool.ChildId,
|
||||
ToolName = tool == null ? "" : tool.FamilyName,
|
||||
Disabled = tool == null ? false : !tool.IsActive,
|
||||
Measured = tool == null ? false : tool.IsMeasured,
|
||||
Broken = tool == null ? false : tool.IsInhibited,
|
||||
MaxLoad = tool == null ? 0 : tool.Load,
|
||||
MaxSpeed = tool == null ? 0 : tool.MaxSpeed,
|
||||
ResidualLife = residualLife
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
public override CmsError PLC_RWorkedTimeHead(int head, ref uint time)
|
||||
@@ -2102,6 +1989,11 @@ namespace CMS_CORE_Library.S7Net
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
// FIXME
|
||||
|
||||
// fare guardando mappatura memoria stsato processo
|
||||
|
||||
#if false
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
@@ -2122,7 +2014,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -2135,6 +2028,12 @@ namespace CMS_CORE_Library.S7Net
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
|
||||
// FIXME
|
||||
|
||||
// fare guardando amppatura variabili status
|
||||
|
||||
#if false
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
@@ -2151,7 +2050,8 @@ namespace CMS_CORE_Library.S7Net
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
@@ -2159,99 +2059,37 @@ namespace CMS_CORE_Library.S7Net
|
||||
// Get PP Lines
|
||||
public override CmsError PROC_RPPLines(ushort ProcNumber, ref List<string> Lines)
|
||||
{
|
||||
// Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
string[] newLines;
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
// Setup variables
|
||||
DataSvc Data = HighPriorityDataSvc();
|
||||
Item itemRead = new Item(ACT_PROG_LINES_PATH + "[u" + ProcNumber + "]");
|
||||
|
||||
// Read Data
|
||||
Data.Read(itemRead);
|
||||
|
||||
// Save Data
|
||||
newLines = ((string)itemRead.Value).Replace("\r", string.Empty).Split('\n');
|
||||
|
||||
// Setup the return values
|
||||
Lines.Clear();
|
||||
foreach (string Line in newLines)
|
||||
Lines.Add(Line);
|
||||
|
||||
// Remove the first Line (the previous line)
|
||||
if (Lines.Count > 0)
|
||||
Lines.RemoveAt(0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
// Get PP Name
|
||||
public override CmsError PROC_RSelectedPPName(ushort ProcNumber, ref string Name)
|
||||
{
|
||||
// Check if the NC is Connected
|
||||
CmsError cmsError = CheckConnection();
|
||||
if (cmsError.IsError())
|
||||
return cmsError;
|
||||
|
||||
string RetString;
|
||||
int LastUnderscore;
|
||||
|
||||
// Try to get information
|
||||
try
|
||||
{
|
||||
// Setup variables
|
||||
DataSvc Data = HighPriorityDataSvc();
|
||||
Item itemRead = new Item(ACT_PROG_NAME_PATH + "[u" + ProcNumber + "]");
|
||||
|
||||
// Read Data
|
||||
Data.Read(itemRead);
|
||||
|
||||
// Elaborate String
|
||||
RetString = ((string)itemRead.Value);
|
||||
RetString = RetString.Replace("_N_", "");
|
||||
LastUnderscore = RetString.LastIndexOf("_");
|
||||
if (LastUnderscore >= 0)
|
||||
RetString = RetString.Remove(LastUnderscore, 1).Insert(LastUnderscore, ".");
|
||||
|
||||
// Save Data
|
||||
Name = RetString;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ManageException(ex);
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
return FUNCTION_NOT_ALLOWED_ERROR;
|
||||
}
|
||||
|
||||
// Get the process Active Alarms
|
||||
public override CmsError PROC_RActiveAlarms(ushort procNumber, ref List<AlarmModel> alarms)
|
||||
{
|
||||
// fare guardando bitmap allarmi attivi
|
||||
|
||||
#if false
|
||||
alarms = SiemensAlarms
|
||||
.Where(x => x.Id >= IDMinChannel && x.Id <= IDMaxChannel && x.Parameters[0].Equals(procNumber.ToString()))
|
||||
.Select(x =>
|
||||
{
|
||||
uint id = x.Instance == 1 ? (uint)x.Id : Convert.ToUInt32((x.Id & 0xffff) | (x.Instance << 24));
|
||||
return new AlarmModel()
|
||||
.Where(x => x.Id >= IDMinChannel && x.Id <= IDMaxChannel && x.Parameters[0].Equals(procNumber.ToString()))
|
||||
.Select(x =>
|
||||
{
|
||||
Id = id,
|
||||
Message = x.Message,
|
||||
IsWarning = false,
|
||||
Process = procNumber,
|
||||
DateTime = x.TimeStamp
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
uint id = x.Instance == 1 ? (uint)x.Id : Convert.ToUInt32((x.Id & 0xffff) | (x.Instance << 24));
|
||||
return new AlarmModel()
|
||||
{
|
||||
Id = id,
|
||||
Message = x.Message,
|
||||
IsWarning = false,
|
||||
Process = procNumber,
|
||||
DateTime = x.TimeStamp
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
#endif
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user