Prima vers signal-r x dati ChannelsIO
This commit is contained in:
@@ -119,6 +119,8 @@
|
||||
<sampling>
|
||||
<thread name="alarms" value="200" />
|
||||
<thread name="axis" value="200" />
|
||||
<thread name="channelsIoFast" value="300" />
|
||||
<thread name="channelsIoSlow" value="5000" />
|
||||
<thread name="area" value="500" />
|
||||
<thread name="confReq" value="2000" />
|
||||
<thread name="expMan" value="30000" />
|
||||
|
||||
@@ -30,6 +30,7 @@ using static Thermo.Active.Utils.ExceptionManager;
|
||||
using System.Windows;
|
||||
using System.Drawing;
|
||||
using System.Configuration;
|
||||
using Thermo.Active.Model.DTOModels.ThIO;
|
||||
|
||||
public static class ThreadsFunctions
|
||||
{
|
||||
@@ -412,6 +413,55 @@ public static class ThreadsFunctions
|
||||
ncAdapter.Dispose();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Lettura valorichannelsIO
|
||||
/// </summary>
|
||||
public static void ReadChannelsIoData()
|
||||
{
|
||||
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();
|
||||
|
||||
if (ncAdapter.numericalControl.NC_IsConnected())
|
||||
{
|
||||
// Get Data from config and PLC
|
||||
libraryError = ncAdapter.ReadValIO(out DTOChannelsIOVal currChannelsIoVal);
|
||||
if (libraryError.errorCode != 0)
|
||||
ManageLibraryError(libraryError);
|
||||
else
|
||||
// Send through signalR
|
||||
MessageServices.Current.Publish(SEND_CHANNELS_IO_DATA, null, currChannelsIoVal);
|
||||
}
|
||||
else
|
||||
RestoreConnection();
|
||||
|
||||
sw.Stop();
|
||||
|
||||
//Update thread timer
|
||||
UpdateStat(MethodBase.GetCurrentMethod().Name, sw.ElapsedMilliseconds);
|
||||
|
||||
// verifico se periodo rapido o veloce...
|
||||
int timerAct = RedisController.FastIoSample ? samplMsec("channelsIoFast") : samplMsec("channelsIoSlow");
|
||||
// Wait
|
||||
Thread.Sleep(CalcSleepTime(timerAct, (int)sw.ElapsedMilliseconds));
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException)
|
||||
{
|
||||
ncAdapter.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadEnabledFunctionality()
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Thermo.Active.Core
|
||||
ThreadsFunctions.ReadScadaData,
|
||||
ThreadsFunctions.ReadMComandsData,
|
||||
ThreadsFunctions.ReadAxisInfoData,
|
||||
ThreadsFunctions.ReadChannelsIoData,
|
||||
ThreadsFunctions.ReadM154Data // levare?
|
||||
|
||||
};
|
||||
|
||||
@@ -183,6 +183,32 @@ namespace Thermo.Active.Database.Controllers
|
||||
redUtil.man.ListPush(redisHash, msg);
|
||||
return true;
|
||||
}
|
||||
public static string ReadValue(string msgKey)
|
||||
{
|
||||
string redisHash = redUtil.man.redHash(msgKey);
|
||||
return redUtil.man.getRSV(redisHash);
|
||||
}
|
||||
public static bool WriteValue(string msgKey, string msg, int ttlSec)
|
||||
{
|
||||
string redisHash = redUtil.man.redHash(msgKey);
|
||||
redUtil.man.setRSV(redisHash, msg, ttlSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool FastIoSample
|
||||
{
|
||||
get
|
||||
{
|
||||
var currVal = ReadValue("FastIoSample");
|
||||
bool answ = !string.IsNullOrEmpty(currVal);
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
// imposta con TTL a 5 min
|
||||
WriteValue("FastIoSample", "Active", 60 * 5);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool WriteCurrentAxisStatus(Dictionary<int, DTOAxisInfoModel> axis)
|
||||
{
|
||||
|
||||
@@ -377,6 +377,7 @@ namespace Thermo.Active.Model
|
||||
public const string SEND_NC_SOFTKEYS_DATA = "SEND_NC_SOFTKEYS_DATA";
|
||||
public const string SEND_HEADS_DATA = "SEND_HEADS_DATA";
|
||||
public const string SEND_AXIS_INFO = "SEND_AXIS_INFO";
|
||||
public const string SEND_CHANNELS_IO_DATA = "SEND_CHANNELS_IO_DATA";
|
||||
public const string SEND_ACTIVE_PROGRAM_DATA = "SEND_ACTIVE_PROGRAM_DATA";
|
||||
public const string SEND_QUEUE_DATA = "SEND_QUEUE_DATA";
|
||||
public const string SEND_M155_DATA = "SEND_M155_DATA";
|
||||
|
||||
@@ -64,6 +64,10 @@ namespace Thermo.Active.Listeners
|
||||
{
|
||||
SignalRListener.SendThermoAxisInfoData(a);
|
||||
}));
|
||||
infos.Add(MessageServices.Current.Subscribe(SEND_CHANNELS_IO_DATA, (a, b) =>
|
||||
{
|
||||
SignalRListener.SendThermoChannelsIoData(a);
|
||||
}));
|
||||
infos.Add(MessageServices.Current.Subscribe(SEND_ACTIVE_PROGRAM_DATA, (a, b) =>
|
||||
{
|
||||
SignalRListener.SendActiveProgramData(a);
|
||||
|
||||
@@ -13,6 +13,7 @@ using Thermo.Active.Model.DTOModels;
|
||||
using Thermo.Active.Model.DTOModels.AlarmModels;
|
||||
using Thermo.Active.Model.DTOModels.Scada;
|
||||
using Thermo.Active.Model.DTOModels.ThAxes;
|
||||
using Thermo.Active.Model.DTOModels.ThIO;
|
||||
using Thermo.Active.Model.DTOModels.ThModules;
|
||||
using Thermo.Active.Model.DTOModels.ThProd;
|
||||
using Thermo.Active.Model.DTOModels.ThRecipe;
|
||||
@@ -59,7 +60,7 @@ namespace Thermo.Active.Listeners.SignalR
|
||||
{
|
||||
RedisController.WriteCurrentMachineEmergencyPath(LastPowerOnData.PrePowerOn.EmergencyButtons.Active);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,8 +457,8 @@ namespace Thermo.Active.Listeners.SignalR
|
||||
LastProdPanelData = currProdPanel;
|
||||
|
||||
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
|
||||
context.Clients.Group("ncData").prodPanelData(currProdPanel);
|
||||
|
||||
context.Clients.Group("ncData").prodPanelData(currProdPanel);
|
||||
|
||||
if (Config.ServerConfig.ServerStartupConfig.CmsConnectReady)
|
||||
{
|
||||
if (newPiece)
|
||||
@@ -508,8 +509,8 @@ namespace Thermo.Active.Listeners.SignalR
|
||||
RedisController.WriteCurrentMachineStatus(CMSConnectConstants.ConvertThermoToConnectStatus(currProdCycle.Status));
|
||||
RedisController.WriteCurrentMachinePowerPath(CMSConnectConstants.ConvertThermoToConnectPower(currProdCycle.Status));
|
||||
|
||||
RedisController.WriteCurrentProcessStatus(1,CMSConnectConstants.ConvertThermoToConnectProcessStatus(currProdCycle.Status));
|
||||
RedisController.WriteCurrentProcessMode(1,CMSConnectConstants.ConvertThermoToConnectProcessMode(currProdCycle.Mode));
|
||||
RedisController.WriteCurrentProcessStatus(1, CMSConnectConstants.ConvertThermoToConnectProcessStatus(currProdCycle.Status));
|
||||
RedisController.WriteCurrentProcessMode(1, CMSConnectConstants.ConvertThermoToConnectProcessMode(currProdCycle.Mode));
|
||||
|
||||
|
||||
}
|
||||
@@ -551,6 +552,65 @@ namespace Thermo.Active.Listeners.SignalR
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendThermoChannelsIoData(object channelsIoData)
|
||||
{
|
||||
DTOChannelsIOVal currChannelsIoData = channelsIoData as DTOChannelsIOVal;
|
||||
DTOChannelsIOVal diffChannelsData = new DTOChannelsIOVal();
|
||||
|
||||
// processing differenze DI
|
||||
foreach (var item in currChannelsIoData.DI)
|
||||
{
|
||||
// recupero
|
||||
var element = LastChannelsIoData.DI.Find(x => x.Id == item.Id);
|
||||
if ((element == null) || (!item.Value.Equals(element)))
|
||||
{
|
||||
diffChannelsData.DI.Add(item);
|
||||
}
|
||||
}
|
||||
// processing differenze DO
|
||||
foreach (var item in currChannelsIoData.DO)
|
||||
{
|
||||
// recupero
|
||||
var element = LastChannelsIoData.DO.Find(x => x.Id == item.Id);
|
||||
if ((element == null) || (!item.Value.Equals(element)))
|
||||
{
|
||||
diffChannelsData.DO.Add(item);
|
||||
}
|
||||
}
|
||||
// processing differenze AI
|
||||
foreach (var item in currChannelsIoData.AI)
|
||||
{
|
||||
// recupero
|
||||
var element = LastChannelsIoData.AI.Find(x => x.Id == item.Id);
|
||||
if ((element == null) || (!item.Value.Equals(element)))
|
||||
{
|
||||
diffChannelsData.AI.Add(item);
|
||||
}
|
||||
}
|
||||
// processing differenze AO
|
||||
foreach (var item in currChannelsIoData.AO)
|
||||
{
|
||||
// recupero
|
||||
var element = LastChannelsIoData.AO.Find(x => x.Id == item.Id);
|
||||
if ((element == null) || (!item.Value.Equals(element)))
|
||||
{
|
||||
diffChannelsData.AO.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// se ho differenze invio!
|
||||
if (diffChannelsData.DI.Count + diffChannelsData.DO.Count + diffChannelsData.AI.Count + diffChannelsData.AO.Count > 0)
|
||||
{
|
||||
// salvo update CLONANDO
|
||||
LastChannelsIoData.DI = currChannelsIoData.DI.Clone();
|
||||
LastChannelsIoData.DO = currChannelsIoData.DO.Clone();
|
||||
LastChannelsIoData.AI = currChannelsIoData.AI.Clone();
|
||||
LastChannelsIoData.AO = currChannelsIoData.AO.Clone();
|
||||
var context = GlobalHost.ConnectionManager.GetHubContext<NcHub>();
|
||||
context.Clients.Group("ncData").channelsIoVal(diffChannelsData);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetGatewayRebootStatus(object status)
|
||||
{
|
||||
string msg = status.ToString();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using CMS_CORE_Library.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Thermo.Active.Model.DTOModels;
|
||||
using Thermo.Active.Model.DTOModels.AlarmModels;
|
||||
using Thermo.Active.Model.DTOModels.Scada;
|
||||
using Thermo.Active.Model.DTOModels.ThAxes;
|
||||
using Thermo.Active.Model.DTOModels.ThIO;
|
||||
using Thermo.Active.Model.DTOModels.ThModules;
|
||||
using Thermo.Active.Model.DTOModels.ThProd;
|
||||
using Thermo.Active.Model.DTOModels.ThRecipe;
|
||||
@@ -46,6 +48,8 @@ namespace Thermo.Active.Listeners
|
||||
public static DTOThermoPanelProd LastProdPanelData = new DTOThermoPanelProd();
|
||||
// Oggetti per assi THERMO
|
||||
public static Dictionary<int, DTOAxisInfoModel> LastAxisInfoData = new Dictionary<int, DTOAxisInfoModel>();
|
||||
// Oggetti x Valori Channels IO
|
||||
public static DTOChannelsIOVal LastChannelsIoData = new DTOChannelsIOVal();
|
||||
|
||||
public static bool LastIsNcConnected = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user