Files
Mapo-IOB-WIN/IOB-WIN-NEXT/IobModbusTCPZetapack.cs
T
Samuele E. Locatelli cd28df8a1d Zetapack:
- aggiunto metodo test INT
- conf aggiornata
2022-11-11 19:13:44 +01:00

207 lines
6.1 KiB
C#

using EasyModbus;
using System;
namespace IOB_WIN_NEXT
{
/* --------------------------------------------------------------------------------
* Controlli ModBusTCP Zetapack
* - protocollo ModBus TCP
* - specifico comportamento impianti imballaggio Zetapack (Giacovelli)
* - gestione allarmi
*
* STRUTTURA MEMORIA a banchi di UInt16, convertiti successivamente in int EVENTUALMENTE divisi per 10/100/1000
* G:\Drive condivisi\30_Clienti\Giacovelli - WIL\Zetapack PLC
*
* -------------------------------------------------------------------------------- */
public class IobModbusTCPZetapack : IobModbusTCP
{
#region Public Constructors
/// <summary>
/// Classe base con i metodi x ModBusTCP
/// </summary>
/// <param name="caller"></param>
/// <param name="IOBConf"></param>
public IobModbusTCPZetapack(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
lgInfo("NEW IOB ModBus TCP Zetapack");
// provo lettura una prima volta i dati DYN
if (currPLC != null && currPLC.Connected)
{
try
{
processDynData();
}
catch (Exception exc)
{
lgError($"Eccezione in processDynData iniziale x ModBus TCP IMAS Aeromec:{Environment.NewLine}{exc}");
}
}
}
#endregion Public Constructors
#region Protected Properties
/// <summary>
/// Restituisce status di WORK (auto + lavora), hard coded
/// </summary>
protected bool WorkState
{
get
{
return testIntCondition("WorkIntCond");
}
}
/// <summary>
/// Restituisce status di Manuale, hard coded
/// </summary>
protected bool ManualState
{
get
{
return testIntCondition("ManualIntCond");
}
}
/// <summary>
/// Restituisce status di ESTOP triggered (triggered = premuta, altrimenti armed)
/// </summary>
protected bool EStopTriggered
{
get
{
return testBitCondition("EStopBitCond");
}
}
/// <summary>
/// Restituisce controllo IN ALLARME
/// </summary>
protected bool AlarmState
{
get
{
return testIntCondition("AlarmIntCond");
}
}
/// <summary>
/// Restituisce status di LAVORA, hard coded
/// </summary>
protected bool Work
{
get
{
return testIntCondition("WorkIntCond");
}
}
#endregion Protected Properties
#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
* B3: allarme
* B4: manuale
* B5: slowTC
* B6: WarmUpCoolDown
* B7: EmergArmata
*
----------------------------------------------------- */
var MemInt = new byte[2];
int byteSignals = 0;
// bit 0 (poweron) imposto a 1 SE connected...
if (currPLC.Connected)
{
byteSignals += (1 << 0);
}
// se ho qualcosa nella holding register...
if (HoldingRegisterLUT != null && HoldingRegisterLUT.Count > 0)
{
// se emergenza NON premuta (triggered) indico OK (armata...) FARE !!! togliere true
//if (!EStopTriggered)
if (true)
{
byteSignals += (1 << 7);
}
// impiego controlli da setup IntConditions... processo dagli stati + gravi...
if (AlarmState || hasAlarms())
{
byteSignals += (1 << 3);
}
else if (ManualState)
{
byteSignals += (1 << 4);
}
else if (WorkState)
{
byteSignals += (1 << 1);
}
}
else
{
lgInfo("HoldingRegisterLUT vuoto!");
}
// salvo!
B_input = byteSignals;
}
#endregion Protected Methods
#region Private Methods
private void testBlockRead(int baseAddr, int numByte)
{
int baseHold = 40001;
int[] readTestFull = new int[2];
lgTrace($"-------------------- Inizio test lettura {baseAddr} --------------------");
try
{
stopwatch.Restart();
readTestFull = currPLC.ReadHoldingRegisters(baseAddr - baseHold, numByte);
stopwatch.Stop();
lgTrace($"Stats lettura | {readTestFull.Length} val | {stopwatch.ElapsedMilliseconds}ms");
}
catch
{ }
for (int i = 0; i < readTestFull.Length / 2; i++)
{
int[] thisSet = new int[2];
Array.Copy(readTestFull, i * 2, thisSet, 0, 2);
lgTrace($"{baseAddr + i * 2:000} | HoldingRegisters: {thisSet[0]} / {thisSet[1]} | Val Real: {ModbusClient.ConvertRegistersToFloat(thisSet):N6}");
}
lgTrace("-------------------- Completato test lettura {baseAddr} --------------------");
}
private void testRead()
{
foreach (var item in memSetR)
{
testBlockRead(item.Key, item.Value);
}
}
#endregion Private Methods
}
}