160 lines
5.0 KiB
C#
160 lines
5.0 KiB
C#
using Flir.Atlas.Live.Device;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Thermo.Active.Model;
|
|
using Thermo.Active.Model.DTOModels.ThWarmers;
|
|
using Thermo.Cam.Utils;
|
|
|
|
namespace Thermo.Active.Thermocamera
|
|
{
|
|
public class ThermoCamComunicator
|
|
{
|
|
#region Protected Fields
|
|
|
|
/// <summary>
|
|
/// Classe gestione ThermoCam (oggetti Image, metodi processing...)
|
|
/// </summary>
|
|
protected TCContr TCamLive = new TCContr(BASE_PATH, BASE_PATH);
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Public Fields
|
|
|
|
public static readonly string BASE_PATH = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
|
|
|
/// <summary>
|
|
/// Indica se la camera sia connessa
|
|
/// </summary>
|
|
public bool CameraIsConnected = false;
|
|
|
|
#endregion Public Fields
|
|
|
|
#region Public Constructors
|
|
|
|
/// <summary>
|
|
/// Init classe
|
|
/// </summary>
|
|
/// <param name="isLive">Indica aabilitazione a live straming vs load dati storici</param>
|
|
public ThermoCamComunicator(bool isLive)
|
|
{
|
|
// init classe controllo camera
|
|
TCamLive = new TCContr($"{Constants.WEBSITE_DIRECTORY}\\{Constants.THERMO_DATA_FOLDER}", $"{BASE_PATH}\\{Constants.CONFIG_DIRECTORY}");
|
|
|
|
// aggancio evento connesisone/disconnessione
|
|
TCamLive.eh_CameraConnStatusChanged += TCamLive_eh_CameraConnStatusChanged;
|
|
|
|
// avvio classe gestione thermocamera...
|
|
TCamLive.tryReloadConf();
|
|
|
|
if (isLive)
|
|
{
|
|
// SOLO PER IL LIVE --> cerco camera
|
|
TCamLive.discoveryCamera();
|
|
}
|
|
}
|
|
|
|
private void TCamLive_eh_CameraConnStatusChanged(object sender, Flir.Atlas.Live.ConnectionStatusChangedEventArgs e)
|
|
{
|
|
// salvo stato connessione
|
|
CameraIsConnected = e.Status == ConnectionStatus.Connected;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Protected Methods
|
|
|
|
/// <summary>
|
|
/// Rilettura da file di tutti i dati
|
|
/// </summary>
|
|
/// <param name="fileName">Nome set file (originale + colorized + dati temperatura)</param>
|
|
/// <returns></returns>
|
|
protected bool loadData(string fileName)
|
|
{
|
|
bool done = false;
|
|
try
|
|
{
|
|
done = TCamLive.fileLoad(fileName);
|
|
}
|
|
catch
|
|
{ }
|
|
return done;
|
|
}
|
|
|
|
#endregion Protected Methods
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// chiusura metodi legati a ThermoCam (discovery e connessione)
|
|
/// </summary>
|
|
public void Dispose()
|
|
{
|
|
TCamLive.stopDiscovery();
|
|
TCamLive.DisconnectCamera();
|
|
TCamLive.DisposeCamera();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Restituisce lettura di tutti i punti richiesti (es centroidi riscaldi)
|
|
/// </summary>
|
|
/// <param name="setName">Nome dei dati da leggere, se "" --> live</param>
|
|
/// <param name="points">Dictionary id richiesta + punto (es canali + relativi punti medi come centro calcolato della resistenza di riferimento del canale)</param>
|
|
/// <param name="temp">Dizionario temperature come id + valore double in °C</param>
|
|
/// <returns></returns>
|
|
public bool readMultiTemperatures(string setName, Dictionary<int, ThermoPoint> points, out List<MeasurePoint> temp)
|
|
{
|
|
temp = new List<MeasurePoint>();
|
|
// converto la richiesta in una lista di punti di misura...
|
|
List<MeasurePoint> reqData = points.Select(item => new MeasurePoint()
|
|
{
|
|
Id = item.Key,
|
|
Coords = new System.Drawing.Point(item.Value.X, item.Value.Y),
|
|
Temperature = 0
|
|
}).ToList();
|
|
bool done = false;
|
|
if (string.IsNullOrEmpty(setName) || setName == "_live")
|
|
{
|
|
done = true;
|
|
}
|
|
else
|
|
{
|
|
// carico file vari...
|
|
done = TCamLive.fileLoad(setName);
|
|
}
|
|
try
|
|
{
|
|
temp = TCamLive.getPointsTemperature(false, reqData);
|
|
}
|
|
catch
|
|
{ }
|
|
// fatto!
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Richiesta di acquisizione immagine FLIR (restituisce nome con cui sono stati salvati file)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string takePicture()
|
|
{
|
|
string imgName = "";
|
|
try
|
|
{
|
|
// effettua chiamata x scattare immagine e SALVARE
|
|
TCamLive.takePicture();
|
|
TCamLive.calculateTarget();
|
|
imgName = TCamLive.fileSave();
|
|
}
|
|
catch
|
|
{ }
|
|
return imgName;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
}
|
|
} |