Files
Mapo-IOB-WIN/IOB-WIN-NEXT/IobSiemens/SiemensNWSE.cs
T
Samuele Locatelli 8bb0f158b5 SPLIT PROGETTO!!!
- proj di base con le 2 form da ereditare
- progetto globale che contiene TUTTI gli adapter (pronto a venire spezzettato
- gettate le basi x "portare fuori" i vari componenti oppure fare compilazione condizonale
2024-12-20 10:16:32 +01:00

221 lines
8.3 KiB
C#

using IOB_UT_NEXT;
using MapoSDK;
using System;
using System.Collections.Generic;
using System.Threading;
namespace IOB_WIN_NEXT.IobSiemens
{
/// <summary>
/// Controllo Siemens specifico x impianti RobotSerice (es Smerigliature DONATI)
/// </summary>
public class SiemensNWSE : Siemens
{
/* --------------------------------------------------------------------------------
* Controlli SIEMENS NWS
* - basasto su SIEMENS
* - S7 vers 1200
*
* STRUTTURA MEMORIA DB100: (lettura) 50byte,
* G:\Drive condivisi\30_Clienti\Giacovelli - WIL\NWS
*
*
* DB100
* B00..B15 --> 16 byte di allarmi (osmosi, depurazione, 6 x filtri)
* B20..B35 --> 16 byte di stati (osmosi, depurazione, 6 x filtri)
* B40..B49 --> 5 valori uint lettura parametri
*
*
*
* STRUTTURA MEMORIA DB101: (scrittura) 14byte, solo 2 impiegati x ora
* NB: segnali da tenere attivi ALMENO 3 secondi x farli recepire
*
* B0.0 Num Azzeramento volume acqua OSMOSI
* B0.1 Num Azzeramento volume acqua DEPURAZIONE
*
* B1.7 Num Attivazione modo DEMO (0 = disattivato)
*
* -------------------------------------------------------------------------------- */
#region Public Constructors
/// <summary>
/// Classe base con i metodi x Siemens
/// </summary>
/// <param name="caller"></param>
/// <param name="adpConf"></param>
public SiemensNWSE(AdapterFormNext caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
lgInfo("NEW IOB SIEMENS versione NWS");
if (IOBConf.optPar.ContainsKey("EMERGENCY_BYPASS"))
{
bool.TryParse(IOBConf.optPar["EMERGENCY_BYPASS"], out EmergencyBypass);
lgInfo($"Override EmergencyBypass da conf: {IOBConf.optPar["EMERGENCY_BYPASS"]} --> {EmergencyBypass}");
}
}
#endregion Public Constructors
#region Public Methods
/// <summary>
/// Processo i task richiesti e li elimino dalla coda 1:1
/// </summary>
/// <param name="task2exe"></param>
public override Dictionary<string, string> executeTasks(Dictionary<string, string> task2exe)
{
lgInfo($"Chiamata executeTasks specifica IobSiemensNWS: {task2exe.Count} task ricevuti");
// Verificare il protocollo: dovrebeb togliere SOLO i task eseguiti...
Dictionary<string, string> taskDone = new Dictionary<string, string>();
bool taskOk = false;
string taskVal = "";
// inizio con 1 byte di default
byte[] MemBlock = new byte[1];
string memAddrWrite = "";
if (task2exe != null)
{
// cerco task specifici
foreach (var item in task2exe)
{
taskOk = false;
taskVal = "";
// converto richiesta in enum...
taskType tName = taskType.nihil;
Enum.TryParse(item.Key, out tName);
// controllo sulla KEY
switch (tName)
{
case taskType.forceResetPzCount:
// usato x resettare i contatori osmosi inversa e depurazione processo
// scrittura BIT su DB101.DBB0 per
MemBlock = new byte[1];
// scrivo 3 x resettare entrambi i contatori
MemBlock = S7.Net.Types.Byte.ToByteArray(3);
memAddrWrite = "DB101.DB0";
// scrivo!
taskOk = S7WriteBB(ref MemBlock, memAddrWrite);
// attesa 3.5 sec sec
Thread.Sleep(3500);
// predispongo x reset valore 0...
MemBlock = S7.Net.Types.Byte.ToByteArray(0);
break;
// lasciato commentato, da rivalutare...
#if false
case taskType.setParameter:
// richiedo da URL i parametri WRITE da popolare
lgInfo("setParameter --> processMemWriteRequests");
taskVal = processMemWriteRequests();
// se restituiscce "" faccio altra prova...
if (string.IsNullOrEmpty(taskVal))
{
// i parametri me li aspetto come stringa composta paramName|paramvalue
if (item.Value.Contains("|"))
{
string[] paramsJob = item.Value.Split('|');
taskVal = $"REQUEST SET PARAMETERS: {paramsJob[0]} --> {paramsJob[1]}";
}
else
{
taskVal = $"WRONG REQUEST FOR SET PARAMETERS: {item.Value} doesnt contain pipe for splitting key/value";
}
}
break;
#endif
default:
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
break;
}
lgInfo($"executeTask | task name: {tName} | task value: {taskVal}");
// aggiungo task!
taskDone.Add(item.Key, taskVal);
if (!string.IsNullOrEmpty(memAddrWrite))
{
// scrivo!
taskOk = S7WriteBB(ref MemBlock, memAddrWrite);
}
if (taskOk)
{
// aggiorno valore memoria... SE presente
if (memMap.mMapWrite.ContainsKey(item.Key))
{
memMap.mMapWrite[item.Key].value = item.Value;
lgInfo($"Aggiornato valore in mMapWrite per {item.Key}");
}
lgInfo($"Eseguita con successo S7WriteBB per executeTasks: {item.Key} | {item.Value}");
}
else
{
lgError($"Errore in S7WriteBB durante executeTasks: {item.Key} | {item.Value}");
}
}
}
return taskDone;
}
#endregion Public Methods
#region Protected Fields
protected bool EmergencyBypass = false;
#endregion Protected Fields
#region Protected Methods
/// <summary>
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
/// </summary>
protected override void decodeToBaseBitmap()
{
// init a zero...
B_input = 0;
/* -----------------------------------------------------
* bitmap MAPO STANDARD 60
* B0: POWER_ON
* B1: RUN
* B2: pzCount - NON usato
* B3: allarme (almeno 1 presente)
* B4: manuale - non usato
* B5: slowTC - non usato
* B6: WarmUpCoolDown - no usato
* B7: Emergenza armata (1)
*
----------------------------------------------------- */
int byteSignals = 0;
// bit 0 (poweron) imposto a 1 SE connected...
if (currPLC.IsConnected)
{
byteSignals += (1 << 0);
}
// processo dagli stati + gravi...
if (hasAlarms())
{
byteSignals += (1 << 3);
}
else
{
byteSignals += (1 << 1);
}
// se bypass emergenza attivo --> forzo a ARMED...
if (EmergencyBypass)
{
// segnalo NON emergenza
byteSignals += (1 << 7);
}
// salvo!
B_input = byteSignals;
}
#endregion Protected Methods
}
}