diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs
index 3a4281d8..5b097c2a 100644
--- a/Thermo.Active.Core/ThreadsFunctions.cs
+++ b/Thermo.Active.Core/ThreadsFunctions.cs
@@ -732,7 +732,7 @@ public static class ThreadsFunctions
if (ncAdapter.numericalControl.NC_IsConnected())
{
// Get new data from PLC (and log if changed...)
- libraryError = ncAdapter.ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData);
+ libraryError = ncAdapter.ReadProdInfoData(out DTOProdInfo prodInfoData);
if (libraryError.IsError())
ManageLibraryError(libraryError);
diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs
new file mode 100644
index 00000000..a8ac886a
--- /dev/null
+++ b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs
@@ -0,0 +1,93 @@
+using CMS_CORE_Library.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Thermo.Active.Model.DTOModels.ThProd
+{
+ public class DTOProdInfo
+ {
+ public DateTime DtEvent { get; set; }
+ public short NumTarget { get; set; } = 0;
+ public short NumDone { get; set; } = 0;
+ public double TimeWarm { get; set; } = 0;
+ public double TimeVent { get; set; } = 0;
+ public double TimeVacuum { get; set; } = 0;
+ public double TimeCycleGross { get; set; } = 0;
+ public double TimeCycleNet { get; set; } = 0;
+ public int NumDec { get; set; } = 1;
+ public int ScaleFactor { get; set; } = 1000;
+ public double MaterialTempEndWarm { get; set; } = 0;
+ public double MaterialTempEndVent { get; set; } = 0;
+ public double MoldTemp { get; set; } = 0;
+ public double VacuumReadVal { get; set; } = 0;
+ public double MouldEnergyOUT { get; set; } = 0;
+ public double MouldEnergyIN { get; set; } = 0;
+
+ public override bool Equals(object obj)
+ {
+ // Object is not a GaugeModel instance
+ if (!(obj is DTOProdInfo item))
+ return false;
+
+ if (DtEvent != item.DtEvent)
+ return false;
+ if (NumTarget != item.NumTarget)
+ return false;
+ if (NumDone != item.NumDone)
+ return false;
+ if (TimeWarm != item.TimeWarm)
+ return false;
+ if (TimeVent != item.TimeVent)
+ return false;
+ if (TimeVacuum != item.TimeVacuum)
+ return false;
+ if (TimeCycleGross != item.TimeCycleGross)
+ return false;
+ if (TimeCycleNet != item.TimeCycleNet)
+ return false;
+ if (MaterialTempEndWarm != item.MaterialTempEndWarm)
+ return false;
+ if (MaterialTempEndVent != item.MaterialTempEndVent)
+ return false;
+ if (MoldTemp != item.MoldTemp)
+ return false;
+ if (VacuumReadVal != item.VacuumReadVal)
+ return false;
+ if (MouldEnergyOUT != item.MouldEnergyOUT)
+ return false;
+ if (MouldEnergyIN != item.MouldEnergyIN)
+ return false;
+
+ return true;
+ }
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public DTOProdInfo()
+ {
+ }
+
+ public DTOProdInfo(ThermoModels.ProdInfoModel pimRawData)
+ {
+ this.DtEvent = pimRawData.DtEvent;
+ this.NumDone = pimRawData.NumDone;
+ this.NumTarget = pimRawData.NumTarget;
+ this.TimeCycleGross = Math.Round((double)pimRawData.TimeCycleGross / this.ScaleFactor, 2);
+ this.TimeCycleNet = Math.Round((double)pimRawData.TimeCycleNet / this.ScaleFactor, 2);
+ this.TimeVacuum = Math.Round((double)pimRawData.TimeVacuum / this.ScaleFactor, 2);
+ this.TimeVent = Math.Round((double)pimRawData.TimeVent / this.ScaleFactor, 2);
+ this.TimeWarm = Math.Round((double)pimRawData.TimeWarm / this.ScaleFactor, 2);
+ this.MaterialTempEndWarm = pimRawData.MaterialTempEndWarm;
+ this.MaterialTempEndVent = pimRawData.MaterialTempEndVent;
+ this.MoldTemp = pimRawData.MoldTemp;
+ this.VacuumReadVal = pimRawData.VacuumReadVal;
+ this.MouldEnergyIN = pimRawData.MouldEnergyIN;
+ this.MouldEnergyOUT = pimRawData.MouldEnergyOUT;
+ }
+ }
+}
diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj
index 5bb9344c..85350ec6 100644
--- a/Thermo.Active.Model/Thermo.Active.Model.csproj
+++ b/Thermo.Active.Model/Thermo.Active.Model.csproj
@@ -107,6 +107,7 @@
+
diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs
index b43f142a..534dffc5 100644
--- a/Thermo.Active.NC/NcAdapter.cs
+++ b/Thermo.Active.NC/NcAdapter.cs
@@ -1296,13 +1296,13 @@ namespace Thermo.Active.NC
{
currentProdPanel.NumDone = lastProdInfoData.NumDone;
currentProdPanel.NumTarget = lastProdInfoData.NumTarget;
- currentProdPanel.LastTCiclo = lastProdInfoData.TimeCycleGross;
+ currentProdPanel.LastTCiclo = Math.Round((double)lastProdInfoData.TimeCycleGross / 1000, 2);
if (lastProdInfoData.TimeCycleGross > 0)
{
- currentProdPanel.LastCadenza = (double)3600 / lastProdInfoData.TimeCycleGross;
+ currentProdPanel.LastCadenza = Math.Round((double)3600000 / lastProdInfoData.TimeCycleGross, 2);
}
// stima durata da pz fatti...
- currentProdPanel.StimaDurata = (currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo;
+ currentProdPanel.StimaDurata = Math.Round((currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo, 2);
}
// dai parametri sistemo i setpoints
if (lastRecipe != null)
@@ -1324,52 +1324,48 @@ namespace Thermo.Active.NC
{
if (TS_TC.ContainsKey(item.NumDone))
{
- TS_TC[item.NumDone] = item.TimeCycleGross;
+ TS_TC[item.NumDone] = Math.Round((double)item.TimeCycleGross / 1000, 2);
}
else
{
- TS_TC.Add(item.NumDone, item.TimeCycleGross);
+ TS_TC.Add(item.NumDone, Math.Round((double)item.TimeCycleGross / 1000, 2));
}
if (item.TimeCycleGross > 0)
{
if (TS_Cad.ContainsKey(item.NumDone))
{
- TS_Cad[item.NumDone] = 3600 / item.TimeCycleGross;
+ TS_Cad[item.NumDone] = Math.Round((double)3600000 / item.TimeCycleGross, 2);
}
else
{
- TS_Cad.Add(item.NumDone, 3600 / item.TimeCycleGross);
+ TS_Cad.Add(item.NumDone, Math.Round((double)3600000 / item.TimeCycleGross, 2));
}
numTcOk++;
}
}
- // FIXME TODO: da levare post test... SE i TC sono zero (almeno 5)--> SIMULO
- if (numTcOk == 0 || (numRecProdPanelGraph - numTcOk) > 5)
+#if DEBUG
+
+ // creo una perturubazione...
+ var rand = new Random();
+ Dictionary origTcData = new Dictionary();
+ foreach (var item2fix in TS_TC)
{
- // calcolo primo/ultimo e divido...
- DateTime fine = prodInfoDataList[0].DtEvent;
- DateTime inizio = prodInfoDataList[prodInfoDataList.Count - 1].DtEvent;
- double TCMedio = Math.Abs(fine.Subtract(inizio).TotalSeconds / prodInfoDataList.Count);
- // simulo
- var rand = new Random();
- List numList = new List();
- foreach (var item2fix in TS_TC)
+ origTcData.Add(item2fix.Key, item2fix.Value);
+ }
+ foreach (var origVal in origTcData)
+ {
+ TS_TC[origVal.Key] = Math.Round(origVal.Value + (rand.NextDouble() * 20 - 10), 2);
+ if (TS_Cad.ContainsKey(origVal.Key))
{
- numList.Add(item2fix.Key);
+ TS_Cad[origVal.Key] = Math.Round((double)3600 / TS_TC[origVal.Key], 2);
}
- foreach (var numPz in numList)
+ else
{
- TS_TC[numPz] = TCMedio + (rand.NextDouble() * 4 - 2);
- if (TS_Cad.ContainsKey(numPz))
- {
- TS_Cad[numPz] = 3600 / TS_TC[numPz];
- }
- else
- {
- TS_Cad.Add(numPz, 3600 / TS_TC[numPz]);
- }
+ TS_Cad.Add(origVal.Key, Math.Round((double)3600 / TS_TC[origVal.Key], 2));
}
}
+
+#endif
// accodo!
currentProdPanel.TS_Cadenza = TS_Cad;
currentProdPanel.TS_TCiclo = TS_TC;
@@ -1404,29 +1400,33 @@ namespace Thermo.Active.NC
///
///
///
- public CmsError ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData)
+ public CmsError ReadProdInfoData(out DTOProdInfo prodInfoData)
{
- prodInfoData = new ThermoModels.ProdInfoModel();
- CmsError libraryError = numericalControl.PLC_RProdInfo(ref prodInfoData);
+ prodInfoData = new DTOProdInfo();
+ ThermoModels.ProdInfoModel prodInfoRawData = new ThermoModels.ProdInfoModel();
+ CmsError libraryError = numericalControl.PLC_RProdInfo(ref prodInfoRawData);
if (libraryError.IsError())
return libraryError;
+ // converto 1:1 dati da ThermoModels.ProdInfoModel --> DTOProdInfo
+ prodInfoData = new DTOProdInfo(prodInfoRawData);
+
// if lastProdInfo is missing --> populate!
if (lastProdInfoData == null)
- lastProdInfoData = prodInfoData;
+ lastProdInfoData = prodInfoRawData;
- // se ho update, sennò restituisco ultima lettura...
- if (ThermoProdUpdatedStr)
+ // se ho update OPPURE differenza di lettura..., sennò restituisco ultima lettura...
+ if (ThermoProdUpdatedStr || (lastProdInfoData.NumDone != prodInfoRawData.NumDone))
{
// do comparison with old record and if changed --> persist on DB!
- if (!prodInfoData.Equals(lastProdInfoData))
+ if (!prodInfoRawData.Equals(lastProdInfoData))
{
// save on DB!
using (ProdInfoController prodInfoController = new ProdInfoController())
- prodInfoController.Create(prodInfoData.NumTarget, prodInfoData.NumDone, prodInfoData.TimeWarm, prodInfoData.TimeVent, prodInfoData.TimeVacuum, prodInfoData.TimeCycleGross, prodInfoData.TimeCycleNet, prodInfoData.MaterialTempEndWarm, prodInfoData.MaterialTempEndVent, prodInfoData.MoldTemp, prodInfoData.VacuumReadVal, prodInfoData.MouldEnergyOUT, prodInfoData.MouldEnergyIN);
+ prodInfoController.Create(prodInfoRawData.NumTarget, prodInfoRawData.NumDone, prodInfoRawData.TimeWarm, prodInfoRawData.TimeVent, prodInfoRawData.TimeVacuum, prodInfoRawData.TimeCycleGross, prodInfoRawData.TimeCycleNet, prodInfoRawData.MaterialTempEndWarm, prodInfoRawData.MaterialTempEndVent, prodInfoRawData.MoldTemp, prodInfoRawData.VacuumReadVal, prodInfoRawData.MouldEnergyOUT, prodInfoRawData.MouldEnergyIN);
// update last info data
- lastProdInfoData = prodInfoData;
+ lastProdInfoData = prodInfoRawData;
// manage strobe/ack!
libraryError = numericalControl.PLC_WAckProdUpdate();
@@ -1436,7 +1436,7 @@ namespace Thermo.Active.NC
}
else
{
- prodInfoData = lastProdInfoData;
+ prodInfoRawData = lastProdInfoData;
}
// ora controllo inizio/fine produzione
diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs
index 6730692f..233332a8 100644
--- a/Thermo.Active.NC/NcFileAdapter.cs
+++ b/Thermo.Active.NC/NcFileAdapter.cs
@@ -764,7 +764,7 @@ namespace Thermo.Active.NC
{
answ = true;
// serialize
- string rawData = JsonConvert.SerializeObject(RecipeLiveData);
+ string rawData = JsonConvert.SerializeObject(RecipeLiveData, Newtonsoft.Json.Formatting.Indented);
// save live!
var dir = Path.GetDirectoryName(LIVE_RECIPE_PATH);
if (!Directory.Exists(dir))
@@ -848,7 +848,7 @@ namespace Thermo.Active.NC
// fix name!
currRecipe.RecipeName = fileName;
// serialize
- string rawData = JsonConvert.SerializeObject(currRecipe);
+ string rawData = JsonConvert.SerializeObject(currRecipe, Newtonsoft.Json.Formatting.Indented);
// save live!
File.WriteAllText(LIVE_RECIPE_PATH, rawData);
// verifica path
diff --git a/Thermo.Active/Controllers/WebApi/ProdController.cs b/Thermo.Active/Controllers/WebApi/ProdController.cs
index 2d6f1cf7..81f28f97 100644
--- a/Thermo.Active/Controllers/WebApi/ProdController.cs
+++ b/Thermo.Active/Controllers/WebApi/ProdController.cs
@@ -143,7 +143,7 @@ namespace Thermo.Active.Controllers.WebApi
}
// scrivo sul PLC il comando strobe richiesta AUTO!
- libraryError = ncAdapter.ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoDat);
+ libraryError = ncAdapter.ReadProdInfoData(out DTOProdInfo prodInfoDat);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetProd error | {libraryError.exception}");
diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs
index afe21404..9bb8d6e2 100644
--- a/Thermo.Active/Controllers/WebApi/RecipeController.cs
+++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs
@@ -2,18 +2,22 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Net;
using System.Net.Http;
+using System.Security.Claims;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using Thermo.Active.Config;
+using Thermo.Active.Database.Controllers;
using Thermo.Active.Model.DTOModels.ThRecipe;
using Thermo.Active.Model.DTOModels.ThWarmers;
using Thermo.Active.NC;
using Thermo.Active.Utils;
using static CMS_CORE_Library.Models.DataStructures;
using static Thermo.Active.Config.ServerConfig;
+using static Thermo.Active.Model.Constants;
namespace Thermo.Active.Controllers.WebApi
{
@@ -309,8 +313,25 @@ namespace Thermo.Active.Controllers.WebApi
///
///
[Route("save"), HttpPut]
+ //[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)]
public IHttpActionResult Save()
{
+#if false
+ // recupero dati utente loggato
+ var identity = User.Identity as ClaimsIdentity;
+ // Find user id from the bearer token
+ var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY);
+ if (userId == null)
+ return Unauthorized();
+
+ using (UsersController usersController = new UsersController())
+ {
+ var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value));
+ }
+#endif
+
+
+
// recupero i dati LIVE dei parametri HMI della ricetta...
CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe);
if (libraryError.IsError())
diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs
index 2614409e..86dbb1f7 100644
--- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs
+++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs
@@ -430,7 +430,7 @@ namespace Thermo.Active.Listeners.SignalR
}
public static void SendThermoProdInfoData(object prodInfoData)
{
- ProdInfoModel currProdInfo = prodInfoData as ProdInfoModel;
+ DTOProdInfo currProdInfo = prodInfoData as DTOProdInfo;
if (!LastProdInfoData.Equals(currProdInfo))
{
diff --git a/Thermo.Active/Listeners/SignalRStaticObjects.cs b/Thermo.Active/Listeners/SignalRStaticObjects.cs
index 7f5f9987..a34ab879 100644
--- a/Thermo.Active/Listeners/SignalRStaticObjects.cs
+++ b/Thermo.Active/Listeners/SignalRStaticObjects.cs
@@ -38,11 +38,9 @@ namespace Thermo.Active.Listeners
public static Dictionary LastAreaData = new Dictionary();
public static Dictionary LastLiveProdData = new Dictionary();
public static ThermoModels.ProdCycleModel LastProdCycleData = new ThermoModels.ProdCycleModel();
- public static ThermoModels.ProdInfoModel LastProdInfoData = new ThermoModels.ProdInfoModel();
+ public static DTOProdInfo LastProdInfoData = new DTOProdInfo();
public static DTOThermoPanelProd LastProdPanelData = new DTOThermoPanelProd();
-
public static bool LastIsNcConnected = false;
-
}
}
\ No newline at end of file
diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs
index 6832e260..ec2cfffb 100644
--- a/Thermo.Active/Properties/AssemblyInfo.cs
+++ b/Thermo.Active/Properties/AssemblyInfo.cs
@@ -30,4 +30,4 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("0.9.34")]
\ No newline at end of file
+[assembly: AssemblyVersion("0.9.36")]
\ No newline at end of file