fix api TCamData x range temp + dim immagine

This commit is contained in:
Samuele E. Locatelli
2021-02-18 18:23:50 +01:00
parent 1536042a38
commit 490c95ac9c
6 changed files with 490 additions and 423 deletions
+9 -1
View File
@@ -88,7 +88,7 @@
<entry>
<key>loaderSuckersNumber</key>
<value>12</value>
</entry>
</entry>
<entry>
<key>ThermoCameraXpos</key>
<value>93</value>
@@ -105,6 +105,14 @@
<key>ThermoCameraYdim</key>
<value>1004</value>
</entry>
<entry>
<key>RangeTempMin</key>
<value>0</value>
</entry>
<entry>
<key>RangeTempMax</key>
<value>100</value>
</entry>
</additionalParameters>
<unitOfMeasures>
<unitOfMeasure id="0" value="" />
+291 -362
View File
@@ -83,283 +83,6 @@ namespace Thermo.Active.Config
return xmlConfigFile;
}
private static void ReadDataModel()
{
XDocument xmlConfigFile = GetXmlHandler(CONNECT_DATAMODEL_CONFIG_PATH);
XElement el = xmlConfigFile.Descendants("Machine").First();
CMSConnectEntry = new Dictionary<string, string>();
ElaborateDataModel(el, el.Name.LocalName, ref CMSConnectEntry);
CMSConnectDataModel = File.ReadAllText(CONNECT_DATAMODEL_CONFIG_PATH);
}
private static void ReadM156()
{
// Get Areas file handler
XDocument xmlConfigFile = GetXmlHandlerWithValidator(M156_CONFIG_SCHEMA_PATH, M156_CONFIG_PATH);
InputsOperatorConfig = xmlConfigFile
.Descendants("inputsOperator")
.Elements()
.Select(x => new InputOperatorConfigModel()
{
Id = Convert.ToInt32(x.Element("id").Value),
Messages = x.Element("title").Elements().ToDictionary( // Read localized names and convert into a dictionary
y => y.Attribute("langKey").Value, y => y.Value
),
Buttons = x.Element("buttons")?.Elements().ToDictionary( // Read buttons data and convert into a dictionary
y => Convert.ToByte(y.Element("value").Value),
y => y.Element("title").Elements().ToDictionary( // Read localized names and convert into a dictionary
z => z.Attribute("langKey").Value,
z => z.Value
)
),
Type = GetInputOperatoType(x.Name.ToString())
})
.ToList();
}
private static void ReadScadaFile()
{
DirectoryInfo d = new DirectoryInfo(SCADA_DIRECTORY);
FileInfo[] files = d.GetFiles("*.xml");
int i = 1;
// Cycle inside xml files
foreach (var file in files)
{
validateScada(SCADA_PAGES_SCHEMA_PATH, SCADA_DIRECTORY + file.Name);
StreamReader sr = new StreamReader(SCADA_DIRECTORY + file.Name);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScadaSchemaModel));
ScadaSchemaModel schema = xmlSerializer.Deserialize(sr) as ScadaSchemaModel;
// Setup incremental ids
schema.Id = i++;
var name = Path.GetFileNameWithoutExtension(file.Name);
schema.BackgroundImage = GetImageBase64String(SCADA_DIRECTORY + name, schema.BackgroundImage);
schema.Layers = schema.Layers.Select(x => new ScadaSchemaLayerModel()
{
Id = i++,
Buttons = x.Buttons.Select(y => { y.Id = i++; return y; }).ToArray(),
Images = x.Images.Select(y =>
{
y.Id = i++;
y.Name = GetImageBase64String(SCADA_DIRECTORY + name, y.Name);
return y;
})
.ToArray(),
Labels = x.Labels.Select(y => { y.Id = i++; return y; }).ToArray(),
ProgressBars = x.ProgressBars.Select(y => { y.Id = i++; return y; }).ToArray(),
Inputs = x.Inputs.Select(y => { y.Id = i++; return y; }).ToArray()
})
.ToArray();
if (schema.IsInProductionPage == true)
ProductionScadaSchema.Add(schema);
else
ConfiguredScadaSchema.Add(schema);
}
}
private static void SetAreaValue(ref AreasConfigModel areasConfig, XElement element)
{
// Set area model with xml data
areasConfig = new AreasConfigModel()
{
Name = element.Name.ToString(),
Enabled = Convert.ToBoolean(element.Element("enabled").Value),
AllowExternalBrowser = Convert.ToBoolean(element.Element("allowExternalBrowser").Value),
NcNeeded = Convert.ToBoolean(element.Element("ncNeeded").Value)
};
}
private static void SetAreaValueByName(XElement element)
{
// Choose which area to be set
switch (element.Name.ToString())
{
case AREAS.PRODUCTION_KEY:
SetAreaValue(ref ProductionConfig, element);
break;
case AREAS.REPORT_KEY:
SetAreaValue(ref ReportConfig, element);
break;
case AREAS.ALARMS_KEY:
SetAreaValue(ref AlarmsConfig, element);
break;
case AREAS.MAINTENANCE_KEY:
SetAreaValue(ref MaintenanceConfig, element);
break;
case AREAS.UTILITIES_KEY:
SetAreaValue(ref UtilitiesConfig, element);
break;
case AREAS.SCADA_KEY:
SetAreaValue(ref ScadaConfig, element);
break;
case AREAS.JOBEDITOR_KEY:
SetAreaValue(ref JobEditorConfig, element);
break;
case AREAS.USERS_KEY:
SetAreaValue(ref UsersConfig, element);
break;
case AREAS.THERMO_HOOD_KEY:
SetAreaValue(ref ThermoHoodConfig, element);
break;
}
}
private static void validateScada(string configSchemaFilePath, string configFilePath)
{
// Create new instance
XmlSchemaSet readerSettings = new XmlSchemaSet();
// Add Schema from Assembly
Assembly myAssembly = Assembly.GetExecutingAssembly();
using (Stream schemaStream = myAssembly.GetManifestResourceStream(configSchemaFilePath))
{
using (XmlReader schemaReader = XmlReader.Create(schemaStream))
{
readerSettings.Add(null, schemaReader);
}
}
actualFileName = Path.GetFileName(configFilePath);
// Open file reader
XDocument xmlConfigFile = XDocument.Load(configFilePath);
// Validate file
xmlConfigFile.Validate(readerSettings, ValidationHandler);
}
private static void ValidationHandler(object sender, ValidationEventArgs e)
{
if (e.Severity == XmlSeverityType.Warning)
{
ExceptionManager.ManageError(ERROR_LEVEL.WARNING, e.Message, true);
}
else if (e.Severity == XmlSeverityType.Error)
{
ExceptionManager.ManageError(ERROR_LEVEL.FATAL,
// "Error while reading file: " + e.Exception.SourceUri +
"Error while reading XML file \"" + actualFileName + "\" \n\n" + e.Message,
true
);
}
}
#endregion Private Methods
#region Public Methods
public static bool CheckAreaStatus(string areaName)
{ // Get Area status ( enabled field) by name
switch (areaName)
{
case AREAS.PRODUCTION_KEY:
return ProductionConfig.Enabled;
case AREAS.REPORT_KEY:
return ProductionConfig.Enabled;
case AREAS.ALARMS_KEY:
return AlarmsConfig.Enabled;
case AREAS.MAINTENANCE_KEY:
return MaintenanceConfig.Enabled;
case AREAS.UTILITIES_KEY:
return UtilitiesConfig.Enabled;
case AREAS.SCADA_KEY:
return ScadaConfig.Enabled;
case AREAS.JOBEDITOR_KEY:
return ScadaConfig.Enabled;
case AREAS.GENERAL_KEY:
case AREAS.UNDER_HOOD:
return true;
default:
return false;
}
}
public static string GetInputOperatoType(string tagName)
{
switch (tagName)
{
case "modalValue":
return "REAL";
case "buttonsListModal":
return "MULTIPLE_BUTTONS";
case "showValModal":
return "SHOW_VAL";
case "simpleModal":
return "MODAL";
default:
return "REAL";
}
}
public static void ReadStartupConfig()
{
try
{
ReadServerConfig();
ReadAreaConfig();
ReadMaintenancesConfig();
ReadNcSoftKeys();
ReadUserSoftKeysConfig();
ReadAlarmsConfig();
ReadHeadsConfig();
ReadThermoProdConfig();
ReadRecipeConfig();
ReadModBlockConfig();
ReadIOConfig();
ReadRiskConfig();
ReadAxesConfig();
ReadCMSConnectConfig();
ReadMacros();
ReadScadaFile();
ReadM156();
ReadDataModel();
}
catch (XmlException ex)
{
ExceptionManager.ManageError(ERROR_LEVEL.FATAL,
"Error while reading file: " + ex.SourceUri +
"\n Error: " + ex.Message,
true
);
}
catch (Exception ex)
{
var message = ex.Message;
if (ex.InnerException != null)
message += "\n" + ex.InnerException.Message;
ExceptionManager.ManageError(ERROR_LEVEL.FATAL, message, true);
}
}
#endregion Public Methods
#region Read config from file from configuration
private static void ReadAlarmsConfig()
{
XDocument xmlConfigFile = GetXmlHandlerWithValidator(ALARMS_CONFIG_SCHEMA_PATH, ALARMS_CONFIG_PATH);
@@ -451,6 +174,15 @@ namespace Thermo.Active.Config
CmsConnectConfig.Gateway = tempGatewayConfigModel;
}
private static void ReadDataModel()
{
XDocument xmlConfigFile = GetXmlHandler(CONNECT_DATAMODEL_CONFIG_PATH);
XElement el = xmlConfigFile.Descendants("Machine").First();
CMSConnectEntry = new Dictionary<string, string>();
ElaborateDataModel(el, el.Name.LocalName, ref CMSConnectEntry);
CMSConnectDataModel = File.ReadAllText(CONNECT_DATAMODEL_CONFIG_PATH);
}
private static void ReadHeadsConfig()
{
XDocument xmlConfigFile = GetXmlHandlerWithValidator(HEADS_CONFIG_SCHEMA_PATH, HEADS_CONFIG_PATH);
@@ -474,6 +206,56 @@ namespace Thermo.Active.Config
.ToList();
}
/// <summary>
/// IO config setup from file
/// </summary>
private static void ReadIOConfig()
{
XDocument xmlConfigFile = GetXmlHandlerWithValidator(IO_CONFIG_SCHEMA_PATH, IO_CONFIG_PATH);
// Read head config from XML file
IOConfig = xmlConfigFile
.Root
.Elements()
.Select(x => new IOConfigModel()
{
Id = Convert.ToInt16(x.Element("id").Value),
Category = GetTActIO_Type(x.Element("category").Value),
Bank = x.Element("bank") != null ? x.Element("bank").Value : "0",
Position = x.Element("position") != null ? x.Element("position").Value : "0",
Page = x.Element("page") != null ? x.Element("page").Value : "",
Wire = x.Element("wire") != null ? x.Element("wire").Value : "",
Profinet = x.Element("profinet") != null ? x.Element("profinet").Value : "",
DisableForce = x.Element("disableForce") != null ? Convert.ToBoolean(x.Element("disableForce").Value) : false
})
.ToList();
}
private static void ReadM156()
{
// Get Areas file handler
XDocument xmlConfigFile = GetXmlHandlerWithValidator(M156_CONFIG_SCHEMA_PATH, M156_CONFIG_PATH);
InputsOperatorConfig = xmlConfigFile
.Descendants("inputsOperator")
.Elements()
.Select(x => new InputOperatorConfigModel()
{
Id = Convert.ToInt32(x.Element("id").Value),
Messages = x.Element("title").Elements().ToDictionary( // Read localized names and convert into a dictionary
y => y.Attribute("langKey").Value, y => y.Value
),
Buttons = x.Element("buttons")?.Elements().ToDictionary( // Read buttons data and convert into a dictionary
y => Convert.ToByte(y.Element("value").Value),
y => y.Element("title").Elements().ToDictionary( // Read localized names and convert into a dictionary
z => z.Attribute("langKey").Value,
z => z.Value
)
),
Type = GetInputOperatoType(x.Name.ToString())
})
.ToList();
}
/// <summary>
/// Module config setup from file
/// </summary>
@@ -504,30 +286,6 @@ namespace Thermo.Active.Config
.ToList();
}
/// <summary>
/// IO config setup from file
/// </summary>
private static void ReadIOConfig()
{
XDocument xmlConfigFile = GetXmlHandlerWithValidator(IO_CONFIG_SCHEMA_PATH, IO_CONFIG_PATH);
// Read head config from XML file
IOConfig = xmlConfigFile
.Root
.Elements()
.Select(x => new IOConfigModel()
{
Id = Convert.ToInt16(x.Element("id").Value),
Category = GetTActIO_Type(x.Element("category").Value),
Bank = x.Element("bank") != null ? x.Element("bank").Value : "0",
Position = x.Element("position") != null ? x.Element("position").Value : "0",
Page = x.Element("page") != null ? x.Element("page").Value : "",
Wire = x.Element("wire") != null ? x.Element("wire").Value : "",
Profinet = x.Element("profinet") != null ? x.Element("profinet").Value : "",
DisableForce = x.Element("disableForce") != null ? Convert.ToBoolean(x.Element("disableForce").Value): false
})
.ToList();
}
private static void ReadNcSoftKeys()
{
XDocument xmlConfigFile = GetXmlHandlerWithValidator(NC_SOFTKEYS_CONFIG_SCHEMA_PATH, NC_SOFTKEYS_CONFIG_PATH);
@@ -797,73 +555,51 @@ namespace Thermo.Active.Config
}
}
}
}
int zero = 0;
#if false
foreach (var currResist in listResist.OrderBy(x => x.Row).OrderBy(x => x.Column))
private static void ReadScadaFile()
{
DirectoryInfo d = new DirectoryInfo(SCADA_DIRECTORY);
FileInfo[] files = d.GetFiles("*.xml");
int i = 1;
// Cycle inside xml files
foreach (var file in files)
{
// se cambio riga --> mi metto a metà della prima cella
if (currResist.Row != currRow)
{
currX = (currResist.Dimension * resistSizeX) / 2;
currRow = currResist.Row;
}
else
{
// calcolo coordinata X CumSum
currX += (currResist.Dimension * resistSizeX);
}
//// reset distanza
//actDist = warmerPlanSizeX + warmerPlanSizeY;
//minDist = warmerPlanSizeX + warmerPlanSizeY;
validateScada(SCADA_PAGES_SCHEMA_PATH, SCADA_DIRECTORY + file.Name);
// tutti i calcoli in coordinate mm del riscaldo
punto = new ThermoPoint() { X = (int)currX, Y = currResist.Row * resistSizeY + resistSizeY / 2 };
puntoFlirImg = new ThermoPoint();
actDist = ThermoPoint.distance(punto, centro);
// cerco i dati del canale attuale...
var currChannel = RiskChannelConfig.FirstOrDefault(x => x.IdChannel == currResist.IdChannel);
if (currChannel.refPosDistance > actDist)
{
// riscalo il punto per la dimensione della FLIR
puntoFlirImg.X = punto.X * flirImgX / warmerPlanSizeX;
puntoFlirImg.Y = punto.Y * flirImgY / warmerPlanSizeY;
currChannel.refPos = puntoFlirImg;
currChannel.refPosDistance = actDist;
}
}
#endif
StreamReader sr = new StreamReader(SCADA_DIRECTORY + file.Name);
XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScadaSchemaModel));
ScadaSchemaModel schema = xmlSerializer.Deserialize(sr) as ScadaSchemaModel;
#if false
foreach (var currChannel in listChSup)
{
// reset distanza
actDist = warmerPlanSizeX + warmerPlanSizeY;
minDist = warmerPlanSizeX + warmerPlanSizeY;
// recupero resistenze
var currResist = RiskResistConfig.Where(x => x.IdChannel == currChannel.IdChannel);
// ciclo x trovare minimo
foreach (var resist in currResist)
// Setup incremental ids
schema.Id = i++;
var name = Path.GetFileNameWithoutExtension(file.Name);
schema.BackgroundImage = GetImageBase64String(SCADA_DIRECTORY + name, schema.BackgroundImage);
schema.Layers = schema.Layers.Select(x => new ScadaSchemaLayerModel()
{
// tutti i calcoli in coordinate mm del riscaldo
punto = new ThermoPoint() { X = resist.Column * resistSizeX + resistSizeX / 2, Y = resist.Row * resistSizeY + resistSizeY / 2 };
puntoFlirImg = new ThermoPoint();
actDist = ThermoPoint.distance(punto, centro);
if (actDist < minDist)
Id = i++,
Buttons = x.Buttons.Select(y => { y.Id = i++; return y; }).ToArray(),
Images = x.Images.Select(y =>
{
// riscalo il punto per la dimensione della FLIR
puntoFlirImg.X = punto.X * flirImgX / warmerPlanSizeX;
puntoFlirImg.Y = punto.Y * flirImgY / warmerPlanSizeY;
//// OLD coordinate in mm
//currChannel.refPos = punto;
// aggiorno conf channels con coord in punti FLIR
currChannel.refPos = puntoFlirImg;
// riporto minimo aggiornato
minDist = actDist;
}
}
y.Id = i++;
y.Name = GetImageBase64String(SCADA_DIRECTORY + name, y.Name);
return y;
})
.ToArray(),
Labels = x.Labels.Select(y => { y.Id = i++; return y; }).ToArray(),
ProgressBars = x.ProgressBars.Select(y => { y.Id = i++; return y; }).ToArray(),
Inputs = x.Inputs.Select(y => { y.Id = i++; return y; }).ToArray()
})
.ToArray();
if (schema.IsInProductionPage == true)
ProductionScadaSchema.Add(schema);
else
ConfiguredScadaSchema.Add(schema);
}
#endif
}
/// <summary>
@@ -929,6 +665,104 @@ namespace Thermo.Active.Config
.ToList();
}
private static void SetAreaValue(ref AreasConfigModel areasConfig, XElement element)
{
// Set area model with xml data
areasConfig = new AreasConfigModel()
{
Name = element.Name.ToString(),
Enabled = Convert.ToBoolean(element.Element("enabled").Value),
AllowExternalBrowser = Convert.ToBoolean(element.Element("allowExternalBrowser").Value),
NcNeeded = Convert.ToBoolean(element.Element("ncNeeded").Value)
};
}
private static void SetAreaValueByName(XElement element)
{
// Choose which area to be set
switch (element.Name.ToString())
{
case AREAS.PRODUCTION_KEY:
SetAreaValue(ref ProductionConfig, element);
break;
case AREAS.REPORT_KEY:
SetAreaValue(ref ReportConfig, element);
break;
case AREAS.ALARMS_KEY:
SetAreaValue(ref AlarmsConfig, element);
break;
case AREAS.MAINTENANCE_KEY:
SetAreaValue(ref MaintenanceConfig, element);
break;
case AREAS.UTILITIES_KEY:
SetAreaValue(ref UtilitiesConfig, element);
break;
case AREAS.SCADA_KEY:
SetAreaValue(ref ScadaConfig, element);
break;
case AREAS.JOBEDITOR_KEY:
SetAreaValue(ref JobEditorConfig, element);
break;
case AREAS.USERS_KEY:
SetAreaValue(ref UsersConfig, element);
break;
case AREAS.THERMO_HOOD_KEY:
SetAreaValue(ref ThermoHoodConfig, element);
break;
}
}
private static void validateScada(string configSchemaFilePath, string configFilePath)
{
// Create new instance
XmlSchemaSet readerSettings = new XmlSchemaSet();
// Add Schema from Assembly
Assembly myAssembly = Assembly.GetExecutingAssembly();
using (Stream schemaStream = myAssembly.GetManifestResourceStream(configSchemaFilePath))
{
using (XmlReader schemaReader = XmlReader.Create(schemaStream))
{
readerSettings.Add(null, schemaReader);
}
}
actualFileName = Path.GetFileName(configFilePath);
// Open file reader
XDocument xmlConfigFile = XDocument.Load(configFilePath);
// Validate file
xmlConfigFile.Validate(readerSettings, ValidationHandler);
}
private static void ValidationHandler(object sender, ValidationEventArgs e)
{
if (e.Severity == XmlSeverityType.Warning)
{
ExceptionManager.ManageError(ERROR_LEVEL.WARNING, e.Message, true);
}
else if (e.Severity == XmlSeverityType.Error)
{
ExceptionManager.ManageError(ERROR_LEVEL.FATAL,
// "Error while reading file: " + e.Exception.SourceUri +
"Error while reading XML file \"" + actualFileName + "\" \n\n" + e.Message,
true
);
}
}
#endregion Private Methods
#region Public Methods
public static string CalculateHash(string filename)
{
using (var sha = SHA1.Create())
@@ -941,6 +775,61 @@ namespace Thermo.Active.Config
}
}
public static bool CheckAreaStatus(string areaName)
{ // Get Area status ( enabled field) by name
switch (areaName)
{
case AREAS.PRODUCTION_KEY:
return ProductionConfig.Enabled;
case AREAS.REPORT_KEY:
return ProductionConfig.Enabled;
case AREAS.ALARMS_KEY:
return AlarmsConfig.Enabled;
case AREAS.MAINTENANCE_KEY:
return MaintenanceConfig.Enabled;
case AREAS.UTILITIES_KEY:
return UtilitiesConfig.Enabled;
case AREAS.SCADA_KEY:
return ScadaConfig.Enabled;
case AREAS.JOBEDITOR_KEY:
return ScadaConfig.Enabled;
case AREAS.GENERAL_KEY:
case AREAS.UNDER_HOOD:
return true;
default:
return false;
}
}
public static string GetInputOperatoType(string tagName)
{
switch (tagName)
{
case "modalValue":
return "REAL";
case "buttonsListModal":
return "MULTIPLE_BUTTONS";
case "showValModal":
return "SHOW_VAL";
case "simpleModal":
return "MODAL";
default:
return "REAL";
}
}
public static void ReadAssistanceConfig()
{
//Read Standard CMS Configuration
@@ -1181,6 +1070,46 @@ namespace Thermo.Active.Config
.ToDictionary(x => x.Key, x => x.Value);
}
#endregion Read config from file from configuration
public static void ReadStartupConfig()
{
try
{
ReadServerConfig();
ReadAreaConfig();
ReadMaintenancesConfig();
ReadNcSoftKeys();
ReadUserSoftKeysConfig();
ReadAlarmsConfig();
ReadHeadsConfig();
ReadThermoProdConfig();
ReadRecipeConfig();
ReadModBlockConfig();
ReadIOConfig();
ReadRiskConfig();
ReadAxesConfig();
ReadCMSConnectConfig();
ReadMacros();
ReadScadaFile();
ReadM156();
ReadDataModel();
}
catch (XmlException ex)
{
ExceptionManager.ManageError(ERROR_LEVEL.FATAL,
"Error while reading file: " + ex.SourceUri +
"\n Error: " + ex.Message,
true
);
}
catch (Exception ex)
{
var message = ex.Message;
if (ex.InnerException != null)
message += "\n" + ex.InnerException.Message;
ExceptionManager.ManageError(ERROR_LEVEL.FATAL, message, true);
}
}
#endregion Public Methods
}
}
@@ -10,6 +10,16 @@ namespace Thermo.Active.Model.DTOModels.ThWarmers
{
#region Public Properties
/// <summary>
/// Thermo Image Size
/// </summary>
public Size ImageSize { get; set; } = new Size();
/// <summary>
/// Thermo Temperature Range
/// </summary>
public RangeVal RangeTemperature { get; set; } = new RangeVal();
/// <summary>
/// Modalità ThermoCamera (set by HMI)
/// </summary>
@@ -45,6 +55,10 @@ namespace Thermo.Active.Model.DTOModels.ThWarmers
return false;
if (ThermoCamOnOff != item.ThermoCamOnOff)
return false;
if (ImageSize != item.ImageSize)
return false;
if (RangeTemperature != item.RangeTemperature)
return false;
return true;
}
@@ -60,4 +74,38 @@ namespace Thermo.Active.Model.DTOModels.ThWarmers
#endregion Public Methods
}
public class RangeVal
{
#region Public Properties
/// <summary>
/// VAlore MASSIMO
/// </summary>
public double Max { get; set; } = 50;
/// <summary>
/// Valore minimo
/// </summary>
public double Min { get; set; } = 0;
#endregion Public Properties
}
public class Size
{
#region Public Properties
/// <summary>
/// Dimensione X
/// </summary>
public int X { get; set; } = 100;
/// <summary>
/// Dimensione X
/// </summary>
public int Y { get; set; } = 100;
#endregion Public Properties
}
}
+19
View File
@@ -3117,6 +3117,25 @@ namespace Thermo.Active.NC
ThermoCamMode = currPlcTCamData.ThermoCamMode,
ThermoCamOnOff = currPlcTCamData.ThermoCamOnOff
};
// aggiungo dati da parametri addizionali...
int dimX = 100;
int dimY = 100;
int.TryParse(AdditionalParametersConfig["flirImgX"], out dimX);
int.TryParse(AdditionalParametersConfig["flirImgY"], out dimY);
currTCamData.ImageSize = new Size()
{
X = dimX,
Y = dimY
};
double minVal = 0;
double maxVal = 100;
double.TryParse(AdditionalParametersConfig["RangeTempMin"], out minVal);
double.TryParse(AdditionalParametersConfig["RangeTempMax"], out maxVal);
currTCamData.RangeTemperature = new RangeVal()
{
Min = minVal,
Max = maxVal
};
}
return libraryError;
}
+15
View File
@@ -46,6 +46,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client2020", "Client2020\Cl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thermo.Active.Thermocamera", "THermo.Active.Thermocamera\Thermo.Active.Thermocamera.csproj", "{8D8EC91A-3A15-4A1D-951B-A35E7068DEBD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thermo.Cam.Utils", "Thermo.Cam.Utils\Thermo.Cam.Utils.csproj", "{E4587942-498B-4AA7-9CC9-9304EB2D05C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -236,6 +238,18 @@ Global
{8D8EC91A-3A15-4A1D-951B-A35E7068DEBD}.Release|x64.Build.0 = Release|Any CPU
{8D8EC91A-3A15-4A1D-951B-A35E7068DEBD}.Release|x86.ActiveCfg = Release|Any CPU
{8D8EC91A-3A15-4A1D-951B-A35E7068DEBD}.Release|x86.Build.0 = Release|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Debug|x64.ActiveCfg = Debug|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Debug|x64.Build.0 = Debug|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Debug|x86.ActiveCfg = Debug|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Debug|x86.Build.0 = Debug|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Release|Any CPU.Build.0 = Release|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Release|x64.ActiveCfg = Release|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Release|x64.Build.0 = Release|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Release|x86.ActiveCfg = Release|Any CPU
{E4587942-498B-4AA7-9CC9-9304EB2D05C8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -255,6 +269,7 @@ Global
{49B04D99-0ECD-4900-86D3-7098D61314D7} = {0769EE3C-4259-4C72-97B4-0CCAEBFA7724}
{0780047F-12E4-4FCC-9748-6B23F0FD3711} = {2F873243-A483-40B6-A0F7-65FC3541A269}
{8D8EC91A-3A15-4A1D-951B-A35E7068DEBD} = {0769EE3C-4259-4C72-97B4-0CCAEBFA7724}
{E4587942-498B-4AA7-9CC9-9304EB2D05C8} = {0769EE3C-4259-4C72-97B4-0CCAEBFA7724}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {51D459FB-B45B-4A47-984E-46C35F933A82}
@@ -11,23 +11,83 @@ using Thermo.Active.Utils;
using static Thermo.Active.Config.ServerConfig;
using static Thermo.Active.Model.Constants;
using static CMS_CORE_Library.Models.DataStructures;
using System.Web.Http.Description;
namespace Thermo.Active.Controllers.WebApi
{
[RoutePrefix("api/warmers")]
public class WarmersController : ApiController
{
#region Fields
#region Protected Fields
/// <summary>
/// Oggetto adapter condiviso da WebAPI
/// </summary>
protected static NcAdapter ncAdapter = new NcAdapter();
#endregion Fields
#endregion Protected Fields
#region Methods
#region Private Methods
/// <summary>
/// Do actual recipe warmers SetpointHMI File-Save
/// </summary>
/// <param name="chSetpoints"></param>
private static void saveCurrentRecipeWarmersData(Dictionary<int, int> chSetpoints, Dictionary<int, double> chTCamTempReq, Dictionary<int, bool> chTCamEnab)
{
try
{
// ora salvo ANCHE i dati live...
NcAdapter.RecipeLiveData.ChannelSetpoints = chSetpoints;
NcAdapter.RecipeLiveData.ChannelTCamTempReq = chTCamTempReq;
NcAdapter.RecipeLiveData.ChannelTCamEnab = chTCamEnab;
// e salvo su disco
NcFileAdapter.SaveRecipeCurrent();
}
catch (Exception exc)
{
ThermoActiveLogger.LogError($"Warmers | saveCurrentRecipeWarmersData exception | {exc}");
}
notifyHmi();
}
#endregion Private Methods
#region Protected Methods
/// <summary>
/// Esegue notifica HMI delle modifiche sulla ricetta/riscaldi
/// </summary>
/// <returns></returns>
protected static CmsError notifyHmi()
{
CmsError libraryError = NO_ERROR;
// invio dati NUOVA ricetta (DOPO aver sistemato PLC)
DTORecipeStatus message = new DTORecipeStatus()
{
recipeName = NcAdapter.RecipeLiveData.RecipeName,
hasChanged = NcAdapter.RecipeLiveData.hasChanged,
forceSend = true
};
MessageServices.Current.Publish(SEND_THERMO_RECIPE_CHANGED, null, message);
// invio dati warmers aggiornati...
// Get new data from PLC
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Load error | ReadWarmers | {libraryError.errorCode} | {libraryError.exception} | {libraryError.localizationKey}");
return libraryError;
}
// pubblico
MessageServices.Current.Publish(SEND_THERMO_WARMERS_DATA, null, currWarmers);
return libraryError;
}
#endregion Protected Methods
#region Public Methods
/// <summary>
/// Cancel recipe modification (parameters: PLC --> HMI)
@@ -53,8 +113,6 @@ namespace Thermo.Active.Controllers.WebApi
return BadRequest(libraryError.localizationKey);
}
// recupero i dati LIVE dei parametri HMI dei riscaldi...
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
@@ -86,7 +144,7 @@ namespace Thermo.Active.Controllers.WebApi
// salvo!
saveCurrentRecipeWarmersData(currSetpointHMI, currTCamTempReq, currTCamEnab);
// ritorno solo fatto!
return Ok();
}
@@ -192,6 +250,7 @@ namespace Thermo.Active.Controllers.WebApi
/// Current status related to ThermoCamera
/// </summary>
/// <returns></returns>
[ResponseType(typeof(DTOThermoCam))]
[Route("TCamData"), HttpGet]
public IHttpActionResult GetCurrentTCamData()
{
@@ -237,6 +296,7 @@ namespace Thermo.Active.Controllers.WebApi
return Ok(currWarmers);
}
/// <summary>
/// Resistance setup info
/// </summary>
@@ -262,6 +322,46 @@ namespace Thermo.Active.Controllers.WebApi
return Ok(currWarmers);
}
[ResponseType(typeof(PointReq))]
[Route("getTemperatures"), HttpGet]
public IHttpActionResult GetTempAtPoints(PointReq pointRequest)
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"NC Not connected! | GetTempAtPoints | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
PointReq results = new PointReq();
// fake: genero casualmenteEsegui
Random rnd = new Random();
int numval = pointRequest != null && pointRequest.List != null && pointRequest.List.Count > 0 ? pointRequest.List.Count : 10;
for (int i = 0; i < numval; i++)
{
ThermoPointFlir newVal = new ThermoPointFlir()
{
X = rnd.Next(0, 1500),
Y = rnd.Next(0, 1200),
Temperature = ((float)rnd.Next(100, 2000)) / 10
};
results.List.Add(newVal);
}
#if false
// leggo dati gauges
libraryError = ncAdapter.ReadValIO(out DTOChannelsIOVal ChannelsIOVal);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetChannelsIoVal error | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
#endif
// ritorno!
return Ok(results);
}
/// <summary>
/// Force write risk setup + others warmers data (ex ThermoCam)
/// </summary>
@@ -399,7 +499,6 @@ namespace Thermo.Active.Controllers.WebApi
return BadRequest(libraryError.localizationKey);
}
// recupero valori attuali post update
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> newWarmers);
@@ -516,58 +615,7 @@ namespace Thermo.Active.Controllers.WebApi
return NotFound();
}
}
/// <summary>
/// Esegue notifica HMI delle modifiche sulla ricetta/riscaldi
/// </summary>
/// <returns></returns>
protected static CmsError notifyHmi()
{
CmsError libraryError = NO_ERROR;
// invio dati NUOVA ricetta (DOPO aver sistemato PLC)
DTORecipeStatus message = new DTORecipeStatus()
{
recipeName = NcAdapter.RecipeLiveData.RecipeName,
hasChanged = NcAdapter.RecipeLiveData.hasChanged,
forceSend = true
};
MessageServices.Current.Publish(SEND_THERMO_RECIPE_CHANGED, null, message);
// invio dati warmers aggiornati...
// Get new data from PLC
libraryError = ncAdapter.ReadWarmers(false, out Dictionary<int, DTOWarmers> currWarmers);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"Load error | ReadWarmers | {libraryError.errorCode} | {libraryError.exception} | {libraryError.localizationKey}");
return libraryError;
}
// pubblico
MessageServices.Current.Publish(SEND_THERMO_WARMERS_DATA, null, currWarmers);
return libraryError;
}
/// <summary>
/// Do actual recipe warmers SetpointHMI File-Save
/// </summary>
/// <param name="chSetpoints"></param>
private static void saveCurrentRecipeWarmersData(Dictionary<int, int> chSetpoints, Dictionary<int, double> chTCamTempReq, Dictionary<int, bool> chTCamEnab)
{
try
{
// ora salvo ANCHE i dati live...
NcAdapter.RecipeLiveData.ChannelSetpoints = chSetpoints;
NcAdapter.RecipeLiveData.ChannelTCamTempReq = chTCamTempReq;
NcAdapter.RecipeLiveData.ChannelTCamEnab = chTCamEnab;
// e salvo su disco
NcFileAdapter.SaveRecipeCurrent();
}
catch (Exception exc)
{
ThermoActiveLogger.LogError($"Warmers | saveCurrentRecipeWarmersData exception | {exc}");
}
notifyHmi();
}
#endregion Methods
#endregion Public Methods
}
}