& alarm Fixes
This commit is contained in:
Lucio Maranta
2018-11-21 17:26:58 +01:00
parent 929f8ffa53
commit 0e009dc6ec
7 changed files with 88 additions and 67 deletions
Binary file not shown.
+45 -5
View File
@@ -24,10 +24,52 @@ public static class ThreadsFunctions
private static long ReadAxesNamesTimer = 0, ReadAxesNamesTimes = 0;
private static long ReadHeadsTimer = 0, ReadHeadsTimes = 0;
private static long ReadToolDataTimer = 0, ReadToolDataTimes = 0;
private static long WatchdogTimer = 0, WatchdogTimes = 0;
private static Thread ConnThread;
#region Nc functions threads
#region Functions
public static void ManageWatchdog()
{
NcHandler ncHandler = new NcHandler();
Stopwatch sw = new Stopwatch();
try
{
CmsError libraryError = ncHandler.Connect();
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
while (true)
{
sw.Restart();
// Check if client is connected
if (ncHandler.numericalControl.NC_IsConnected())
{
// Manage watchdog
libraryError = ncHandler.ManageWatchdog();
}
else
TryNcConnection();
sw.Stop();
//Update thread timer
WatchdogTimer += sw.ElapsedMilliseconds;
WatchdogTimes++;
// Wait
Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
{
ncHandler.Dispose();
}
}
public static void ReadAlarms()
{
@@ -115,7 +157,6 @@ public static class ThreadsFunctions
}
}
// Read processes part program status
public static void ReadProcessesPPStatus()
{
NcHandler ncHandler = new NcHandler();
@@ -157,7 +198,6 @@ public static class ThreadsFunctions
MessageServices.Current.Publish(SEND_NC_SOFTKEYS_DATA, null, ncSoftKeys);
// Send m155 through signalR
MessageServices.Current.Publish(SEND_M155_DATA, null, m155Data);
}
}
}
@@ -459,7 +499,7 @@ public static class ThreadsFunctions
try
{
// Try connection
CmsError libraryError = ncHandler.Connect();
CmsError libraryError = ncHandler.Connect();
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
@@ -675,7 +715,7 @@ public static class ThreadsFunctions
}
}
#endregion Nc functions threads
#endregion Functions
#region SupportFunctions
+12 -13
View File
@@ -8,6 +8,7 @@ using System.IO;
using System.Linq;
using static Step.Model.Constants;
using static Step.Config.ServerConfig;
using System.Diagnostics;
namespace Step.Database.Controllers
{
@@ -47,21 +48,19 @@ namespace Step.Database.Controllers
.OrderBy(x => x.AlarmOccurrenceId)
.Include("Users")
.Where(x =>
x.TimeStamp >= startDate && x.TimeStamp <= endDate
&& types.Contains(x.Type)
&& x.Users.Any(y => userIds.Any(z => z == y.UserId))
x.TimeStamp >= startDate && x.TimeStamp <= endDate // Filter by date
&& types.Contains(x.Type) // Type
&& x.Users.Any(y => userIds.Any(z => z == y.UserId)) // Check user
&&
((x.Source == ALARM_SOURCE.NC && ncAlarmDescIds.Contains(x.AlarmDescriptionId.Value))
|| (x.Source == ALARM_SOURCE.PLC && plcAlarmDescIds.Contains(x.PlcMessageId.Value)))
);
var occurrences = occurrencesQuery
.Skip(page * pageSize)
.Take(pageSize)
.Include("AlarmDescription")
.ToList();
((x.Source == ALARM_SOURCE.NC && ncAlarmDescIds.Contains(x.AlarmDescriptionId.Value)) // Check if message is contained in NC messages
|| (x.Source == ALARM_SOURCE.PLC && plcAlarmDescIds.Contains(x.PlcMessageId.Value))) // Check if message is contained in PLC messages
)
.Skip(page * pageSize) // Paginate
.Take(pageSize)
.Include("AlarmDescription") // Include foreign key
.ToList();
return occurrences
return occurrencesQuery
.Select(x => (DTOAlarmHistoricModel)x)
.ToList();
}
+2 -2
View File
@@ -34,12 +34,12 @@ namespace Step.Model.DatabaseModels
{
return new NcShankModel()
{
ShankId = obj.ShankId,
ShankId = (ushort)obj.ShankId,
Balluf = obj.Balluf == null ? (ushort)0 : (ushort)obj.Balluf.Value,
MagazineId = obj.MagazineId == null ? (byte)0 : obj.MagazineId.Value,
PositionId = obj.PositionId == null ? (byte)0 : obj.PositionId.Value,
MagazinePositionType = obj.MagazinePositionType,
};
};
}
}
}
+20 -43
View File
@@ -30,8 +30,8 @@ namespace Step.NC
public Nc numericalControl;
public NcHandler() =>
// Choose NC
numericalControl = SetNumericalControl();
// Choose NC
numericalControl = SetNumericalControl();
public void Dispose()
{
@@ -87,7 +87,7 @@ namespace Step.NC
CmsError cmsError = NO_ERROR;
if (File.Exists(path))
cmsError = LocalPartProgramFileInfo(path, out fileInfo);
cmsError = LocalPartProgramFileInfo(path, out fileInfo);
else
cmsError = numericalControl.FILES_RGetFileInfo(path, ref fileInfo);
@@ -120,10 +120,10 @@ namespace Step.NC
return FILE_NOT_FOUND_ERROR;
string base64Img = model.Metadata.Generics.Images.Count() > 0 ? model.Metadata.Generics.Images[0].Base64 : "";
fileInfo = new DTOActiveImageAndNameDataModel()
{
Image = base64Img,
Image = base64Img,
Name = Path.GetFileName(path) // TODO: Get From NC
};
@@ -139,13 +139,13 @@ namespace Step.NC
fileInfo = new DTOActiveImageAndNameDataModel()
{
Image = SupportFunctions.FindImageBase64String(IMAGES_PATH, name),
Image = SupportFunctions.FindImageBase64String(IMAGES_PATH, name),
Name = Path.GetFileName(name) // TODO: Get From NC
};
}
return NO_ERROR;
}
}
public CmsError LocalPartProgramFileInfo(string path, out InfoFile fileInfo)
{
@@ -164,7 +164,7 @@ namespace Step.NC
// Populate fileInfo content
fileInfo.Content = new List<string>();
while ((line = fileRead.ReadLine()) != null && count < 10)
while ((line = fileRead.ReadLine()) != null && count < 10)
{
fileInfo.Content.Add(line);
count++;
@@ -250,7 +250,7 @@ namespace Step.NC
};
return cmsError;
}
}
public CmsError UploadPartProgram(string localPath, string fileName, out string newFilePath)
{
@@ -430,34 +430,6 @@ namespace Step.NC
return NO_ERROR;
}
//public CmsError SwapQueueItems(int processId, int item1Index, int item2Index)
//{
// item1Index = item1Index - 1;
// item2Index = item2Index - 1;
// // Check if there is a queue
// if (!PartProgramQueue.ContainsKey(processId))
// return INCORRECT_PARAMETERS_ERROR;
// // Check if items exists
// if (PartProgramQueue[processId].ElementAtOrDefault(item1Index) == null || PartProgramQueue[processId].ElementAtOrDefault(item2Index) == null)
// return INCORRECT_PARAMETERS_ERROR;
// // Create a item
// DTOQueueModel tmp = PartProgramQueue[processId][item1Index];
// // Swap item 1 with 2
// PartProgramQueue[processId][item1Index] = PartProgramQueue[processId][item2Index];
// // Swap 2 with tmp
// PartProgramQueue[processId][item2Index] = tmp;
// // Swap ids
// PartProgramQueue[processId][item2Index].Id = item2Index + 1;
// // Swap 2 with tmp
// PartProgramQueue[processId][item1Index].Id = item1Index + 1;
// return NO_ERROR;
//}
public CmsError MoveQueueItems(int processId, int itemId, int newIndex, out List<DTOQueueModel> queue)
{
itemId = itemId - 1;
@@ -578,6 +550,11 @@ namespace Step.NC
#region Read Data
public CmsError ManageWatchdog()
{
return numericalControl.PLC_RWManageWatchdog();
}
public CmsError GetNcGenericData(out DTONcGenericDataModel genericData)
{
genericData = new DTONcGenericDataModel(MachineConfig.Model);
@@ -1327,7 +1304,7 @@ namespace Step.NC
public CmsError ReadAxisData(out List<DTOAxisNameModel> axesNames)
{
axesNames = new List<DTOAxisNameModel>();
List<AxisModel> plcAxes = new List<AxisModel>();
List<AxisModel> plcAxes = new List<AxisModel>();
// Read selected process
ushort selectedProcess = 0;
CmsError cmsError = numericalControl.PROC_RSelectedProcess(ref selectedProcess);
@@ -1343,7 +1320,7 @@ namespace Step.NC
{
Id = x.Id,
Name = x.Name,
IsSelectable = x.IsSelectable
IsSelectable = x.IsSelectable
}).ToList();
}
@@ -1442,7 +1419,7 @@ namespace Step.NC
families = new List<FamilyModel>();
return numericalControl.TOOLS_RFamilyData(ref families);
}
public CmsError GetMagazinesPositionsData(out List<PositionModel> magazinesPositions)
{
magazinesPositions = new List<PositionModel>();
@@ -1474,10 +1451,10 @@ namespace Step.NC
data = ncData.Select(x => new DTOM155InputModel()
{
Buttons = x.Buttons,
IsNeeded = x.IsNeeded,
Buttons = x.Buttons,
IsNeeded = x.IsNeeded,
Message = x.Message,
Process = x.Process,
Process = x.Process,
Type = x.Type.ToString()
}).ToList();
@@ -16,7 +16,7 @@ namespace Step.Controllers.WebApi
public class FavoriteUserSoftkeyController : ApiController
{
[Route("favorite"), HttpGet]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.MAINTENANCE, Action = ACTIONS.WRITE)]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_SOFTKEY, Action = ACTIONS.WRITE)]
public IHttpActionResult GetFavoriteSoftkeys()
{
var identity = User.Identity as ClaimsIdentity;
@@ -32,7 +32,7 @@ namespace Step.Controllers.WebApi
}
[Route("favorite"), HttpPut]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.MAINTENANCE, Action = ACTIONS.WRITE)]
[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_SOFTKEY, Action = ACTIONS.WRITE)]
public IHttpActionResult PutFavoriteSoftkeys(List<uint> favoriteSoftkeyIds)
{
var identity = User.Identity as ClaimsIdentity;
+7 -2
View File
@@ -38,7 +38,7 @@ namespace Step
ServerControlWindow.Start();
// Create unhandled exception handler
// AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);
// Read config
ServerConfigController.ReadStartupConfig();
@@ -117,7 +117,12 @@ namespace Step
private static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args)
{
using (NcHandler ncHandler = new NcHandler())
ncHandler.Disconnect();
{
if (ncHandler.numericalControl.NC_IsConnected())
{
ncHandler.Disconnect();
}
}
LogException((Exception)args.ExceptionObject, ERROR_LEVEL.FATAL);
}