Update metodi preliminari signal-r

This commit is contained in:
Samuele Locatelli
2020-05-19 16:23:10 +02:00
parent 63b09c1dfb
commit 95484c7ee7
11 changed files with 226 additions and 39 deletions
+52 -4
View File
@@ -377,6 +377,7 @@ public static class ThreadsFunctions
}
}
#if false
public static void ReadHeadsData()
{
NcAdapter ncAdapter = new NcAdapter();
@@ -419,7 +420,8 @@ public static class ThreadsFunctions
{
ncAdapter.Dispose();
}
}
}
#endif
public static void ReadAxesNamesData()
{
@@ -509,6 +511,7 @@ public static class ThreadsFunctions
}
}
#if false
public static void ReadActiveProgramData()
{
NcFileAdapter ncAdapter = new NcFileAdapter();
@@ -552,8 +555,10 @@ public static class ThreadsFunctions
{
ncAdapter.Dispose();
}
}
}
#endif
#if false
public static void ReadPartProgramQueueData()
{
NcFileAdapter ncAdapter = new NcFileAdapter();
@@ -599,7 +604,8 @@ public static class ThreadsFunctions
{
ncAdapter.Dispose();
}
}
}
#endif
public static void ReadScadaData()
{
@@ -645,7 +651,49 @@ public static class ThreadsFunctions
ncAdapter.Dispose();
}
}
public static void ReadGaugeData()
{
NcAdapter ncAdapter = new NcAdapter();
Stopwatch sw = new Stopwatch();
try
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
while (true)
{
sw.Restart();
// Check if client is connected
if (ncAdapter.numericalControl.NC_IsConnected())
{
// Get new data from PLC
libraryError = ncAdapter.ReadGaugeData(out ThermoModels.GaugeModel gaugeData);
if (libraryError.IsError())
ManageLibraryError(libraryError);
MessageServices.Current.Publish(SEND_THERMO_GAUGE_DATA, null, gaugeData);
}
else
RestoreConnection();
sw.Stop();
//Update thread timer
UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds);
// Wait
Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
{
ncAdapter.Dispose();
}
}
public static void ReadRecipeData()
{
NcAdapter ncAdapter = new NcAdapter();
@@ -687,7 +735,7 @@ public static class ThreadsFunctions
// Update thread timer
UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds);
// Wait
Thread.Sleep(CalcSleepTime(500, (int)sw.ElapsedMilliseconds));
Thread.Sleep(CalcSleepTime(250, (int)sw.ElapsedMilliseconds));
}
}
catch (ThreadAbortException)
+2 -1
View File
@@ -24,8 +24,9 @@ namespace Thermo.Active.Core
//ThreadsFunctions.ReadActiveProgramData,
//ThreadsFunctions.ReadPartProgramQueueData,
ThreadsFunctions.ReadScadaData,
ThreadsFunctions.ReadM154Data,
ThreadsFunctions.ReadM154Data, // levare?
// ThreadsFunctions.ReadNcSoftKeysData,
ThreadsFunctions.ReadGaugeData,
ThreadsFunctions.ReadRecipeData,
ThreadsFunctions.ReadWarmersData,
ThreadsFunctions.ReadModulesData
+1
View File
@@ -269,6 +269,7 @@ namespace Thermo.Active.Model
public const string SEND_THERMO_RECIPE_OVERWIEW = "SEND_THERMO_RECIPE_OVERWIEW";
public const string SEND_THERMO_MODULE_DATA = "SEND_THERMO_MODULE_DATA";
public const string SEND_THERMO_WARMERS_DATA = "SEND_THERMO_WARMERS_DATA";
public const string SEND_THERMO_GAUGE_DATA = "SEND_THERMO_GAUGE_DATA";
public const string BROADCAST_DATA = "BROADCAST_DATA";
@@ -0,0 +1,33 @@
using CMS_CORE_Library.Models;
using System.Linq;
using static CMS_CORE_Library.Models.DataStructures;
using static CMS_CORE_Library.Models.ThermoModels;
namespace Thermo.Active.Model.DTOModels
{
public class DTOGaugeDataModel : GaugeModel
{
public override bool Equals(object obj)
{
if (!(obj is DTOGaugeDataModel item))
return false;
if (TimeAdv != item.TimeAdv)
return false;
if (Power != item.Power)
return false;
if (Vacuum != item.Vacuum)
return false;
if (Air != item.Air)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
@@ -13,17 +13,77 @@ namespace Thermo.Active.Model.DTOModels.Recipe
public RPStatus Status { get; set; }
public string UnitMeasure { get; set; }
public double ValueAct { get; set; }
public override bool Equals(object obj)
{
if (!(obj is DTORecipeParam item))
return false;
if (Id!= item.Id)
return false;
if (!Range.Equals(item.Range))
return false;
if (!Status.Equals(item.Status))
return false;
if (UnitMeasure != item.UnitMeasure)
return false;
if (ValueAct != item.ValueAct)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public struct RPRange
{
public double Min { get; set; }
public double Max { get; set; }
public override bool Equals(object obj)
{
if (!(obj is RPRange item))
return false;
if (Min != item.Min)
return false;
if (Max != item.Max)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
public struct RPStatus
{
public bool Visible { get; set; }
public bool Enabled { get; set; }
public bool HasError { get; set; }
public override bool Equals(object obj)
{
if (!(obj is RPStatus item))
return false;
if (Visible != item.Visible)
return false;
if (Enabled != item.Enabled)
return false;
if (HasError != item.HasError)
return false;
return true;
}
public override int GetHashCode()
{
return base.GetHashCode();
}
}
}
@@ -95,6 +95,7 @@
<Compile Include="DatabaseModels\MachineUserModel.cs" />
<Compile Include="DatabaseModels\SessionModel.cs" />
<Compile Include="DTOModels\AlarmModels\DTONewAlarmNoteModel.cs" />
<Compile Include="DTOModels\DTOGaugeDataModel.cs" />
<Compile Include="DTOModels\DTOActiveProgramInfoModel.cs" />
<Compile Include="DTOModels\AlarmModels\DTOAlarmHistoricModel.cs" />
<Compile Include="DTOModels\AlarmModels\DTOAlarmsModel.cs" />
+12 -15
View File
@@ -33,7 +33,7 @@ namespace Thermo.Active.NC
/// </summary>
public bool simData = true;
public Nc numericalControl;
public NcThermo numericalControl;
public NcAdapter() =>
// Choose NC
@@ -59,23 +59,11 @@ namespace Thermo.Active.NC
return null;
}
public Nc SetNumericalControl()
public NcThermo SetNumericalControl()
{
// Return new Numerical control instance choosed from the configuration
switch (NcConfig.NcVendor)
{
case NC_VENDOR.DEMO:
return new Nc_Demo(NcConfig.NcIpAddress, NcConfig.NcPort);
case NC_VENDOR.FANUC:
return new Nc_Fanuc(NcConfig.NcIpAddress, NcConfig.NcPort, 2000);
case NC_VENDOR.SIEMENS:
return new Nc_Siemens(2000);
case NC_VENDOR.OSAI:
return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2000);
case NC_VENDOR.S7NET:
return new Nc_S7Net(NcConfig.NcIpAddress, NcConfig.NcPort, 2000);
}
@@ -1071,6 +1059,15 @@ namespace Thermo.Active.NC
return NO_ERROR;
}
public CmsError ReadGaugeData(out ThermoModels.GaugeModel gaugeData)
{
gaugeData = new ThermoModels.GaugeModel();
CmsError cmsError = numericalControl.PLC_RGaugeData(ref gaugeData);
return cmsError;
}
public CmsError ReadRecipeData(bool refreshOnlyRT, out Dictionary<string, DTORecipeParam> currentRecipe)
{
// init obj
@@ -1696,7 +1693,7 @@ namespace Thermo.Active.NC
public CmsError SetActiveScreen(short screen)
{
// Set to true power on data by id
return numericalControl.NC_SetScreenVisible((Nc.SCREEN_PAGE)screen);
return numericalControl.NC_SetScreenVisible((NcThermo.SCREEN_PAGE)screen);
}
public CmsError WriteM155Data(int process, double responseValue)
+16 -12
View File
@@ -20,7 +20,7 @@ namespace Thermo.Active.Utils
{
private static readonly string CMSCONNECT_TOKEN = "59f1qik5PYfiJLiXZ4xZ05pjzx5E9FscQWtj4lmfLKXaF1OAxkvu7ziBzXFBuuVQ";
public static SOFTKEY_TYPE GetSoftKeyType(string type)
public static SOFTKEY_TYPE GetSoftKeyType(string type)
{
switch (type)
{
@@ -42,8 +42,9 @@ namespace Thermo.Active.Utils
public static TACT_PARAM_TYPE GetTActCategory(string strCategory)
{
TACT_PARAM_TYPE answ = TACT_PARAM_TYPE.ND;
try {
TACT_PARAM_TYPE answ = TACT_PARAM_TYPE.ND;
try
{
answ = (TACT_PARAM_TYPE)Enum.Parse(typeof(TACT_PARAM_TYPE), strCategory);
}
catch { }
@@ -82,7 +83,7 @@ namespace Thermo.Active.Utils
case "xTen": return 26;
case "xHundred": return 27;
case "xThousand": return 28;
case "overstroke": return 30;
case "overstroke": return 30;
case "feedByPass": return 31;
default: return -1;
}
@@ -163,7 +164,7 @@ namespace Thermo.Active.Utils
List<short> listOfPossibleIds = Enumerable.Range(1, objIds.Max() + 1).Select(x => (short)x).ToList();
IEnumerable<short> res = listOfPossibleIds.Except(objIds).ToList();
IEnumerable<short> res = listOfPossibleIds.Except(objIds).ToList();
if (res.Count() > 0)
return res.First();
@@ -172,7 +173,7 @@ namespace Thermo.Active.Utils
}
public static string GetImageBase64String(string directoryPath, string imageName)
{
{
string fileName = Path.GetFileNameWithoutExtension(imageName);
foreach (string ext in VALID_IMAGE_EXTENSIONS)
{
@@ -209,7 +210,7 @@ namespace Thermo.Active.Utils
return null;
EmptyFolder(jobFolderPath);
using (ZipArchive zipExtractor = ZipFile.OpenRead(filePath))
{
// Setup main job fields
@@ -317,7 +318,7 @@ namespace Thermo.Active.Utils
string filePath = JOB_TMP_DIRECTORY + "\\" + processId + "\\";
if (!Directory.Exists(filePath))
return null;
// Setup main Fields
DTOJobModel jobData = new DTOJobModel()
{
@@ -382,7 +383,7 @@ namespace Thermo.Active.Utils
return SCADA_MEM_TYPE.WORD;
case "INT":
return SCADA_MEM_TYPE.INT;
return SCADA_MEM_TYPE.INT;
case "REAL":
return SCADA_MEM_TYPE.REAL;
@@ -417,7 +418,7 @@ namespace Thermo.Active.Utils
public static string GetSoftwareVersionAndBuildDate()
{
Version v = Assembly.GetEntryAssembly()?.GetName().Version;
Version v = Assembly.GetEntryAssembly()?.GetName().Version;
if (v != null)
{
// Get first 2 number of the version
@@ -434,7 +435,7 @@ namespace Thermo.Active.Utils
return "";
}
public static Boolean DecodeCMSConnectGatewayLogin(string encryptedString, out string login, out string password)
{
@@ -506,7 +507,10 @@ namespace Thermo.Active.Utils
{
intMachineVal = 0;
containsLetters = Regex.IsMatch(machineNumber, @".*?[a-zA-Z].*?");
if (string.IsNullOrEmpty(machineNumber))
{
machineNumber = "0000";
}
if (containsLetters)
// Convert ASCII string to a single INT
intMachineVal = SupportFunctions.ConvertAsciiStringToInt(machineNumber);
@@ -109,6 +109,10 @@ namespace Thermo.Active.Listeners
{
SignalRListener.SendThermoWarmersData(a);
}));
infos.Add(MessageServices.Current.Subscribe(SEND_THERMO_GAUGE_DATA, (a, b) =>
{
SignalRListener.SendThermoGaugeData(a);
}));
// Broadcast
@@ -15,6 +15,9 @@ using static Thermo.Active.Listeners.SignalRStaticObjects;
using static Thermo.Active.Model.Constants;
using static Thermo.Active.Config.ServerConfig;
using Thermo.Active.Model.DTOModels.Recipe;
using CMS_CORE_Library.Models;
using static CMS_CORE_Library.Models.ThermoModels;
using System.Threading.Tasks;
namespace Thermo.Active.Listeners.SignalR
{
@@ -247,21 +250,41 @@ namespace Thermo.Active.Listeners.SignalR
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
context.Clients.Group("ncData").scadaData(scadaVal);
}
}
}
public static void SendThermoRecipeFullData(object recipeFull)
{
Dictionary<string, DTORecipeParam> currRecipeFull = recipeFull as Dictionary<string, DTORecipeParam>;
// FIXME TODO: usare un foreach comparer?
if (!LastRecipeFullData.SequenceEqual(currRecipeFull))
Dictionary<string, DTORecipeParam> diffData = new Dictionary<string, DTORecipeParam>();
// calcola ed invia SOLO le differenze...
Parallel.ForEach(currRecipeFull, item =>
{
if (!LastRecipeFullData.ContainsKey(item.Key))
{
diffData.Add(item.Key, item.Value);
}
else
{
// comparazione
if (!item.Value.Equals(LastRecipeFullData[item.Key]))
{
diffData.Add(item.Key, item.Value);
}
}
});
if (diffData.Count > 0)
{
// salvo update
LastRecipeFullData = currRecipeFull;
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
context.Clients.Group("ncData").recipeFullData(currRecipeFull);
}
context.Clients.Group("ncData").recipeFullData(diffData);
//context.Clients.Group("ncData").recipeFullData(currRecipeFull);
}
}
public static void SendThermoRecipeOverviewData(object recipeOver)
@@ -287,7 +310,7 @@ namespace Thermo.Active.Listeners.SignalR
LastRecipeFullData = currModules;
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
context.Clients.Group("ncData").recipeModulesData(currModules);
context.Clients.Group("ncData").modulesData(currModules);
}
}
@@ -301,7 +324,20 @@ namespace Thermo.Active.Listeners.SignalR
LastRecipeFullData = currWarmers;
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
context.Clients.Group("ncData").recipeWarmersData(currWarmers);
context.Clients.Group("ncData").warmersData(currWarmers);
}
}
public static void SendThermoGaugeData(object gaugeData)
{
GaugeModel currGauge = gaugeData as GaugeModel;
// FIXME TODO: usare un foreach comparer?
if (!LastGaugeData.Equals(currGauge))
{
LastGaugeData = currGauge;
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
context.Clients.Group("ncData").gaugeData(currGauge);
}
}
@@ -3,6 +3,7 @@ using Thermo.Active.Model.DTOModels.AlarmModels;
using Thermo.Active.Model.DTOModels.Scada;
using System.Collections.Generic;
using Thermo.Active.Model.DTOModels.Recipe;
using CMS_CORE_Library.Models;
namespace Thermo.Active.Listeners
{
@@ -31,6 +32,7 @@ namespace Thermo.Active.Listeners
public static Dictionary<string, RecipeCatStatus> LastRecipeOverData = new Dictionary<string, RecipeCatStatus>();
public static List<DTOScadaModel> LastModulesData = new List<DTOScadaModel>();
public static List<DTOScadaModel> LastWarmersData = new List<DTOScadaModel>();
public static ThermoModels.GaugeModel LastGaugeData = new ThermoModels.GaugeModel();
public static bool LastIsNcConnected = false;