Merge branch 'release/ModBusBeta'

This commit is contained in:
Samuele Locatelli
2021-09-28 10:57:06 +02:00
20 changed files with 2308 additions and 1800 deletions
Binary file not shown.
+10
View File
@@ -269,6 +269,16 @@ namespace IOB_UT_NEXT
/// </summary>
ND,
/// <summary>
/// Adapter ModBus TCP generico
/// </summary>
MODBUS_TCP,
/// <summary>
/// Adapter ModBus TCP versione HAM (Pizzaferri)
/// </summary>
MODBUS_TCP_HAM,
/// <summary>
/// Adapter MTConnect
/// </summary>
+2 -2
View File
@@ -59,8 +59,8 @@
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.1.9, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.3.1\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="MapoSDK, Version=6.13.2105.1421, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MapoSDK.6.13.2105.1421\lib\net40\MapoSDK.dll</HintPath>
<Reference Include="MapoSDK, Version=6.13.2109.1112, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MapoSDK.6.13.2109.1112\lib\net40\MapoSDK.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
+76
View File
@@ -188,6 +188,82 @@ namespace IOB_UT_NEXT
#endregion Public Methods
}
#if false
/// <summary>
/// Struttura della conf memoria ModBus
/// </summary>
public class BaseModbusConf
{
public enum DataType
{
ND = 0,
BIT,
INT,
REAL
}
public enum MemType
{
ND = 0,
DiscreteInput = 1,
Coil = 2,
InputRegister = 3,
HoldingRegister = 4
}
/// <summary>
/// Elenco aree memoria ModBus in lettura
/// </summary>
public List<ModbusMemArea> mMapRead { get; set; } = new List<ModbusMemArea>();
/// <summary>
/// Elenco aree memoria ModBus in scrittura
/// </summary>
public List<ModbusMemArea> mMapWrite { get; set; } = new List<ModbusMemArea>();
/// <summary>
/// struttura di base memoria ModBus
/// </summary>
public class ModbusMemArea
{
public ushort BaseAddr { get; set; } = 0;
public string RawAddr { get; set; } = "";
public ushort Size { get; set; } = 0;
[JsonConverter(typeof(StringEnumConverter))]
public MemType Type { get; set; } = MemType.ND;
public List<VarConf> VarList { get; set; } = new List<VarConf>();
}
public class VarConf
{
public string description { get; set; } = "";
public int factor { get; set; } = 1;
public bool hasRange
{
get
{
return !this.minVal.Equals(this.maxVal);
}
}
public ushort index { get; set; } = 0;
public int maxVal { get; set; } = 0;
public string memAddr { get; set; } = "";
public int minVal { get; set; } = 0;
public string name { get; set; } = "none";
public ushort size { get; set; } = 0;
[JsonConverter(typeof(StringEnumConverter))]
public DataType tipoMem { get; set; } = DataType.ND;
public string value { get; set; } = "";
}
}
#endif
/// <summary>
/// Classe gestione configurazione parametri di base x configuraizone estesa (es MTConnect, OPC-UA, ...)
/// </summary>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MapoSDK" version="6.13.2105.1421" targetFramework="net462" />
<package id="MapoSDK" version="6.13.2109.1112" targetFramework="net462" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net462" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net462" />
<package id="NLog" version="4.7.9" targetFramework="net462" />
+10
View File
@@ -1186,6 +1186,16 @@ namespace IOB_WIN_NEXT
start.Enabled = true;
break;
case tipoAdapter.MODBUS_TCP:
iobObj = new IobModbusTCP(this, IOBConf);
start.Enabled = true;
break;
case tipoAdapter.MODBUS_TCP_HAM:
iobObj = new IobModbusTCPHam(this, IOBConf);
start.Enabled = true;
break;
case tipoAdapter.MTConnect:
iobObj = new IobMTC(this, IOBConf);
start.Enabled = true;
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -64,7 +64,9 @@ CLI_INST=SteamWareSim
;STARTLIST=TEST
;STARTLIST=SIMUL_01
;STARTLIST=1032
STARTLIST=PIZ08
;STARTLIST=1033
;STARTLIST=PIZ08
STARTLIST=PIZ04
;STARTLIST=OPC_UA
MAXCNC=10
+70
View File
@@ -0,0 +1,70 @@
;Configurazione IOB-WIN
[IOB]
;Impianto HAM per Pizzaferri
CNCTYPE=MODBUS_TCP_HAM
PING_MS_TIMEOUT=500
[MACHINE]
VENDOR=HAM
MODEL=HAM
[CNC]
IP=hampizzaferri.dyndns.org
PORT=502
[SERVER]
;MPIP=https://localhost:44339
MPIP=https://gwms.egalware.com
MPURL=/api
CMDBASE=/IOB/input/
CMDFLOG=/IOB/flog/
CMDALIVE=/IOB
CMDENABLED=/IOB/enabled/
CMDADV1=?valore=
CMDREBO=/IOB/sendReboot?idxMacchina=
[MEMORY]
ADDR_READ=40001
ADDR_WRITE=40401
SIZE_READ=34
;SIZE_READ=5046
SIZE_WRITE=358
[BLINK]
;MAX_COUNTER_BLINK = 30
MAX_COUNTER_BLINK = 15
;bit0 = 0
;bit1 = 0
;bit2 = 1
;bit3 = 1
;bit4 = 1
;bit5 = 0
;bit6 = 0
;bit7 = 0
BLINK_FILT=0
;BLINK_FILT=28
[OPTPAR]
;PZCOUNT_MODE=STD.[PAR/MEM].info|BIT.indice
PZCOUNT_MODE=STD.DB85.DBRE16
DISABLE_PZCOUNT=TRUE
ENABLE_SEND_PZC_BLOCK=TRUE
MIN_SEND_PZC_BLOCK=0
MAX_SEND_PZC_BLOCK=100
; GEST DATI DYN
ENABLE_DYN_DATA=TRUE
FORCE_DYN_DATA=TRUE
; clock base (da 10ms)
timerIntMs=100
; conf parametri memoria READ/WRITE
PARAM_CONF=PIZ04.json
NO_PING=FALSE
; conf aree allarme
ALARM_CONF=PIZ04_alarm.json
[BRANCH]
NAME=master
+255
View File
@@ -0,0 +1,255 @@
{
//"mMapWrite": {
// "setProg": {
// "name": "setProg",
// "description": "Programma",
// "tipoMem": "String",
// "memAddr": "DB6.DBB50",
// "index": 50,
// "size": 50
// },
// "setComm": {
// "name": "setComm",
// "description": "Commessa",
// "tipoMem": "String",
// "memAddr": "DB6.DBB0",
// "index": 0,
// "size": 50
// },
// "setArt": {
// "name": "setArt",
// "description": "Articolo",
// "tipoMem": "String",
// "memAddr": "DB6.DBB100",
// "index": 100,
// "size": 50
// },
// "setPzComm": {
// "name": "setPzComm",
// "description": "Qty",
// "memAddr": "DB30.DBB212",
// "tipoMem": "DInt",
// "index": 212,
// "size": 4
// }
//},
"mMapRead": {
"Level": {
"name": "GiacSerb",
"description": "Livello Serbatoio",
"memAddr": "40001",
"tipoMem": "Real",
"index": 1,
"size": 2,
"func": "MAX",
"period": 60,
"factor": 280,
"minVal": 0,
"maxVal": 100
},
"MainPress": {
"name": "PressSerb",
"description": "Pressione Serbatoio",
"memAddr": "40003",
"tipoMem": "Real",
"index": 3,
"size": 2,
"func": "MAX",
"period": 60,
"factor": 1,
"minVal": 0,
"maxVal": 25
},
"PressBH": {
"name": "PBH",
"description": "Pressione media allinterno dellaccumulo GNC (pacco bombole) di alta pressione",
"memAddr": "40019",
"tipoMem": "Real",
"index": 19,
"size": 2,
"func": "MAX",
"period": 60,
"factor": 1,
"minVal": 0,
"maxVal": 400
},
"PressBL": {
"name": "PBM",
"description": "Pressione media allinterno dellaccumulo GNC (pacco bombole) di media pressione",
"memAddr": "40021",
"tipoMem": "Real",
"index": 21,
"size": 2,
"func": "MAX",
"period": 60,
"factor": 1,
"minVal": 0,
"maxVal": 400
},
//"TE2A": {
// "name": "TE2A",
// "description": "Temperatura Controllo Tenute Pompa A",
// "memAddr": "DB85.DBB0",
// "tipoMem": "Real",
// "index": 0,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE1A": {
// "name": "TE1A",
// "description": "Temperatura Raffreddamento Pompa A",
// "memAddr": "DB85.DBB4",
// "tipoMem": "Real",
// "index": 4,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE3A": {
// "name": "TE3A",
// "description": "Temperatura Cavitazione Pompa A",
// "memAddr": "DB85.DBB8",
// "tipoMem": "Real",
// "index": 8,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"Temp01": {
// "name": "TE04",
// "description": "Temperatura Torcia Aria Fredda",
// "memAddr": "DB85.DBB12",
// "tipoMem": "Real",
// "index": 12,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"Temp02": {
// "name": "TT17",
// "description": "Temperatura Spurgo Torcia Serbatoio",
// "memAddr": "DB85.DBB36",
// "tipoMem": "Real",
// "index": 36,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE06": {
// "name": "TE06",
// "description": "Temperatura Uscita Vaporizzatore",
// "memAddr": "DB85.DBB40",
// "tipoMem": "Real",
// "index": 40,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE05": {
// "name": "TE05",
// "description": "Temperatura Carica Fredda",
// "memAddr": "DB85.DBB60",
// "tipoMem": "Real",
// "index": 60,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE2B ": {
// "name": "TE2B",
// "description": "Temperatura Controllo Tenute Pompa B",
// "memAddr": "DB85.DBB64",
// "tipoMem": "Real",
// "index": 64,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE1B ": {
// "name": "TE1B",
// "description": "Temperatura Raffreddamento Pompa B",
// "memAddr": "DB85.DBB68",
// "tipoMem": "Real",
// "index": 68,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"TE3B": {
// "name": "TE3B",
// "description": "Temperatura Cavitazione Pompa B",
// "memAddr": "DB85.DBB72",
// "tipoMem": "Real",
// "index": 72,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"PressH": {
// "name": "PT300A",
// "description": "Alta Pressione",
// "memAddr": "DB85.DBB120",
// "tipoMem": "Real",
// "index": 120,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"PressM": {
// "name": "PT300M",
// "description": "Media Pressione",
// "memAddr": "DB85.DBB124",
// "tipoMem": "Real",
// "index": 124,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"LivelloPerc": {
// "name": "LT15%",
// "description": "Livello Serbatorio %",
// "memAddr": "DB85.DBB148",
// "tipoMem": "Real",
// "index": 148,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"MinTemp01": {
// "name": "MinTempTE04",
// "description": "Minima Temperatura Linea Sfiato Gas TE04",
// "memAddr": "DB85.DBB152",
// "tipoMem": "Real",
// "index": 152,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//},
//"MinTemp02": {
// "name": "MinTempTT17",
// "description": "Minima Temperatura Linea Sfiato Gas Torcia Serbatoio TT17",
// "memAddr": "DB85.DBB156",
// "tipoMem": "Real",
// "index": 156,
// "size": 4,
// "func": "MAX",
// "period": 60,
// "factor": 1
//}
}
}
+125
View File
@@ -0,0 +1,125 @@
[
//{
// "description": "Allarmi Impianto",
// "tipoMem": "Boolean",
// "memAddr": "DB85.DBB232",
// "index": 232,
// "size": 6,
// "messages": [
// "Emergenza Non Ripristinata",
// "Emergenza QE Intervenuta",
// "Emergenza Puls. Dispencer B Invervenuta",
// "Emergenza Puls. Dispencer A Invervenuta",
// "Stato Interruttore Erogatore Liquido B",
// "Allarme Controllo Tensione di Rete",
// "Allarme Controllo Tensione Antincendio",
// "Stato Interruttore Erogatore Liquido A",
// "Stato Sezionatore Generale",
// "Stato Interruttore Protezione SPD",
// "Stato Interruttore Sirena e Rotoalarm",
// "Stato Interruttore Luci Emergenza",
// "Stato Interruttore Pompa PC1A",
// "Stato Interruttore Pompa PC1B",
// "Stato Interruttore Pompa Sommersa C",
// "Stato Termica Boil-Off",
// "##234.0",
// "Preallarme Centralina Metano",
// "Allarme Centralina Metano",
// "Emergenza Puls. Dispencer C Invervenuta",
// "Mancaza Pressione Aria",
// "Minima Temperatura Linea Sfiato Gas TE04",
// "Minima Temperatura Linea Sfiato Gas Torcia Serbatoio TT17",
// "Massima Temperatura Linea Sfiato Gas Torcia Serbatoio TT17",
// "Almeno Un Emergenza Intervenuta",
// "Arresto Operativo da PT1(predisposizione)",
// "Stato Interruttore Alimentazione Punto Zero",
// "##234.11",
// "##234.12",
// "##234.13",
// "##234.14",
// "Configurazione Incongruente",
// "Pulsante Emergenza 2 SB17.3A Premuto",
// "Pulsante Emergenza 1 SB17.3B Premuto",
// "Pulsante Emergenza SB17.3C Premuto",
// "Pulsante Emergenza 3 SB17.5 Premuto",
// "Pulsante Emergenza 4 SB17.7 Premuto",
// "##236.5",
// "##236.6",
// "##236.7",
// "GT_TE2A",
// "GT_TE1A",
// "GT_TE3A",
// "GT_TE04",
// "GT_LT15",
// "GT_PT01",
// "GT_PT300R",
// "GT_PT16"
// ]
//},
//{
// "description": "Allarmi Serbatoio",
// "tipoMem": "Boolean",
// "memAddr": "DB85.DBB248",
// "index": 248,
// "size": 2,
// "messages": [
// "Serbatoio Troppo Pieno",
// "Serbatoio Pieno_HH",
// "Serbatoio Pieno_H",
// "Serbatoio Vuoto_LL",
// "H Pressione Serbatoio",
// "HH Pressione Serbatoio",
// "LL Temperatura Ingresso BoilOff TE08",
// "Minima Pressione Serbatoio per Partenza Pompe",
// "Timeout Apertura Valvola PV1",
// "Timeout Chiusura Valvola PV1",
// "Timeout Apertura Valvola PV70",
// "Timeout Chiusura Valvola PV70",
// "##248.12",
// "##248.13",
// "##248.14",
// "##248.15"
// ]
//},
//{
// "description": "Allarmi Pompa Alta Pressione A",
// "tipoMem": "Boolean",
// "memAddr": "DB85.DBB252",
// "index": 252,
// "size": 4,
// "messages": [
// "Ritardo Avvio Pompa PC1B",
// "##252.1",
// "Temperatura Freddo TE1B NON Raggiunta",
// "HH Temperatura Cavitazione TE3B",
// "Allarme Temperatura Tenute Pompa TE2B",
// "LL Temperatura Ingresso Stoccaggio TE06",
// "Allarme Temperatura Ingresso Stoccaggio TE07",
// "Aumento Pressione PT01",
// "##Max Pressione PT01",
// "##256.9",
// "##256.10",
// "##256.11",
// "##256.12",
// "##256.13",
// "##256.14",
// "##256.15",
// "Timeout Apertura PV3B",
// "Timeout Apertura PV5B",
// "Timeout Apertura PV6B",
// "Timeout Apertura PV7",
// "##258.4",
// "##258.5",
// "##258.6",
// "##258.7",
// "##258.8",
// "##258.9",
// "##258.10",
// "##258.11",
// "##258.12",
// "##258.13",
// "##258.14",
// "##258.15"
// ]
//}
]
+2
View File
@@ -67,6 +67,8 @@ MAX_SEND_PZC_BLOCK=100
;GESTIONE DATI DYN
ENABLE_DYN_DATA=TRUE
FORCE_DYN_DATA=TRUE
; gestione scrittura string/char[]: true = string / false = char[]
WRITE_PRE=TRUE
USE_NEW_EXE_TASK=TRUE
; conf parametri memoria READ/WRITE
+17 -3
View File
@@ -83,12 +83,15 @@
<Reference Include="CndexLinkDotNet">
<HintPath>..\CncLib\ExtLib\CndexLinkDotNet.dll</HintPath>
</Reference>
<Reference Include="EasyModbus, Version=5.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll</HintPath>
</Reference>
<Reference Include="krcc, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>ExtLib\krcc.dll</HintPath>
</Reference>
<Reference Include="MapoSDK, Version=6.13.2105.1421, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MapoSDK.6.13.2105.1421\lib\net40\MapoSDK.dll</HintPath>
<Reference Include="MapoSDK, Version=6.14.2109.2809, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MapoSDK.6.14.2109.2809\lib\net40\MapoSDK.dll</HintPath>
</Reference>
<Reference Include="MTConnect-NET, Version=2.9.1.28314, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MTConnect.NET.2.9.1.28314\lib\net40\MTConnect-NET.dll</HintPath>
@@ -97,7 +100,7 @@
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.7.9\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.4.7.11\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="OmronFinsTCP.Net, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\OmronFinsTCP.Net.3.0.0.0\lib\net40\OmronFinsTCP.Net.dll</HintPath>
@@ -172,6 +175,8 @@
<Compile Include="ControlExtensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="IobFileEurom63.cs" />
<Compile Include="IobModbusTCPHam.cs" />
<Compile Include="IobModbusTCP.cs" />
<Compile Include="IobOpcUa.cs" />
<Compile Include="IobMTC.cs" />
<Compile Include="IobOmron.cs" />
@@ -347,12 +352,21 @@
<None Include="DATA\CONF\IMI_50.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\PIZ04.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\PIZ04.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\PIZ03.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\PIZ03.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\PIZ04_alarm.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DATA\CONF\PIZ03_alarm.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+15 -5
View File
@@ -536,8 +536,17 @@ namespace IOB_WIN_NEXT
address = IPAddress.Loopback;
int maxRetry = maxPingRetry + 1;
int numRetry = 1; ;
string ipAdrr = cIobConf.serverData.MPIP.Replace($"{cIobConf.serverData.TRANSP}://", "");
IPAddress.TryParse(ipAdrr, out address);
string ipAddr = cIobConf.serverData.MPIP.Replace($"{cIobConf.serverData.TRANSP}://", "");
IPAddress.TryParse(ipAddr, out address);
// se null --> provo DNS...
if (address == null)
{
var rawAddresses = Dns.GetHostAddresses(ipAddr);
if (rawAddresses.Length > 0)
{
address = rawAddresses[0];
}
}
try
{
// se != null --> uso address...
@@ -557,12 +566,12 @@ namespace IOB_WIN_NEXT
// se ho timeout riprovo...
while (reply.Status != IPStatus.Success && numRetry < maxRetry)
{
lgInfo($"Ping KO | reply: {reply.Status} --> retry");
lgInfo($"Server Ping KO | reply: {reply.Status} --> retry");
reply = pingSender.Send(address, pingServerMsTimeout * numRetry / 2);
numRetry++;
if (reply.Status == IPStatus.Success)
{
lgInfo("PING OK!");
lgInfo("Server PING OK!");
break;
}
}
@@ -4072,7 +4081,8 @@ namespace IOB_WIN_NEXT
{ }
/// <summary>
/// Effettua processing del recupero delle speed (RPM, feedrate) degli assi
/// Effettua processing del recupero dei valori dinamici:
/// es: speed (RPM, feedrate) degli assi, valori pressioni, temeprature
/// </summary>
public void processDynData()
{
File diff suppressed because it is too large Load Diff
+421
View File
@@ -0,0 +1,421 @@
using EasyModbus;
using IOB_UT_NEXT;
using MapoSDK;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace IOB_WIN_NEXT
{
/* --------------------------------------------------------------------------------
* Controlli ModBusTCP COMECA
* - protocollo ModBus TCP HAM
* - specifico comportamento impianti HAM Pizzaferri
*
* STRUTTURA MEMORIA a banchi di byte, convertiti successivamente in bit/int/real:
* lettura: xxx byte,
* scrittura yyy byte
* G:\Drive condivisi\30_Clienti\Pizzaferri\Impianti\HAM
* *
* -------------------------------------------------------------------------------- */
public class IobModbusTCPHam : IobModbusTCP
{
#region Public Constructors
/// Classe base con i metodi x ModBusTCP
/// </summary>
/// <param name="caller"></param>
/// <param name="adpConf"></param>
public IobModbusTCPHam(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
lgInfo("NEW IOB ModBus TCP HAM");
// provo lettura una prima volta i dati DYN
if (currPLC.Connected)
{
try
{
processDynData();
}
catch (Exception exc)
{ }
}
}
#endregion Public Constructors
#region Protected Properties
protected bool hasAlarms
{
get
{
bool answ = false;
#if false
int numErrors = 0;
uint currStatus = 0;
if (alarmMaps != null)
{
// leggo a ciclo le aree degli allarmi CONFIGURATI, se ne trovo --> segnalo allarme...
foreach (var item in alarmMaps)
{
// in primis decremento eventuali blink...
item.decreaseBlinkCounter();
// banchi in WORD (2 byte) --> scompongo
for (int i = 0; i < item.size / 2; i++)
{
currStatus = S7.Net.Types.Counter.FromByteArray(RawInput.Skip(item.index + 2 * i).Take(2).ToArray());
// verifico SE sia variato...
if (item.isChanged(i, currStatus))
{
numErrors++;
answ = true;
// registro gli allarmi attivi e trasmetto...
if (sendAlarmVariations(item.memAddr, i, item.alarmsState[i], currStatus))
{
// se inviato --> salvo stato da current...
item.updStatusVal(i, currStatus);
}
}
}
}
}
#endif
return answ;
}
}
#endregion Protected Properties
#region Private Methods
private void testRead()
{
//Ip-Address and Port of Modbus-TCP-Server
//currPLC = new ModbusClient(cIobConf.cncIpAddr, 502);
////Connect to Server
//currPLC.Connect();
//modbusClient.WriteMultipleCoils(4, new bool[] { true, true, true, true, true, true, true, true, true, true }); //Write Coils starting with Address 5
//bool[] readCoils = modbusClient.ReadCoils(9, 10); //Read 10 Coils from Server, starting with address 10
//int[] readHoldingRegisters = currPLC.ReadHoldingRegisters(0, 34); //Read 10 Holding Registers from Server, starting with Address 1
int[] readHR1000 = currPLC.ReadHoldingRegisters(0, 100); //Read 10 Holding Registers from Server, starting with Address 1
//// Console Output
//for (int i = 0; i < readCoils.Length; i++)
// Console.WriteLine("Value of Coil " + (9 + i + 1) + " " + readCoils[i].ToString());
for (int i = 0; i < readHR1000.Length / 2; i++)
{
Console.WriteLine($"Value of HoldingRegister {(i)} | {readHR1000[i]} / {readHR1000[i + 1]}");
int[] thisSet = new int[2];
Array.Copy(readHR1000, i, thisSet, 0, 2);
Console.WriteLine($"Convert val HoldingRegister {(i)} | {ModbusClient.ConvertRegistersToFloat(thisSet)}");
}
//Console.Write("Press any key to continue . . . ");
//Console.ReadKey(true);
}
#endregion Private Methods
#region Protected Methods
/// <summary>
/// Effettua decodifica aree memoria alla bitmap usata x MAPO/GWMS
/// - per lo scopo specifico IN REALTA' non conta lo stato macchina.... ma lo inviamo lo stesso
/// </summary>
protected override void decodeToBaseBitmap()
{
// init a zero...
B_input = 0;
/* -----------------------------------------------------
* bitmap MAPO STANDARD
* B0: POWER_ON
* B1: RUN
* B2: pzCount
* B3: allarme
*
----------------------------------------------------- */
var MemInt = new byte[2];
int byteSignals = 0;
// bit 0 (poweron) imposto a 1 SE connected...
if (currPLC.Connected)
{
byteSignals += (1 << 0);
}
// processo dagli stati + gravi...
if (hasAlarms)
{
byteSignals += (1 << 3);
}
else
{
byteSignals += (1 << 1);
}
// salvo!
B_input = byteSignals;
}
/// <summary>
/// effettua il setup dei memblock da gestire (NON leggo intera memoria ma tanti blocchi...)
/// </summary>
protected override void setupMemBlocks()
{
// da calcolare... ora setup cablato...
memSetR.Add(1, 34);
}
#endregion Protected Methods
#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 ModBus TCP HAM: {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)
{
#if false
// 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.nihil:
case taskType.fixStopSetup:
case taskType.forceResetPzCount:
case taskType.forceSetPzCount:
case taskType.setProg:
case taskType.sendWatchDogMes2Plc:
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
break;
case taskType.setPzComm:
case taskType.setArt:
case taskType.setComm:
saveProdData(item);
int byteSize = 0;
// recupero dati da memMap... altrimenti NULLA
if (memMap.mMapWrite.ContainsKey(item.Key))
{
dataConf currMem = memMap.mMapWrite[item.Key];
byteSize = currMem.size;
memAddrWrite = currMem.memAddr;
MemBlock = new byte[byteSize];
if (currMem.tipoMem == plcDataType.String)
{
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize);
}
else if (currMem.tipoMem == plcDataType.DInt)
{
int valDInt = 0;
int.TryParse(item.Value, out valDInt);
MemBlock = S7.Net.Types.DInt.ToByteArray(valDInt);
}
else if (currMem.tipoMem == plcDataType.Int)
{
short valInt = 0;
short.TryParse(item.Value, out valInt);
MemBlock = S7.Net.Types.Int.ToByteArray(valInt);
}
}
else
{
lgError($"Errore: non trovata chiave write in memMap.mMapWrite per {item.Key}");
}
taskVal = item.Value;
break;
case taskType.startSetup:
// processo scrittura BIT su DB6.DBDW216
MemBlock = new byte[1];
MemBlock[0] = (byte)1;
memAddrWrite = "DB6.DBDW216";
break;
case taskType.stopSetup:
// processo scrittura BIT su DB6.DBDW216
MemBlock = new byte[1];
MemBlock[0] = (byte)0;
memAddrWrite = "DB6.DBDW216";
break;
case taskType.setParameter:
// richiedo da URL i parametri WRITE da popolare
lgInfo("Chiamata 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;
default:
taskVal = "SKIPPED | NO EXEC";
break;
}
// aggiungo task!
taskDone.Add(item.Key, taskVal);
if (!string.IsNullOrEmpty(memAddrWrite))
{
// scrivo!
taskOk = S7WriteBB(ref MemBlock, memAddrWrite);
}
if (!taskOk)
{
lgError($"Errore in S7WriteBB durante executeTasks: {item.Key} | {item.Value}");
}
}
#endif
}
return taskDone;
}
/// <summary>
/// Override connessione
/// </summary>
public override void tryConnect()
{
bool doLog = (verboseLog || periodicLog);
lgInfo("ModBus TCP HAM: tryConnect step 01");
if (!connectionOk)
{
// SE è necessario refresh...
if (needRefresh)
{
lgInfo("ModBus TCP HAM: tryConnect step 02");
// reimporto parametri PLC se necessario...
setParamPlc();
}
lgInfo("ModBus TCP HAM: tryConnect step 03");
// controllo che il ping sia stato tentato almeno pingTestSec fa...
if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
{
if (doLog)
{
lgInfo("ModBus TCP HAM: ConnKO - tryConnect");
}
lgInfo("ModBus TCP HAM: tryConnect step 04");
// in primis salvo data ping...
lastPING = DateTime.Now;
// se passa il ping faccio il resto...
if (testPingMachine == IPStatus.Success)
{
string szStatusConnection = "ND";
try
{
// ora provo connessione...
parentForm.commPlcActive = true;
currPLC.Connect();
szStatusConnection = "OPEN";
parentForm.commPlcActive = false;
connectionOk = currPLC.Connected;
lgInfo($"StatusConnection: {szStatusConnection}");
// refresh stato allarmi!!!
if (connectionOk)
{
if (adpRunning)
{
lgInfo($"Connessione OK: {connectionOk} | adpRunning: {adpRunning}");
}
}
else
{
lgError("Impossibile procedere, connessione mancante...");
}
}
catch (Exception exc)
{
lgFatal($"Errore in TryConnect adapter ModBusTCP | szStatusConnection {szStatusConnection}{Environment.NewLine}{exc}");
connectionOk = false;
needRefresh = true;
}
}
else
{
// loggo no risposta ping ...
connectionOk = false;
if (doLog)
{
lgInfo($"Attenzione: ModBusTCP controllo PING fallito per IP {cIobConf.cncIpAddr}");
}
}
}
}
// se non è ancora connesso faccio procesisng memoria caso disconnesso...
if (!connectionOk)
{
// processo semafori ed invio...
processMemoryDiscon();
}
}
/// <summary>
/// Override disconnessione
/// </summary>
public override void tryDisconnect()
{
if (connectionOk)
{
string szStatusConnection = "";
try
{
currPLC.Disconnect();
connectionOk = false;
lgInfo(szStatusConnection);
lgInfo("Effettuata disconnessione adapter ModBusTCP!");
}
catch (Exception exc)
{
lgFatal(exc, "Errore nella disconnessione dall'adapter ModBusTCP");
}
}
else
{
lgError("IMPOSSIBILE effettuare disconnessione ModBusTCP: Connessione non disponibile...");
}
}
#endregion Public Methods
}
}
+2 -2
View File
@@ -129,7 +129,7 @@ namespace IOB_WIN_NEXT
#region Protected Properties
/// <summary>
/// Dizionario delel ultime operazioni dis crittura per OGNI memoria (in modo che fa log ogni x sec...)
/// Dizionario delle ultime operazioni di scrittura per OGNI memoria (in modo che fa log ogni x sec...)
/// </summary>
protected Dictionary<string, DateTime> lastMemWrite { get; set; } = new Dictionary<string, DateTime>();
@@ -416,7 +416,7 @@ namespace IOB_WIN_NEXT
}
/// <summary>
/// OVerride metodo x scrittura parametri su PLC
/// Override metodo x scrittura parametri su PLC
/// </summary>
/// <param name="updatedPar"></param>
protected override void plcWriteParams(ref List<objItem> updatedPar)
+4 -1
View File
@@ -466,7 +466,10 @@ namespace IOB_WIN_NEXT
try
{
var currForm = (AdapterForm)item;
numAttivi += currForm.iobObj.IobOnline ? 1 : 0;
if (currForm.iobObj != null)
{
numAttivi += currForm.iobObj.IobOnline ? 1 : 0;
}
}
catch
{ }
+3 -2
View File
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autoupdater.NET.Official" version="1.6.4" targetFramework="net462" />
<package id="MapoSDK" version="6.13.2105.1421" targetFramework="net462" />
<package id="EasyModbusTCP" version="5.6.0" targetFramework="net462" />
<package id="MapoSDK" version="6.14.2109.2809" targetFramework="net462" />
<package id="Microsoft.CodeAnalysis.NetAnalyzers" version="5.0.3" targetFramework="net462" developmentDependency="true" />
<package id="Microsoft.VisualStudio.SlowCheetah" version="3.2.26" targetFramework="net40-client" developmentDependency="true" />
<package id="MTConnect.NET" version="2.9.1.28314" targetFramework="net40-client" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net462" />
<package id="NLog" version="4.7.9" targetFramework="net462" />
<package id="NLog" version="4.7.11" targetFramework="net462" />
<package id="OmronFinsTCP.Net" version="3.0.0.0" targetFramework="net40-client" />
<package id="OPCFoundation.NetStandard.Opc.Ua.Client" version="1.4.365.48" targetFramework="net462" />
<package id="OPCFoundation.NetStandard.Opc.Ua.Configuration" version="1.4.365.48" targetFramework="net462" />
+46
View File
@@ -2,6 +2,52 @@
namespace IOB_WIN_NEXT
{
/// <summary>
/// Implementazione classe connessione ModBus TCP,
/// comprensiva dei parametri delle aree di memoria
/// </summary>
public class connParamModBusTCP
{
#region Public Fields
/// <summary>
/// Indirizzo IP del PLC
/// </summary>
public string ipAdrr = "";
/// <summary>
/// Base area x lettura
/// </summary>
public string memAddrRead = "";
/// <summary>
/// Base area x scrittura
/// </summary>
public string memAddrWrite = "";
/// <summary>
/// Size memoria lettura
/// </summary>
public int memSizeRead = 0;
/// <summary>
/// Size memoria scrittura
/// </summary>
public int memSizeWrite = 0;
/// <summary>
/// Timeout ping
/// </summary>
public int pingMsTimeout = 250;
/// <summary>
/// Porta di comunicazione
/// </summary>
public int port;
#endregion Public Fields
}
/// <summary>
/// Implementazione classe connessione SIEMENS con S7.net,
/// comprensiva dei parametri delle aree di memoria