Fix Fanuc library
WIP alarms filters
This commit is contained in:
Binary file not shown.
@@ -8,7 +8,7 @@
|
||||
<alarm>
|
||||
<alarmId>2</alarmId>
|
||||
<plcId>2</plcId>
|
||||
<restoreIsActive>false</restoreIsActive>
|
||||
<restoreIsActive>true</restoreIsActive>
|
||||
</alarm>
|
||||
<alarm>
|
||||
<alarmId>3</alarmId>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<serverConfig>
|
||||
<ncConfig>
|
||||
<ncVendor>SIEMENS</ncVendor> <!-- NO_NC/DEMO/FANUC/SIEMENS/OSAI -->
|
||||
<showNcHMI>true</showNcHMI>
|
||||
<ncVendor>DEMO</ncVendor> <!-- NO_NC/DEMO/FANUC/SIEMENS/OSAI -->
|
||||
<showNcHMI>false</showNcHMI>
|
||||
<ncIpAddress>localhost</ncIpAddress>
|
||||
<ncPort>8080</ncPort>
|
||||
<machineModel>Ares 37 OF</machineModel>
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Data.Entity;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using static Step.Model.Constants;
|
||||
using static Step.Config.ServerConfig;
|
||||
|
||||
namespace Step.Database.Controllers
|
||||
{
|
||||
@@ -26,22 +27,39 @@ namespace Step.Database.Controllers
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
public List<DTOAlarmHistoricModel> GetPaginatedWithFilter(string message, List<ALARM_TYPE> types, int page, int pageSize, DateTime startDate, DateTime endDate, List<int> userIds)
|
||||
public List<DTOAlarmHistoricModel> GetPaginatedWithFilter(string title, List<ALARM_TYPE> types, int page, int pageSize, DateTime startDate, DateTime endDate, List<int> userIds, Dictionary<int, string> plcMessages)
|
||||
{
|
||||
var occurrences = dbCtx
|
||||
List<int> ncAlarmDescIds = dbCtx
|
||||
.AlarmDescriptions
|
||||
.Where(x => x.Title.Contains(title))
|
||||
.Select(x => x.AlarmId)
|
||||
.ToList();
|
||||
|
||||
// Add Plc messages
|
||||
List<int> plcAlarmDescIds =
|
||||
plcMessages
|
||||
.Where(x => x.Value.Contains(title))
|
||||
.Select(x => x.Key)
|
||||
.ToList();
|
||||
|
||||
var occurrencesQuery = dbCtx
|
||||
.AlarmOccurrences
|
||||
.OrderBy(x => x.AlarmOccurrenceId)
|
||||
.Include("Users")
|
||||
.Include("Users")
|
||||
.Where(x =>
|
||||
x.TimeStamp >= startDate && x.TimeStamp <= endDate
|
||||
&& types.Contains(x.Type)
|
||||
&& x.Users.Any(y => userIds.Any(z => z == y.UserId))
|
||||
)
|
||||
.Skip(page * pageSize)
|
||||
.Take(pageSize)
|
||||
.Include("AlarmDescription")
|
||||
.ToList();
|
||||
|
||||
&& ((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();
|
||||
|
||||
return occurrences
|
||||
.Select(x => (DTOAlarmHistoricModel)x)
|
||||
.ToList();
|
||||
@@ -51,7 +69,7 @@ namespace Step.Database.Controllers
|
||||
{
|
||||
dbCtx.AlarmOccurrences.AddRange(alarms);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
dbCtx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void InsertNewNcAlarmDescriptions(List<AlarmDescriptionsModel> descriptions)
|
||||
@@ -66,7 +84,7 @@ namespace Step.Database.Controllers
|
||||
dbCtx.AlarmDescriptions.Add(desc);
|
||||
}
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
dbCtx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public void InsertNewAlarmUser(List<AlarmUserModel> loggedUser)
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -13,7 +13,7 @@ namespace Step.Database.Migrations
|
||||
|
||||
string IMigrationMetadata.Id
|
||||
{
|
||||
get { return "201810240848483_InitMigration"; }
|
||||
get { return "201811141155184_InitMigration"; }
|
||||
}
|
||||
|
||||
string IMigrationMetadata.Source
|
||||
+1
@@ -56,6 +56,7 @@ namespace Step.Database.Migrations
|
||||
type = c.Int(nullable: false),
|
||||
processes = c.Int(nullable: false),
|
||||
timestamp = c.DateTime(nullable: false, precision: 0),
|
||||
plc_message_id = c.Int(),
|
||||
})
|
||||
.PrimaryKey(t => t.id)
|
||||
.ForeignKey("dbo.alarm_description", t => t.alarm_id)
|
||||
File diff suppressed because one or more lines are too long
@@ -81,9 +81,9 @@
|
||||
<Compile Include="Controllers\MachinesUsersController.cs" />
|
||||
<Compile Include="Controllers\UserSoftkeysController.cs" />
|
||||
<Compile Include="DatabaseContext.cs" />
|
||||
<Compile Include="Migrations\201810240848483_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201810240848483_InitMigration.Designer.cs">
|
||||
<DependentUpon>201810240848483_InitMigration.cs</DependentUpon>
|
||||
<Compile Include="Migrations\201811141155184_InitMigration.cs" />
|
||||
<Compile Include="Migrations\201811141155184_InitMigration.Designer.cs">
|
||||
<DependentUpon>201811141155184_InitMigration.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Migrations\Configuration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -119,8 +119,8 @@
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Migrations\201810240848483_InitMigration.resx">
|
||||
<DependentUpon>201810240848483_InitMigration.cs</DependentUpon>
|
||||
<EmbeddedResource Include="Migrations\201811141155184_InitMigration.resx">
|
||||
<DependentUpon>201811141155184_InitMigration.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -4,8 +4,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Step.Model.Constants;
|
||||
|
||||
namespace Step.Model.DTOModels.AlarmModels
|
||||
@@ -21,15 +19,15 @@ namespace Step.Model.DTOModels.AlarmModels
|
||||
public string Description { get; set; }
|
||||
|
||||
public ALARM_SOURCE Source { get; set; }
|
||||
|
||||
|
||||
public ALARM_TYPE Type { get; set; }
|
||||
|
||||
|
||||
public List<int> Processes { get; set; }
|
||||
|
||||
|
||||
public DateTime TimeStamp { get; set; }
|
||||
|
||||
public List<int> Users { get; set; }
|
||||
|
||||
|
||||
public static explicit operator DTOAlarmHistoricModel(AlarmOccurrencesModel obj)
|
||||
{
|
||||
List<int> processes = new List<int>();
|
||||
@@ -55,29 +53,36 @@ namespace Step.Model.DTOModels.AlarmModels
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class DTOAlarmsFilterModel
|
||||
{
|
||||
[Required]
|
||||
public int Page { get; set; }
|
||||
|
||||
[Required]
|
||||
public int PageSize { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Title { get; set; }
|
||||
|
||||
[Required]
|
||||
public List<ALARM_TYPE> Type { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime? StartDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime EndDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public List<int> UserIds { get; set; }
|
||||
|
||||
public string Language { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public struct DTOAlarmsData
|
||||
{
|
||||
public int Pages;
|
||||
public DateTime FirstDate;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,9 @@ namespace Step.Model.DatabaseModels
|
||||
|
||||
[Column("timestamp")]
|
||||
public DateTime TimeStamp { get; set; }
|
||||
|
||||
[Column("plc_message_id")]
|
||||
public int? PlcMessageId { get; set; }
|
||||
|
||||
public AlarmDescriptionsModel AlarmDescription { get; set; }
|
||||
public List<AlarmUserModel> Users { get; set; }
|
||||
|
||||
@@ -8,6 +8,7 @@ using Step.Config;
|
||||
using Step.Model.DatabaseModels;
|
||||
using static Step.Config.ServerConfig;
|
||||
using static Step.Model.Constants;
|
||||
using static Step.Listeners.SignalRStaticObjects;
|
||||
|
||||
namespace Step
|
||||
{
|
||||
@@ -79,6 +80,11 @@ namespace Step
|
||||
if (functionAccess.WriteLevelMin > machineUser.Role.Level)
|
||||
return false; // Not authorized
|
||||
}
|
||||
|
||||
// Check if functionality is enabled by PLC
|
||||
var functionalityIsEnabled = LastRuntimeFunctionality.Where(x => x.Name == functionName).FirstOrDefault();
|
||||
if (functionalityIsEnabled == null || functionalityIsEnabled.Enabled == false)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Step.Database.Controllers;
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels.AlarmModels;
|
||||
using Step.NC;
|
||||
using Step.Provider;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -19,28 +19,23 @@ namespace Step.Controllers.WebApi
|
||||
[RoutePrefix("api/alarm")]
|
||||
public class ApiAlarmController : ApiController
|
||||
{
|
||||
//[Route(""), HttpGet]
|
||||
//public IHttpActionResult GetAll(int page, int pageSize)
|
||||
//{
|
||||
// using (AlarmsController alarm = new AlarmsController())
|
||||
// {
|
||||
// var a = alarm.GetPaginated(page, pageSize);
|
||||
|
||||
// return Ok(a);
|
||||
// }
|
||||
//}
|
||||
|
||||
[Route("paginated"), HttpPost]
|
||||
public IHttpActionResult GetDataPaginated([FromBody]DTOAlarmsFilterModel data)
|
||||
public IHttpActionResult GetDataPaginated([FromBody]DTOAlarmsFilterModel filter)
|
||||
{
|
||||
Validate(data);
|
||||
var a = ModelState.Values.Select(x => x.Errors);
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState);
|
||||
|
||||
Dictionary<int, string> plcMessages = new Dictionary<int, string>();
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
// Read data
|
||||
ncHandler.numericalControl.NC_GetTranslatedPlcMessages(filter.Language, ref plcMessages);
|
||||
}
|
||||
|
||||
|
||||
using (AlarmsController alarm = new AlarmsController())
|
||||
{
|
||||
var alarms = alarm.GetPaginatedWithFilter(data.Title, data.Type, data.Page - 1, data.PageSize, data.StartDate.Value, data.EndDate, data.UserIds);
|
||||
var alarms = alarm.GetPaginatedWithFilter(filter.Title, filter.Type, filter.Page - 1, filter.PageSize, filter.StartDate.Value, filter.EndDate, filter.UserIds, plcMessages);
|
||||
|
||||
return Ok(alarms);
|
||||
}
|
||||
@@ -165,7 +160,6 @@ namespace Step.Controllers.WebApi
|
||||
|
||||
#endregion Note
|
||||
|
||||
|
||||
#region Attachment
|
||||
|
||||
[Route("{alarmDescId:int}/attachments"), HttpGet]
|
||||
|
||||
@@ -121,13 +121,12 @@ namespace Step.Controllers.WebApi
|
||||
{
|
||||
using (NcHandler ncHandler = new NcHandler())
|
||||
{
|
||||
CmsError cmsError = ncHandler.Connect();
|
||||
Dictionary<string, string> returnValue = new Dictionary<string, string>();
|
||||
|
||||
Dictionary<int, string> messages = new Dictionary<int, string>();
|
||||
// Read data from CN
|
||||
cmsError = ncHandler.numericalControl.NC_GetTranslatedPlcMessages(language, ref messages);
|
||||
|
||||
ncHandler.numericalControl.NC_GetTranslatedPlcMessages(language, ref messages); // Avoid checking error because in the worst case "messages" is empty
|
||||
|
||||
// Id start from 1
|
||||
for (int i = 1; i <= 1024; i++)
|
||||
{
|
||||
|
||||
@@ -141,6 +141,7 @@ namespace Step.Listeners.Database
|
||||
alarmNewOccurrences.AddRange(differences.PlcAlarms.Select(x =>
|
||||
{
|
||||
int processesByte = 0;
|
||||
// Convert list to byte
|
||||
x.Process.ForEach(y => processesByte |= (1 << y));
|
||||
|
||||
return new AlarmOccurrencesModel()
|
||||
@@ -149,7 +150,8 @@ namespace Step.Listeners.Database
|
||||
Type = x.IsWarning ? ALARM_TYPE.WARNING : ALARM_TYPE.ERROR,
|
||||
Processes = processesByte,
|
||||
TimeStamp = x.DateTime,
|
||||
Source = ALARM_SOURCE.PLC
|
||||
Source = ALARM_SOURCE.PLC,
|
||||
PlcMessageId = (int)x.Id
|
||||
};
|
||||
}));
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
<div class="axes-menu-container" v-if="showAxesMenu">
|
||||
<div class="menu">
|
||||
<button @click="setAxes(a.id)"
|
||||
v-for="a in axes" v-if="a.isSelectable"
|
||||
v-for="a in axes"
|
||||
v-if="a.isSelectable"
|
||||
:key="a.id"
|
||||
:class="{active: a.id == selectedAxisId}">{{a.name}}</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user