Inserimento preliminare metodi Recipe

This commit is contained in:
Samuele Locatelli
2020-04-24 16:55:02 +02:00
parent 747fe636be
commit e99d3bdb0d
9 changed files with 196 additions and 34 deletions
+1
View File
@@ -32,6 +32,7 @@ namespace Thermo.Active.Config
public static List<NcSoftKeysModel> NcSoftKeysConfig;
public static List<AlarmsConfigModel> InitialAlarmsConfig;
public static List<HeadsConfigModel> HeadsConfig;
public static List<RecipeConfigModel> RecipeConfig;
public static CmsConnectConfigModel CmsConnectConfig;
public static AreasConfigModel ProductionConfig;
@@ -33,6 +33,7 @@ namespace Thermo.Active.Config
ReadUserSoftKeysConfig();
ReadAlarmsConfig();
ReadHeadsConfig();
ReadRecipeConfig();
// ReadCMSConnectConfig();
ReadMacros();
ReadScadaFile();
@@ -572,6 +573,27 @@ namespace Thermo.Active.Config
.ToList();
}
private static void ReadRecipeConfig()
{
XDocument xmlConfigFile = GetXmlHandlerWithValidator(RECIPE_CONFIG_SCHEMA_PATH, RECIPE_CONFIG_PATH);
int i = 1;
// Read head config from XML file
RecipeConfig = xmlConfigFile
.Root
.Elements()
.Select(x => new RecipeConfigModel()
{
Id = Convert.ToInt16(x.Element("id").Value),
Category = GetTActCategory(x.Element("Category").Value),
SubCategory_1 = x.Element("SubCategory_1").Value,
SubCategory_2 = x.Element("SubCategory_2").Value,
Name = x.Element("Name").Value,
Description = x.Element("Description").Value,
Format = x.Element("Format").Value
})
.ToList();
}
private static void ReadCMSConnectConfig()
{
@@ -69,6 +69,7 @@
<Content Include="Config\customMainProgram.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Config\recipeConfig.xml" />
<Content Include="Config\userSoftKeyConfig.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
@@ -83,7 +84,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<EmbeddedResource Include="Config\headsConfigValidator.xsd">
<EmbeddedResource Include="Config\recipeConfigValidator.xsd">
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Config\maintenancesConfigValidator.xsd">
@@ -151,5 +152,10 @@
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Config\headsConfigValidator.xsd">
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -66,6 +66,7 @@
<Compile Include="ConfigModels\AlarmsConfigModel.cs" />
<Compile Include="ConfigModels\CmsConnectConfigModel.cs" />
<Compile Include="ConfigModels\ExtSoftwareModel.cs" />
<Compile Include="ConfigModels\RecipeConfigModel.cs" />
<Compile Include="ConfigModels\HeadsConfigModel.cs" />
<Compile Include="ConfigModels\MaintenanceConfigModel.cs" />
<Compile Include="ConfigModels\NcSoftKeysModel.cs" />
@@ -103,6 +104,7 @@
<Compile Include="DTOModels\DTOAxesModel.cs" />
<Compile Include="DTOModels\DTOAxisNameModel.cs" />
<Compile Include="DTOModels\DTOClientConfigurationModel.cs" />
<Compile Include="DTOModels\DTORecipeConfigModel .cs" />
<Compile Include="DTOModels\DTONetworkMonitor.cs" />
<Compile Include="DTOModels\DTOCmsConnectGateway.cs" />
<Compile Include="DTOModels\JobModels\DTOGenericParamModel.cs" />
+108 -33
View File
@@ -5,7 +5,7 @@ using CMS_CORE_Library.Models;
using CMS_CORE_Library.Osai;
using CMS_CORE_Library.Siemens;
using Thermo.Active.Database.Controllers;
using Thermo.Active.Model.DatabaseModels;
using Thermo.Active.Model.DatabaseModels;
using Thermo.Active.Model.DTOModels;
using Thermo.Active.Model.DTOModels.AlarmModels;
using Thermo.Active.Model.DTOModels.MaintenanceModels;
@@ -116,7 +116,7 @@ namespace Thermo.Active.NC
return cmsError;
}
public CmsError GetAxesPositionsByProcess(ushort processNum, out DTOAxesModel axes)
public CmsError GetAxesPositionsByProcess(ushort processNum, out DTOAxesModel axes)
{
axes = new DTOAxesModel();
@@ -232,7 +232,7 @@ namespace Thermo.Active.NC
// Max process number
genericData.ProcessNumber = procNum;
// Get Installation Date
genericData.InstallationDate = DateTime.ParseExact(NcConfig.InstallationDate, DATE_FORMATS, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
genericData.InstallationDate = DateTime.ParseExact(NcConfig.InstallationDate, DATE_FORMATS, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
// Get PLC version
genericData.PlcVersion = "1.0.0";
// Get PLC version
@@ -241,8 +241,8 @@ namespace Thermo.Active.NC
return cmsError;
genericData.UnitOfMeasurement = tmpInfo;
// Get Server version
genericData.ServerVersion = SupportFunctions.GetSoftwareVersionAndBuildDate();
// Get Server version
genericData.ServerVersion = SupportFunctions.GetSoftwareVersionAndBuildDate();
return cmsError;
}
@@ -539,7 +539,7 @@ namespace Thermo.Active.NC
if (performed != null)
perfVal = performed.CounterValue;
counterValue = (uint) Math.Ceiling(SupportFunctions.ConvertInUmeas(counterVal, currMaintenance.UnitOfMeasure.Value));
counterValue = (uint)Math.Ceiling(SupportFunctions.ConvertInUmeas(counterVal, currMaintenance.UnitOfMeasure.Value));
// Calc percentage = PLC - PERFORMED VALUE * 100 / interval
percentage = ((counterVal - perfVal) * 100) / SupportFunctions.ConvertInMinutes(currMaintenance.Interval.Value, currMaintenance.UnitOfMeasure.Value);
@@ -601,7 +601,7 @@ namespace Thermo.Active.NC
}
}
if(performed != null && performed.ControlWord == -2)
if (performed != null && performed.ControlWord == -2)
{
performed = null;
}
@@ -864,12 +864,84 @@ namespace Thermo.Active.NC
Id = head.Id,
Process = head.Process,
Type = configuredHead.Type.ToString(),
FixedHead = configuredHead.FixedHead,
FixedHead = configuredHead.FixedHead,
inWarning = head.Load_Abrasive >= configuredHead.WarningLimit,
inAlarm = head.Load_Abrasive >= configuredHead.AlarmLimit,
inAlarm = head.Load_Abrasive >= configuredHead.AlarmLimit,
OverrideEditable = head.OverrideEditable,
ActualSpeed = head.ActualSpeed_Pressure,
Load = head.Load_Abrasive,
Load = head.Load_Abrasive,
Override = head.Override,
IsActive = head.IsActive,
IsSelected = head.IsSelected,
AbrasiveIsActive = head.AbrasiveIsActive,
Configured = head.Configured,
Rotation = head.Rotation,
WorkedTime = head.WorkedTime
});
}
break;
case HEAD_TYPE.WJ:
{
heads.Add(new DTOWaterJet()
{
Id = head.Id,
Process = head.Process,
Type = configuredHead.Type.ToString(),
FixedHead = configuredHead.FixedHead,
inAlarm = false,
inWarning = false,
ActualPressure = head.ActualSpeed_Pressure,
OverrideEditable = head.OverrideEditable,
Override = head.Override,
IsActive = head.IsActive,
IsSelected = head.IsSelected,
AbrasiveIsActive = head.AbrasiveIsActive,
WorkedTime = head.WorkedTime
});
}
break;
}
}
return cmsError;
}
// !!!FARE!!! è copia delle heads
public CmsError GetRecipeData(out List<DTOHeadModel> heads)
{
// Returned value
heads = new List<DTOHeadModel>();
// Number of configured heads
int headsNumber = HeadsConfig.Count;
List<HeadDataModel> plcHeads = new List<HeadDataModel>();
// Read value from PLC
CmsError cmsError = numericalControl.PLC_RHeadsData(plcHeads, headsNumber);
if (cmsError.IsError())
return cmsError;
foreach (var head in plcHeads)
{
// Get current head config
var configuredHead = HeadsConfig.Find(x => x.Id == head.Id);
// Create different model according on type
switch (configuredHead.Type)
{
case HEAD_TYPE.SPINDLE:
{
heads.Add(new DTOSpindleModel()
{
Id = head.Id,
Process = head.Process,
Type = configuredHead.Type.ToString(),
FixedHead = configuredHead.FixedHead,
inWarning = head.Load_Abrasive >= configuredHead.WarningLimit,
inAlarm = head.Load_Abrasive >= configuredHead.AlarmLimit,
OverrideEditable = head.OverrideEditable,
ActualSpeed = head.ActualSpeed_Pressure,
Load = head.Load_Abrasive,
Override = head.Override,
IsActive = head.IsActive,
IsSelected = head.IsSelected,
@@ -924,7 +996,7 @@ namespace Thermo.Active.NC
Process = x.Process,
Type = x.Type.ToString(),
Value = x.Value
}).ToList();
}).ToList();
return NO_ERROR;
}
@@ -964,9 +1036,9 @@ namespace Thermo.Active.NC
scadas.Add(scadaValue);
// Add id to read scada
alreadyReadScada.Add(schema.Id);
}
}
}
return cmsError;
}
@@ -1014,7 +1086,7 @@ namespace Thermo.Active.NC
{
if (layer.Labels.ElementAtOrDefault(i) != null)
{
if(layer.Labels[i].MemEnabledIndex != null)
if (layer.Labels[i].MemEnabledIndex != null)
{
// Read enabled from PLC
cmsError = numericalControl.PLC_RScadaValue(layer.Labels[i].MemEnabledIndex, SCADA_MEM_TYPE.BOOL, ref val);
@@ -1044,7 +1116,7 @@ namespace Thermo.Active.NC
return cmsError;
// Populate & add new object into scada model
scadaValue.Buttons.Add(new DTOScadaButtonModel()
scadaValue.Buttons.Add(new DTOScadaButtonModel()
{
Id = layer.Buttons[i].Id,
IsEnabled = Convert.ToBoolean(val)
@@ -1065,7 +1137,7 @@ namespace Thermo.Active.NC
Id = layer.Images[i].Id,
IsVisible = negate ? !Convert.ToBoolean(val) : Convert.ToBoolean(val)
});
}
}
if (layer.ProgressBars.ElementAtOrDefault(i) != null)
{
@@ -1106,7 +1178,7 @@ namespace Thermo.Active.NC
{
IsEnabled = false, //Convert.ToBoolean(val),
Value = val2
}
}
});
}
else
@@ -1134,7 +1206,7 @@ namespace Thermo.Active.NC
});
}
}
}
}
@@ -1290,7 +1362,8 @@ namespace Thermo.Active.NC
Id = enabled.Id,
IsEnabled = Convert.ToBoolean(enabled.Value)
});
} break;
}
break;
case (int)SCADA_ELEMENT_TYPE.IMAGE:
case (int)SCADA_ELEMENT_TYPE.NEGATE_IMAGE:
{
@@ -1298,9 +1371,10 @@ namespace Thermo.Active.NC
scadaValue.Images.Add(new DTOScadaImageModel()
{
Id = enabled.Id,
IsVisible = enabled.ObjectType == (int)SCADA_ELEMENT_TYPE.NEGATE_IMAGE? !Convert.ToBoolean(enabled.Value) : Convert.ToBoolean(enabled.Value)
IsVisible = enabled.ObjectType == (int)SCADA_ELEMENT_TYPE.NEGATE_IMAGE ? !Convert.ToBoolean(enabled.Value) : Convert.ToBoolean(enabled.Value)
});
} break;
}
break;
case (int)SCADA_ELEMENT_TYPE.LABEL:
{
// Populate & add new object into scada model
@@ -1309,23 +1383,24 @@ namespace Thermo.Active.NC
Id = enabled.Id,
IsVisible = Convert.ToBoolean(enabled.Value)
});
} break;
}
}
break;
}
}
for (int i = 0; i < inputData.Count() - 1; i += 2)
{
var obj = inputData[i];
var enabled = inputData[i + 1];
// Populate & add new object into scada model
scadaValue.Inputs.Add(new DTOScadaInputModel()
{
Id = obj.Id,
Value = new DTOScadaValueModel()
{
IsEnabled = obj.Action.ToLower() == SCADA_ACTION.READ ? false : Convert.ToBoolean(enabled.Value),
Value = obj.Value
IsEnabled = obj.Action.ToLower() == SCADA_ACTION.READ ? false : Convert.ToBoolean(enabled.Value),
Value = obj.Value
}
});
}
@@ -1427,7 +1502,7 @@ namespace Thermo.Active.NC
{
// Choose which list contains the maximum number of elements
int max = layer.Buttons.Count();
if (layer.Labels.Count() > max)
max = layer.Labels.Count();
@@ -1458,11 +1533,11 @@ namespace Thermo.Active.NC
SupportFunctions.ConvertStringMachineNumberIntoNumber(strMachNumber, out bool containsLetters, out int machNumber);
// Read Data from NC & elaborate it
long NcCandy = 0;
long NcCandy = 0;
cmsError = numericalControl.PLC_RCandy(ref NcCandy);
if (cmsError.IsError())
return cmsError;
bool bNC_OK = CandiesController.GetDataFromLincense(NcCandy, containsLetters, out long NCLic, out int NCMatr, out long NCParam);
bool bNC_VALID = machNumber == NCMatr && bNC_OK;
@@ -1482,7 +1557,7 @@ namespace Thermo.Active.NC
return cmsError;
// Manage Expired Lincense Bit
if(CandiesController.ElaborateExpiredBit(newDate, bNcCandy, out bool bNewCandy))
if (CandiesController.ElaborateExpiredBit(newDate, bNcCandy, out bool bNewCandy))
{
//Write Expired Lincense Bit on NC
cmsError = numericalControl.PLC_WExpiredCandy(bNewCandy);
@@ -1493,14 +1568,14 @@ namespace Thermo.Active.NC
return NO_ERROR;
}
public void WriteCandy(DateTime value,int machNumber)
public void WriteCandy(DateTime value, int machNumber)
{
long nDays;
long Lic=0;
long Lic = 0;
nDays = (value.Ticks / TimeSpan.TicksPerDay);
//Imposto nel registro
CandiesController.SetPCLincense(machNumber,nDays);
CandiesController.SetPCLincense(machNumber, nDays);
//Imposto nel CN
Lic = long.Parse(CandiesController.SetLincenseFromData(machNumber, nDays));
@@ -102,6 +102,24 @@ namespace Thermo.Active.Controllers.WebApi
return Ok(heads);
}
[Route("recipe"), HttpGet]
public IHttpActionResult GetRecipeConfig()
{
List<DTORecipeConfigModel> recipe = RecipeConfig.Select(x => new DTORecipeConfigModel()
{
Id = x.Id,
Category = x.Category.ToString(),
SubCategory_1 = x.SubCategory_1,
SubCategory_2 = x.SubCategory_2,
Name = x.Name,
Description=x.Description,
Format=x.Format,
Label= $"{x.Category}_{x.SubCategory_1}_{x.SubCategory_2}_{x.Name}".Replace("__", "_").Replace("__", "_").ToLower()
}).ToList();
return Ok(recipe);
}
[Route("alarms"), HttpGet]
public IHttpActionResult GetAlarmsConfig()
{
@@ -114,6 +114,7 @@ namespace Thermo.Active.Controllers.WebApi
);
}
private static string GetValueFromLocalizationList(Dictionary<string, string> localizedNames, string language, string defaultString)
{
// Find text from names by language id
@@ -0,0 +1,36 @@
using CMS_CORE_Library.Models;
using Thermo.Active.Model.DTOModels;
using Thermo.Active.NC;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using static CMS_CORE_Library.Models.DataStructures;
using static Thermo.Active.Config.ServerConfig;
using static Thermo.Active.Model.Constants;
namespace Thermo.Active.Controllers.WebApi
{
[RoutePrefix("api/recipe")]
public class RecipeController : ApiController
{
[Route("overview"), HttpGet]
public IHttpActionResult GetRecipeOverview(string filePath = "")
{
using (NcFileAdapter ncAdapter = new NcFileAdapter())
{
ncAdapter.Connect();
CmsError cmsError = ncAdapter.GetFileList(filePath, out List<PreviewFileModel> fileList);
if (cmsError.IsError())
return BadRequest(cmsError.localizationKey);
return Ok(fileList);
}
}
}
}
+1
View File
@@ -218,6 +218,7 @@
<Compile Include="Attributes\SignalRAuthorizeAttribute.cs" />
<Compile Include="Controllers\SignalR\NcHub.cs" />
<Compile Include="Controllers\WebApi\ApiAlarmController.cs" />
<Compile Include="Controllers\WebApi\RecipeController.cs" />
<Compile Include="Controllers\WebApi\AuthorizationController.cs" />
<Compile Include="Controllers\WebApi\CmsConnectController.cs" />
<Compile Include="Controllers\WebApi\ConfigurationController.cs" />