848 lines
26 KiB
C#
848 lines
26 KiB
C#
using IOB_UT;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Net.NetworkInformation;
|
|
|
|
namespace IOB_WIN
|
|
{
|
|
public class IobOmron : IobGeneric
|
|
{
|
|
|
|
/// <summary>
|
|
/// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO
|
|
/// </summary>
|
|
Dictionary<string, string> signLUT = new Dictionary<string, string>();
|
|
/// <summary>
|
|
/// Oggetto MAIN x connessione OMRON
|
|
/// </summary>
|
|
protected OmronFinsTCP.Net.EtherNetPLC OMRON_ref;
|
|
/// <summary>
|
|
/// Array delle risposte dal controllo OMRON
|
|
/// </summary>
|
|
protected System.Collections.ArrayList resDataArray;
|
|
|
|
/// <summary>
|
|
/// Array valori letti da memoria CIO
|
|
/// </summary>
|
|
protected short[] memReadCIO;
|
|
/// <summary>
|
|
/// Array valori letti da memoria DM
|
|
/// </summary>
|
|
protected short[] memReadDM;
|
|
/// <summary>
|
|
/// Array valori letti da memoria WR
|
|
/// </summary>
|
|
protected short[] memReadWR;
|
|
/// <summary>
|
|
/// Array valori SCRITTI su memoria CIO
|
|
/// </summary>
|
|
protected short[] memWriteCIO;
|
|
/// <summary>
|
|
/// Array valori SCRITTI su memoria DM
|
|
/// </summary>
|
|
protected short[] memWriteDM;
|
|
/// <summary>
|
|
/// Array valori SCRITTI su memoria WR
|
|
/// </summary>
|
|
protected short[] memWriteWR;
|
|
|
|
// <summary>
|
|
/// Calcola la conversione da byte --> num decimale --> HEX --> conversione come stringa in INT
|
|
/// </summary>
|
|
/// <param name="valore"></param>
|
|
/// <returns></returns>
|
|
protected int convDHD(short valore)
|
|
{
|
|
int answ = 0;
|
|
string hexVal = valore.ToString("x");
|
|
int.TryParse(hexVal, out answ);
|
|
return answ;
|
|
}
|
|
// <summary>
|
|
/// Calcola la conversione da INTERO a intero HEX x OMRON
|
|
/// </summary>
|
|
/// <param name="valore"></param>
|
|
/// <returns></returns>
|
|
protected int convHD(string hexVal)
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
if (!hexVal.StartsWith("0x"))
|
|
{
|
|
hexVal = "0x" + hexVal;
|
|
}
|
|
answ = Convert.ToInt32(hexVal, 16);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Converte un valore di 2 short in un unico numero accostato:
|
|
/// es: legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
/// 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
/// </summary>
|
|
/// <param name="valori"></param>
|
|
/// <returns></returns>
|
|
protected int convFromHex(short[] valori)
|
|
{
|
|
int answ = 0;
|
|
string fullVal = $"{convDHD(valori[1]).ToString("D4")}{convDHD(valori[0]).ToString("D4")}";
|
|
int.TryParse(fullVal, out answ);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Converte un valore intero in 2 short che il PLC riporterà ad HEX x visualizzare:
|
|
/// es: legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
/// 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
/// </summary>
|
|
/// <param name="valoreInt"></param>
|
|
/// <returns></returns>
|
|
private short[] convToHex(int valoreInt)
|
|
{
|
|
short[] answ = new short[2];
|
|
string fullVal = valoreInt.ToString("D8");
|
|
// converto un pezzo alla volta...
|
|
answ[0] = (short)convHD(fullVal.Substring(4, 4));
|
|
answ[1] = (short)convHD(fullVal.Substring(0, 4));
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// estende l'init della classe base...
|
|
/// </summary>
|
|
/// <param name="caller"></param>
|
|
/// <param name="adpConf"></param>
|
|
public IobOmron(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
|
{
|
|
// gestione invio ritardato contapezzi
|
|
pzCountDelay = utils.CRI("pzCountDelay");
|
|
lastPzCountSend = DateTime.Now;
|
|
lastWarnODL = DateTime.Now;
|
|
|
|
|
|
// test conversione valori...
|
|
short[] valDM = new short[2];
|
|
// cario dati
|
|
valDM[0] = 9472;
|
|
valDM[1] = 1;
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
var testDec = convFromHex(valDM);
|
|
|
|
var testHex = convToHex(testDec);
|
|
|
|
#if false
|
|
OMRON_ref = new OmronFinsTCP.Net.EtherNetPLC();
|
|
OMRON_ref.Link("192.168.250.1", 9600, 500);
|
|
short[] response;
|
|
short[] response2;
|
|
short bit1;
|
|
short bit2;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out response);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out response2);
|
|
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
|
|
|
|
// spostamento memorie: canale 65, 65.0 (era 50.15) x reset fineciclo; 65.1, era 53.10 scrittura pesatura
|
|
OMRON_ref.ReadWord(OmronFinsTCP.Net.PlcMemory.CIO, 0, out bit1);
|
|
OMRON_ref.ReadWord(OmronFinsTCP.Net.PlcMemory.CIO, 4, out bit2);
|
|
|
|
short[] valoriWord = new short[10];
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
valoriWord[i] = (short)i;
|
|
}
|
|
|
|
OMRON_ref.WriteWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 10, valoriWord);
|
|
#endif
|
|
|
|
#if false
|
|
// init connessione
|
|
setConnection();
|
|
#endif
|
|
|
|
// test completo funzionalità OMRON, da TOGLIERE in prod...
|
|
#if DEBUG
|
|
omronFullTest();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Test completo funzioni OMRON
|
|
/// </summary>
|
|
private void omronFullTest()
|
|
{
|
|
// faccio un try-catch di test vari...
|
|
short[] response;
|
|
short[] response2;
|
|
short bit1;
|
|
short bit2;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out response);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out response2);
|
|
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
|
|
|
|
// spostamento memorie: canale 65, 65.0 (era 50.15) x reset fineciclo; 65.1, era 53.10 scrittura pesatura
|
|
OMRON_ref.ReadWord(OmronFinsTCP.Net.PlcMemory.CIO, 0, out bit1);
|
|
OMRON_ref.ReadWord(OmronFinsTCP.Net.PlcMemory.CIO, 4, out bit2);
|
|
|
|
short[] valoriWord = new short[10];
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
valoriWord[i] = (short)i;
|
|
}
|
|
|
|
OMRON_ref.WriteWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 10, valoriWord);
|
|
}
|
|
|
|
|
|
/// <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)
|
|
{
|
|
// Verificare il protocollo: dovrebbe togliere SOLO i task eseguiti...
|
|
Dictionary<string, string> taskDone = new Dictionary<string, string>();
|
|
bool taskOk = false;
|
|
string taskVal = "";
|
|
#if false
|
|
|
|
// cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4
|
|
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.setArt:
|
|
case taskType.setComm:
|
|
case taskType.setProg:
|
|
case taskType.sendWatchDogMes2Plc:
|
|
taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
|
|
break;
|
|
case taskType.forceResetPzCount:
|
|
// reset contapezzi inizio setup
|
|
taskOk = resetContapezziCNC();
|
|
taskVal = taskOk ? "FORCE RESET PZ COUNT" : "FORCE RESET DISABLED | NO EXEC";
|
|
break;
|
|
case taskType.forceSetPzCount:
|
|
// reset contapezzi inizio setup
|
|
int newPzCount = 0;
|
|
int.TryParse(item.Value, out newPzCount);
|
|
if (newPzCount >= 0)
|
|
{
|
|
taskOk = setContapezziCNC(newPzCount);
|
|
taskVal = taskOk ? $"FORCE SET PZ COUNT TO {newPzCount}" : $"FORCE SET PZ COUNT TO {newPzCount} | NO EXEC";
|
|
}
|
|
else
|
|
{
|
|
taskVal = $"ERROR IN FORCE SET PZ COUNT TO {newPzCount}";
|
|
}
|
|
break;
|
|
case taskType.startSetup:
|
|
// reset contapezzi inizio setup
|
|
taskOk = resetContapezziCNC();
|
|
taskVal = taskOk ? "RESET: SETUP START" : "PZ RESET DISABLED | NO EXEC";
|
|
break;
|
|
case taskType.stopSetup:
|
|
// reset contapezzi fine setup // reset contapezzi fine setup SE ESPLICITAMENTE IMPOSTATO
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET_stopSetup") == "TRUE")
|
|
{
|
|
resetContapezziCNC();
|
|
}
|
|
taskVal = taskOk ? "RESET: SETUP END" : "PZ RESET DISABLED | NO EXEC";
|
|
break;
|
|
default:
|
|
taskVal = "SKIPPED | NO EXEC";
|
|
break;
|
|
}
|
|
taskDone.Add(item.Key, taskVal);
|
|
}
|
|
#endif
|
|
|
|
return taskDone;
|
|
}
|
|
/// <summary>
|
|
/// Effettua reset del contapezzi, in questo caso il conteggio dei KG
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool resetContapezziCNC()
|
|
{
|
|
bool answ = false;
|
|
#if false
|
|
// ...SE abilitato da conf IOB
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
|
|
{
|
|
// scrivo valore 0 x il contapezzi
|
|
try
|
|
{
|
|
pzCounter = 0;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in RESET contapezzi OMRON");
|
|
connectionOk = false;
|
|
}
|
|
answ = true;
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile effettuare RESET contapezzi OMRON, mancanza parametro OPT:ENABLE_PZ_RESET");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// Effettua IMPOSTAZIONE FORZATA del contapezzi, in questo caso il conteggio dei KG
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override bool setContapezziCNC(int newPzCount)
|
|
{
|
|
bool answ = false;
|
|
#if false
|
|
// ...SE abilitato da conf IOB
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
|
|
{
|
|
// scrivo valore 0 x il contapezzi
|
|
try
|
|
{
|
|
pzCounter = newPzCount;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in SET contapezzi OMRON");
|
|
connectionOk = false;
|
|
}
|
|
answ = true;
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile effettuare SET contapezzi OMRON, mancanza parametro OPT:ENABLE_PZ_RESET");
|
|
}
|
|
#endif
|
|
return answ;
|
|
}
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Imposto connessione
|
|
/// </summary>
|
|
protected virtual void setConnection()
|
|
{
|
|
// Creo oggetto connessione NC
|
|
parentForm.commPlcActive = true;
|
|
lgInfo("Start init Adapter OMRON all'IP {0} | --> IOB {1}", cIobConf.cncIpAddr, cIobConf.codIOB);
|
|
|
|
// inizializzo correttamente aree memoria secondo CONF - iniFileName
|
|
IniFile fIni = new IniFile(cIobConf.iniFileName);
|
|
|
|
// SE è necessario refresh...
|
|
if (needRefresh)
|
|
{
|
|
lgInfo("Refreshing connection...");
|
|
// ora tento avvio PLC... SE PING OK...
|
|
if (testPing == IPStatus.Success)
|
|
{
|
|
try
|
|
{
|
|
short esitoLink = doConnect();
|
|
lgInfo($"End init Adapter OMRON, esitoLink: {esitoLink}");
|
|
if (utils.CRB("verbose"))
|
|
{
|
|
lgInfo("OMRON CONNESSIONE AVVENUTA");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in INIT OMRON Commu");
|
|
}
|
|
needRefresh = false;
|
|
}
|
|
parentForm.commPlcActive = false;
|
|
}
|
|
}
|
|
#endif
|
|
/// <summary>
|
|
/// Vera connessione ad OMRON
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private short doConnect()
|
|
{
|
|
// avvio un oggetto di comunicazione OMRON
|
|
OMRON_ref = new OmronFinsTCP.Net.EtherNetPLC();
|
|
short port = 9600;
|
|
short.TryParse(cIobConf.cncPort, out port);
|
|
lgInfo($"Chiamata apertura OMRON FINS: {cIobConf.cncIpAddr}:{port}");
|
|
short esitoLink = OMRON_ref.Link(cIobConf.cncIpAddr, port, 500);
|
|
return esitoLink;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Override disconnessione
|
|
/// </summary>
|
|
public override void tryDisconnect()
|
|
{
|
|
if (connectionOk)
|
|
{
|
|
string szStatusConnection = "";
|
|
try
|
|
{
|
|
OMRON_ref.Close();
|
|
connectionOk = false;
|
|
lgInfo(szStatusConnection);
|
|
lgInfo("Effettuata disconnessione adapter OMRON!");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgFatal(exc, "Errore nella disconnessione dall'adapter OMRON");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError("IMPOSSIBILE effettuare disconnessione OMRON: Connessione non disponibile...");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Override connessione
|
|
/// </summary>
|
|
public override void tryConnect()
|
|
{
|
|
if (!connectionOk)
|
|
{
|
|
// controllo che il ping sia stato tentato almeno pingTestSec fa...
|
|
if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
|
|
{
|
|
if (verboseLog || periodicLog)
|
|
{
|
|
lgInfo("OMRON: ConnKO - tryConnect");
|
|
}
|
|
// in primis salvo data ping...
|
|
lastPING = DateTime.Now;
|
|
// se passa il ping faccio il resto...
|
|
if (testPing == IPStatus.Success)
|
|
{
|
|
string szStatusConnection = "";
|
|
try
|
|
{
|
|
// ora provo connessione...
|
|
parentForm.commPlcActive = true;
|
|
short esitoLink = doConnect();
|
|
lgInfo($"szStatusConnection OMRON, esitoLink: {esitoLink}");
|
|
parentForm.commPlcActive = false;
|
|
connectionOk = true;
|
|
// refresh stato allarmi!!!
|
|
if (connectionOk)
|
|
{
|
|
if (adpRunning)
|
|
{
|
|
// carico status allarmi (completo)
|
|
lgInfo("Inizio refresh completo stato allarmi...");
|
|
forceAlarmCheck();
|
|
lgInfo("Completato refresh completo stato allarmi!");
|
|
}
|
|
else
|
|
{
|
|
lgInfo("Connessione OK");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lgError("Impossibile procedere, connessione mancante...");
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgFatal($"Errore nella connessione all'adapter OMRON: {szStatusConnection}{Environment.NewLine}{exc}");
|
|
connectionOk = false;
|
|
lgInfo($"Eccezione in TryConnect, Adapter OMRON NON running, pausa di {utils.CRI("waitRecMSec")} msec prima di ulteriori tentativi di riconnessione");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// loggo no risposta ping ...
|
|
connectionOk = false;
|
|
if (verboseLog || periodicLog)
|
|
{
|
|
lgInfo($"Attenzione: OMRON controllo PING fallito per IP {cIobConf.cncIpAddr}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
needRefresh = true;
|
|
}
|
|
// se non è ancora connesso faccio procesisng memoria caso disconnesso...
|
|
if (!connectionOk)
|
|
{
|
|
// processo semafori ed invio...
|
|
processMemoryDiscon();
|
|
}
|
|
}
|
|
|
|
public override void forceAlarmCheck()
|
|
{
|
|
// controllo tutta la memoria allarmi SE richiesto
|
|
}
|
|
/// <summary>
|
|
/// Oggetto per lettura PESO rilevato (DM20-21)
|
|
/// </summary>
|
|
protected int pesoRilevato
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
short[] valDM;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out valDM);
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
answ = convDHD(valDM[0]) + 10000 * convDHD(valDM[1]);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Oggetto per lettura (DM22-23) /scrittura (DM26-27) PESO RICHIESTO
|
|
/// </summary>
|
|
protected int pesoRichiesto
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
short[] valDM;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out valDM);
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
answ = convDHD(valDM[0]) + 10000 * convDHD(valDM[1]);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
// DA PROVARE!!!
|
|
short[] valDM = new short[2];
|
|
int highVal = value / 10000;
|
|
int lowVal = value - (highVal * 10000);
|
|
valDM[0] = (short)convHD(lowVal.ToString("x"));
|
|
valDM[1] = (short)convHD(highVal.ToString("x"));
|
|
OMRON_ref.WriteWords(OmronFinsTCP.Net.PlcMemory.DM, 26, 2, valDM);
|
|
}
|
|
}
|
|
|
|
#region Metodi specifici (da verificare/completare in implementazione)
|
|
|
|
|
|
/// <summary>
|
|
/// Effettua vero processing contapezzi
|
|
/// </summary>
|
|
public override void processContapezzi()
|
|
{
|
|
if (utils.CRB("enableContapezzi"))
|
|
{
|
|
#if false
|
|
try
|
|
{
|
|
// hard coded... !!!FARE!!! rivedere megio conf
|
|
lastCountCNC = pzCounter;
|
|
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
|
|
if (cIobConf.optPar.Count > 0 && getOptPar("PZCOUNT_MODE") != "")
|
|
{
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
lgError(exc, "Errore in contapezzi OMRON");
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Lettura e log valori x debug
|
|
/// </summary>
|
|
private void readAndLog()
|
|
{
|
|
#if false
|
|
short[] response1;
|
|
short[] response2;
|
|
short bit1;
|
|
short bit2;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out response1);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out response2);
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
|
|
// esempio 12540 --> diviso in 1 | 2540 --> in HEX diventa 1 | 9472, ma il 9472 va su byte[0] e 1 su byte[1]
|
|
|
|
#endif
|
|
|
|
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 8, out memReadCIO);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out memReadDM);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out memReadWR);
|
|
|
|
lgInfo("Effettuata lettura dati CIO");
|
|
foreach (var item in memReadCIO)
|
|
{
|
|
lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}");
|
|
}
|
|
lgInfo("Effettuata lettura dati DM");
|
|
foreach (var item in memReadDM)
|
|
{
|
|
lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}");
|
|
}
|
|
lgInfo("Effettuata lettura dati WR");
|
|
foreach (var item in memReadWR)
|
|
{
|
|
lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}");
|
|
}
|
|
|
|
|
|
|
|
short[] respDM20;
|
|
short[] respDM22;
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 20, 2, out respDM20);
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 22, 2, out respDM22);
|
|
// legge delle coppie di valori INT, vanno trasformati in HEX e POI accodati, dove il primo è x 1 e il secondo x 10000 (in pratica va in testa)
|
|
lgInfo("Effettuata lettura dati respDM20");
|
|
foreach (var item in respDM20)
|
|
{
|
|
lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}");
|
|
}
|
|
lgInfo("Effettuata lettura dati respDM22");
|
|
foreach (var item in respDM22)
|
|
{
|
|
lgInfo($"Valori: {item} --> {baseUtils.binaryForm(item)}");
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// lettura bit semafori
|
|
/// </summary>
|
|
public override void readSemafori()
|
|
{
|
|
base.readSemafori();
|
|
// init obj display
|
|
newDisplayData currDispData = new newDisplayData();
|
|
try
|
|
{
|
|
if (verboseLog)
|
|
{
|
|
lgInfo("inizio read semafori");
|
|
}
|
|
|
|
currDispData.semIn = Semaforo.SV;
|
|
|
|
|
|
// effettuo TUTTE le letture
|
|
OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.CIO, 0, 60, out memReadCIO);
|
|
//OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.DM, 0, 8, out memReadDM);
|
|
//OMRON_ref.ReadWords(OmronFinsTCP.Net.PlcMemory.WR, 0, 8, out memReadWR);
|
|
|
|
|
|
lastCountCNC = pesoRilevato;
|
|
// decodifica e gestione
|
|
decodeToBaseBitmap();
|
|
}
|
|
catch
|
|
{
|
|
currDispData.semIn = Semaforo.SR;
|
|
}
|
|
parentForm.updateFormDisplay(currDispData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verifico se abbia ALMENO un errore...
|
|
/// </summary>
|
|
protected bool hasError
|
|
{
|
|
get
|
|
{
|
|
bool answ = false;
|
|
// controllo primi errori, parto dal primo e poi OR
|
|
answ = answ || ((memReadCIO[0] & (1 << 7)) == 1);
|
|
answ = answ || ((memReadCIO[1] & (1 << 0)) == 1);
|
|
answ = answ || ((memReadCIO[1] & (1 << 1)) == 1);
|
|
answ = answ || ((memReadCIO[1] & (1 << 3)) == 1);
|
|
answ = answ || (memReadCIO[2] > 0);
|
|
answ = answ || ((memReadCIO[3] & (1 << 0)) == 1);
|
|
answ = answ || ((memReadCIO[3] & (1 << 1)) == 1);
|
|
|
|
return answ;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
|
|
/// </summary>
|
|
private void decodeToBaseBitmap()
|
|
{
|
|
// init a zero...
|
|
B_input = 0;
|
|
|
|
|
|
/* -----------------------------------------------------
|
|
* bitmap MAPO
|
|
* B0: POWER_ON
|
|
* B1: RUN
|
|
* B2: pzCount
|
|
* B3: allarme
|
|
* B4: manuale
|
|
* B5: carico SILOS
|
|
* B6: carico AUTOBOTTE
|
|
----------------------------------------------------- */
|
|
// bit 0 (poweron) imposto a 1 SE pingo...
|
|
B_input = testPing == IPStatus.Success ? 1 : 0;
|
|
|
|
|
|
// RUN se CIO_bit 0.01 è 1
|
|
if ((memReadCIO[0] & (1 << 1)) == 1)
|
|
{
|
|
B_input += (1 << 1);
|
|
}
|
|
// ERROR generale (CORREGGERE!)
|
|
if (hasError)
|
|
{
|
|
B_input += (1 << 3);
|
|
}
|
|
|
|
// carico SILOS
|
|
if ((memReadCIO[55] & (1 << 2)) == 1)
|
|
{
|
|
B_input += (1 << 5);
|
|
}
|
|
// carico AUTOBOTTE
|
|
if ((memReadCIO[55] & (1 << 2)) == 1)
|
|
{
|
|
B_input += (1 << 6);
|
|
}
|
|
|
|
// process ODL e contapezzi
|
|
string currODL = "";
|
|
try
|
|
{
|
|
currODL = utils.callUrl(urlGetCurrODL);
|
|
// solo SE HO un ODL...
|
|
if (currODL == "" || currODL == "0")
|
|
{
|
|
if (periodicLog)
|
|
{
|
|
lgInfo(string.Format("OMRON | Lettura ODL andata a vuoto: currODL: {0}", currODL));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// se variato o scaduto timeout log...
|
|
if (periodicLog || (currIdxODL.ToString() != currODL))
|
|
{
|
|
lgInfo(string.Format("OMRON | Lettura ODL, currODL: {0} --> currIdxODL prec: {1}", currODL, currIdxODL));
|
|
}
|
|
// provo a salvare nuovo ODL
|
|
int.TryParse(currODL, out currIdxODL);
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
if (DateTime.Now.Subtract(lastWarnODL).TotalSeconds > 15)
|
|
{
|
|
lgError(exc, "Errore in fase di chiamata URL x ODL corrente | URL chiamato: {0}", urlGetCurrODL);
|
|
lastWarnODL = DateTime.Now;
|
|
}
|
|
}
|
|
#if false
|
|
if (currODL != null && currODL != "" && currODL != "0")
|
|
{
|
|
// ora processo il contapezzi...
|
|
// controllo se è passato intervallo minimo tra 2 controlli/elaborazioni x distanziare invio e ridurre letture
|
|
if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
|
|
{
|
|
// se sono differenti MOSTRO...
|
|
if (lastCountCNC != contapezzi)
|
|
{
|
|
// registro contapezzi
|
|
lgInfo(string.Format("Differenza Contapezzi: READ: {0} | Interno {1}", lastCountCNC, contapezzi));
|
|
}
|
|
// verifico se variato contapezzi... e se passato ritardo minimo...
|
|
if (lastCountCNC > contapezzi)
|
|
{
|
|
// salvo nuovo contapezzi (incremento di 1...)
|
|
contapezzi++;
|
|
// salvo in semaforo!
|
|
B_input += (1 << 2);
|
|
// registro contapezzi
|
|
lgInfo(string.Format("Contapezzi OMRON: {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
|
|
}
|
|
|
|
// invio a server contapezzi (aggiornato)
|
|
string retVal = utils.callUrl(urlSetPzCount + contapezzi.ToString());
|
|
// verifica se tutto OK
|
|
if (retVal != "OK")
|
|
{
|
|
// errore salvataggio contapezzi
|
|
lgInfo(string.Format("Errore salvataggio Contapezzi OMRON {0} | Contapezzi interno {1} | Errore salvataggio: {2}", lastCountCNC, contapezzi, retVal));
|
|
}
|
|
// resetto timer...
|
|
lastPzCountSend = DateTime.Now;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
|
|
{
|
|
lgInfo(string.Format("Attenzione: mancanza ODL non procedo con gestione contapezzi. Contapezzi OMRON {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
|
|
// resetto timer...
|
|
lastPzCountSend = DateTime.Now;
|
|
}
|
|
}
|
|
#endif
|
|
|
|
// log opzionale!
|
|
if (verboseLog)
|
|
{
|
|
lgInfo(string.Format("Trasformazione B_input: {0}", B_input));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero dati dinamici...
|
|
/// </summary>
|
|
public override Dictionary<string, string> getDynData()
|
|
{
|
|
// valore non presente in vers default... se gestito fare override
|
|
Dictionary<string, string> outVal = new Dictionary<string, string>();
|
|
outVal.Add("PESO_RILEVATO", pesoRilevato.ToString());
|
|
outVal.Add("PESO_RICHIESTO", pesoRichiesto.ToString());
|
|
|
|
// leggo e scrivo LOG... !!!FIXME!!! poi togliere
|
|
readAndLog();
|
|
|
|
return outVal;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|