Update x gestione (sim) della termocam su richiesta PLC
This commit is contained in:
@@ -45,5 +45,11 @@
|
||||
<Compile Include="ThermocameraComunicator.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Thermo.Active.Model\Thermo.Active.Model.csproj">
|
||||
<Project>{631375DD-06D3-49BB-8130-D9DDB34C429D}</Project>
|
||||
<Name>Thermo.Active.Model</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -10,6 +10,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using Thermo.Active.Model.DTOModels.ThWarmers;
|
||||
|
||||
namespace Thermo.Active.Thermocamera
|
||||
{
|
||||
@@ -130,13 +131,13 @@ namespace Thermo.Active.Thermocamera
|
||||
/// <summary>
|
||||
/// Restituisce lettura di tutti i punti (cetroidi) richeisti
|
||||
/// </summary>
|
||||
/// <param name="points">Lista di punti medi (prima resistenza del canale)</param>
|
||||
/// <param name="points">Dictionary dei canali e relativi punti medi (centro calcolato della resistenza di riferimento del canale)</param>
|
||||
/// <param name="timeoutMS">Timeout in ms, 10000 std, da conf</param>
|
||||
/// <param name="temp">°C</param>
|
||||
/// <returns></returns>
|
||||
public bool readMultiTemperatures(IEnumerable<Point> points, int timeoutMS, out List<float> temp)
|
||||
public bool readMultiTemperatures(Dictionary<int, ThermoPoint> points, int timeoutMS, out Dictionary<int, double> temp)
|
||||
{
|
||||
temp = new List<float>();
|
||||
temp = new Dictionary<int, double>();
|
||||
// modalità impiego vero sw esterno
|
||||
if (useTCamSw)
|
||||
{
|
||||
@@ -144,9 +145,9 @@ namespace Thermo.Active.Thermocamera
|
||||
string response;
|
||||
|
||||
string cmdRead = "";
|
||||
foreach (Point point in points)
|
||||
foreach (var point in points)
|
||||
{
|
||||
cmdRead += point.X + ";" + point.Y + ";";
|
||||
cmdRead += point.Value.X + ";" + point.Value.Y + ";";
|
||||
}
|
||||
|
||||
if (!writeCommand(accessor, tempCommand + ";" + cmdRead))
|
||||
@@ -155,24 +156,27 @@ namespace Thermo.Active.Thermocamera
|
||||
return false;
|
||||
|
||||
string[] respSplitted = response.Split(';');
|
||||
foreach (string str in respSplitted)
|
||||
int idxResp = 0;
|
||||
foreach (var item in points)
|
||||
{
|
||||
float tmp;
|
||||
string str = respSplitted[idxResp];
|
||||
double tmp;
|
||||
if (str.Trim() != "")
|
||||
{
|
||||
if (float.TryParse(str.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
|
||||
temp.Add(tmp);
|
||||
if (double.TryParse(str.Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out tmp))
|
||||
temp.Add(item.Key, tmp);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
idxResp++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// simulo!
|
||||
for (int i = 0; i < points.Count(); i++)
|
||||
foreach (var item in points)
|
||||
{
|
||||
temp.Add(simVal);
|
||||
temp.Add(item.Key, simVal);
|
||||
}
|
||||
// attende 5 sec
|
||||
Thread.Sleep(5000);
|
||||
|
||||
@@ -121,6 +121,7 @@
|
||||
<thread name="recipe" value="400" />
|
||||
<thread name="scada" value="1000" />
|
||||
<thread name="statusCommand" value="250" />
|
||||
<thread name="FlirCamera" value="500" />
|
||||
<thread name="userSK" value="250" />
|
||||
<thread name="warmers" value="500" />
|
||||
<thread name="watchdog" value="250" />
|
||||
|
||||
@@ -913,14 +913,14 @@ namespace Thermo.Active.Config
|
||||
}
|
||||
|
||||
// recupero parametri plate e dim resistenze
|
||||
double warmerPlanSizeX = 0;
|
||||
double warmerPlanSizeY = 0;
|
||||
double resistSizeX = 0;
|
||||
double resistSizeY = 0;
|
||||
double.TryParse(AdditionalParametersConfig["warmerPlanSizeX"], out warmerPlanSizeX);
|
||||
double.TryParse(AdditionalParametersConfig["warmerPlanSizeY"], out warmerPlanSizeY);
|
||||
double.TryParse(AdditionalParametersConfig["resistSizeX"], out resistSizeX);
|
||||
double.TryParse(AdditionalParametersConfig["resistSizeY"], out resistSizeY);
|
||||
int warmerPlanSizeX = 0;
|
||||
int warmerPlanSizeY = 0;
|
||||
int resistSizeX = 0;
|
||||
int resistSizeY = 0;
|
||||
int.TryParse(AdditionalParametersConfig["warmerPlanSizeX"], out warmerPlanSizeX);
|
||||
int.TryParse(AdditionalParametersConfig["warmerPlanSizeY"], out warmerPlanSizeY);
|
||||
int.TryParse(AdditionalParametersConfig["resistSizeX"], out resistSizeX);
|
||||
int.TryParse(AdditionalParametersConfig["resistSizeY"], out resistSizeY);
|
||||
// calcolo punti!
|
||||
ThermoPoint centro = new ThermoPoint() { X = warmerPlanSizeX / 2, Y = warmerPlanSizeY / 2 };
|
||||
ThermoPoint punto = new ThermoPoint();
|
||||
|
||||
@@ -80,6 +80,10 @@
|
||||
<Project>{b2366b08-96bd-4f6b-b748-b45089b87a14}</Project>
|
||||
<Name>Thermo.Active.NC</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\THermo.Active.Thermocamera\Thermo.Active.Thermocamera.csproj">
|
||||
<Project>{8D8EC91A-3A15-4A1D-951B-A35E7068DEBD}</Project>
|
||||
<Name>Thermo.Active.Thermocamera</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Thermo.Active.Utils\Thermo.Active.Utils.csproj">
|
||||
<Project>{cbeb631b-abfa-4042-9779-c0060b0dfefe}</Project>
|
||||
<Name>Thermo.Active.Utils</Name>
|
||||
|
||||
@@ -21,11 +21,14 @@ using Thermo.Active.Model.DTOModels.ThProd;
|
||||
using Thermo.Active.Model.DTOModels.ThRecipe;
|
||||
using Thermo.Active.Model.DTOModels.ThWarmers;
|
||||
using Thermo.Active.NC;
|
||||
using Thermo.Active.Thermocamera;
|
||||
using Thermo.Active.Utils;
|
||||
using static CMS_CORE_Library.Models.DataStructures;
|
||||
using static Thermo.Active.Config.ServerConfig;
|
||||
using static Thermo.Active.Model.Constants;
|
||||
using static Thermo.Active.Utils.ExceptionManager;
|
||||
using System.Windows;
|
||||
using System.Drawing;
|
||||
|
||||
public static class ThreadsFunctions
|
||||
{
|
||||
@@ -840,6 +843,79 @@ public static class ThreadsFunctions
|
||||
ncAdapter.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Manage Requesto from PLC for FLir Image --> temp readout
|
||||
/// 1) check if pending request
|
||||
/// 2) give ack
|
||||
/// 3) request image to ext sw
|
||||
/// 4) request temp sampling from ext sw
|
||||
///
|
||||
/// </summary>
|
||||
public static void ManageFlirCamera()
|
||||
{
|
||||
NcAdapter ncAdapter = new NcAdapter();
|
||||
Stopwatch sw = new Stopwatch();
|
||||
try
|
||||
{
|
||||
// Try connection
|
||||
CmsError libraryError = ncAdapter.Connect();
|
||||
if (libraryError.errorCode != 0)
|
||||
ManageLibraryError(libraryError);
|
||||
|
||||
while (true)
|
||||
{
|
||||
bool flirImageReq = false;
|
||||
sw.Restart();
|
||||
int tOut = 10000;
|
||||
|
||||
// Check if client is connected
|
||||
if (ncAdapter.numericalControl.NC_IsConnected())
|
||||
{
|
||||
// check if there is a photo request pending
|
||||
libraryError = ncAdapter.checkFlirImageRequest(out flirImageReq);
|
||||
if (libraryError.IsError())
|
||||
ManageLibraryError(libraryError);
|
||||
|
||||
if (flirImageReq)
|
||||
{
|
||||
bool done = false;
|
||||
// if requested --> give ack!
|
||||
ncAdapter.ManageFlirStrobe();
|
||||
// requesto photo from library
|
||||
done = ThermocameraComunicator.getInstance().takePicture(tOut);
|
||||
if (done)
|
||||
{
|
||||
// init
|
||||
Dictionary<int, double> actualTemp = new Dictionary<int, double>();
|
||||
Dictionary<int, ThermoPoint> chPoints = new Dictionary<int, ThermoPoint>();
|
||||
// recupero punti centrali resistenze
|
||||
ncAdapter.GetWarmersChannelCenterPoints(out chPoints);
|
||||
// richiesta temperature per i punti
|
||||
done = ThermocameraComunicator.getInstance().readMultiTemperatures(chPoints, tOut, out actualTemp);
|
||||
// salvo dati temp sul PLC
|
||||
ncAdapter.WriteRecipeWarmChTCamTempAct(actualTemp);
|
||||
// give PLC strobe for uploaded Actual TEMP from image
|
||||
ncAdapter.SendTCamImageReadyStrb();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
RestoreConnection();
|
||||
|
||||
sw.Stop();
|
||||
|
||||
// Update thread timer
|
||||
UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds);
|
||||
// Wait
|
||||
Thread.Sleep(CalcSleepTime(samplMsec("FlirCamera"), (int)sw.ElapsedMilliseconds));
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ncAdapter.Dispose();
|
||||
}
|
||||
}
|
||||
public static void ReadAreaData()
|
||||
{
|
||||
NcAdapter ncAdapter = new NcAdapter();
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Thermo.Active.Core
|
||||
ThreadsFunctions.ManageWatchdog,
|
||||
ThreadsFunctions.ManageStatusCommand,
|
||||
ThreadsFunctions.ManageConfRequest,
|
||||
ThreadsFunctions.ManageFlirCamera,
|
||||
ThreadsFunctions.ReadAlarms,
|
||||
ThreadsFunctions.ReadPowerOnData,
|
||||
ThreadsFunctions.StatThread,
|
||||
|
||||
@@ -8,13 +8,13 @@ namespace Thermo.Active.Model.DTOModels.ThWarmers
|
||||
{
|
||||
public class ThermoPoint
|
||||
{
|
||||
public double X { get; set; } = 0;
|
||||
public double Y { get; set; } = 0;
|
||||
public int X { get; set; } = 0;
|
||||
public int Y { get; set; } = 0;
|
||||
|
||||
public static double distance(ThermoPoint a, ThermoPoint b)
|
||||
public static int distance(ThermoPoint a, ThermoPoint b)
|
||||
{
|
||||
double answ = 0;
|
||||
answ = Math.Sqrt(Math.Pow((a.X - b.X), 2) + Math.Pow((a.Y - b.Y), 2));
|
||||
int answ = 0;
|
||||
answ = (int)Math.Sqrt(Math.Pow((a.X - b.X), 2) + Math.Pow((a.Y - b.Y), 2));
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,6 +305,26 @@ namespace Thermo.Active.NC
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
private static bool ThermoFlirImageReq
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
if (statusCmd != null)
|
||||
{
|
||||
if (statusCmd.Count > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
answ = checkBitOnWord(statusCmd[0], 12);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1331,6 +1351,11 @@ namespace Thermo.Active.NC
|
||||
setpointHmiInvalidated = ThermoSetpointHmiInvalidated;
|
||||
return NO_ERROR;
|
||||
}
|
||||
public CmsError checkFlirImageRequest(out bool flirImageRequest)
|
||||
{
|
||||
flirImageRequest = ThermoCameraReqImage;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
public CmsError doAckSetpointInvalidated()
|
||||
{
|
||||
@@ -2765,6 +2790,19 @@ namespace Thermo.Active.NC
|
||||
return libraryError;
|
||||
}
|
||||
|
||||
public CmsError GetWarmersChannelCenterPoints(out Dictionary<int, ThermoPoint> centerPoints)
|
||||
{
|
||||
CmsError libraryError = NO_ERROR;
|
||||
centerPoints = new Dictionary<int, ThermoPoint>();
|
||||
var upperReflectors = RiskChannelConfig.Where(x => x.IdReflector == 0);
|
||||
foreach (var item in upperReflectors)
|
||||
{
|
||||
centerPoints.Add(item.IdChannel, item.refPos);
|
||||
}
|
||||
// chiude!
|
||||
return libraryError;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns resistances configuration
|
||||
/// </summary>
|
||||
@@ -3046,6 +3084,16 @@ namespace Thermo.Active.NC
|
||||
return numericalControl.PLC_WScadaValue(memIndex, memType, value);
|
||||
}
|
||||
|
||||
public CmsError ManageFlirStrobe()
|
||||
{
|
||||
return numericalControl.PLC_WStrFlirAcquired();
|
||||
}
|
||||
public CmsError SendTCamImageReadyStrb()
|
||||
{
|
||||
// FIXME TODO !!!
|
||||
return NO_ERROR;// numericalControl.PLC_WStrFlirAcquired();
|
||||
}
|
||||
|
||||
#endregion Write data
|
||||
|
||||
private int GetMaxCountBetweenLayerComponents(ScadaSchemaLayerModel layer)
|
||||
|
||||
@@ -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.108.136")]
|
||||
[assembly: AssemblyVersion("0.109.137")]
|
||||
Reference in New Issue
Block a user