Merge remote-tracking branch 'CMS/develop' into develop

This commit is contained in:
=
2020-07-13 09:52:42 +02:00
10 changed files with 160 additions and 47 deletions
+1 -1
View File
@@ -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);
@@ -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;
}
}
}
@@ -107,6 +107,7 @@
<Compile Include="DTOModels\DTOAxisNameModel.cs" />
<Compile Include="DTOModels\DTOClientConfigurationModel.cs" />
<Compile Include="DTOModels\ThModules\DTOModulesBlock.cs" />
<Compile Include="DTOModels\ThProd\DTOProdInfo.cs" />
<Compile Include="DTOModels\ThProd\DTOThermoPanelProd.cs" />
<Compile Include="DTOModels\ThProd\DTOThermoProd.cs" />
<Compile Include="DTOModels\ThRecipe\LiveData.cs" />
+38 -38
View File
@@ -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<int, double> origTcData = new Dictionary<int, double>();
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<int> numList = new List<int>();
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
/// </summary>
/// <param name="prodInfoData"></param>
/// <returns></returns>
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
+2 -2
View File
@@ -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
@@ -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}");
@@ -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
/// </summary>
/// <returns></returns>
[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<string, DTORecipeParam> currRecipe);
if (libraryError.IsError())
@@ -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))
{
@@ -38,11 +38,9 @@ namespace Thermo.Active.Listeners
public static Dictionary<string, double> LastAreaData = new Dictionary<string, double>();
public static Dictionary<string, DTOThermoProd> LastLiveProdData = new Dictionary<string, DTOThermoProd>();
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;
}
}
+1 -1
View File
@@ -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")]
[assembly: AssemblyVersion("0.9.36")]