From 975e2677691f778ffc1df806a58203377f122d3b Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 16 May 2017 17:09:47 +0200 Subject: [PATCH] portato in generic procPathStrobe --- MTC_Adapter/MTC_Adapter/AdapterDemo.cs | 1 - MTC_Adapter/MTC_Adapter/AdapterFanuc.cs | 2 - MTC_Adapter/MTC_Adapter/AdapterGeneric.cs | 127 +++++++++++++++++++- MTC_Adapter/MTC_Adapter/AdapterOsai.cs | 6 +- MTC_Adapter/MTC_Adapter/AdapterSiemens.cs | 134 +++++++--------------- 5 files changed, 167 insertions(+), 103 deletions(-) diff --git a/MTC_Adapter/MTC_Adapter/AdapterDemo.cs b/MTC_Adapter/MTC_Adapter/AdapterDemo.cs index b7d3349..9db78a4 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterDemo.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterDemo.cs @@ -83,7 +83,6 @@ namespace MTC_Adapter public override void processStrobe() { - base.processStrobe(); // qui forzo la gestione di update dei path & co... getPath(); getUnOp(); diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs index 8ba96a4..50b241a 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs @@ -203,8 +203,6 @@ namespace MTC_Adapter /// public override void processStrobe() { - base.processStrobe(); - // inizializzo userAction string UserAction = ""; string TestingData = ""; diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index f2c915e..e91ee59 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -966,7 +966,7 @@ namespace MTC_Adapter public List[] codaT; #endregion - + #region Events & samples /// @@ -1613,7 +1613,7 @@ namespace MTC_Adapter } #region metodi adapter - + /// /// lettura file di persistenza @@ -2504,7 +2504,128 @@ namespace MTC_Adapter /// public virtual void processStrobe() { - // da gestire su ogni adapter... + // ...da gestire su ogni adapter... + } + /// + /// Processa strobe x un dato path + /// + /// path corrente + /// Byte di strobe del path corrente + /// Byte di strobe del path corrente + /// indice x lettura memoria MST del path + /// indice x scrittura ACK x path + /// stringa COMPLESSIVA azioni utente + public void procPathStrobes(int idxPath, StFlag8 currStrobe, StFlag8 currAck, int memIndexMST, int memIndexAck, ref string UserAction) + { + // byte di strobe e di acknowledge... inizializzo!!! + byte[] currACK_DW = new byte[1]; + // altre variabili + int bitNum = 0; + inizio = DateTime.Now; + // incomincio vera e propria gestione... + try + { + // controllo TUTTI i flag: se ce ne sono di alzati DEVO processare... + if (currStrobe != StFlag8.NONE) + { + // se ho un M/S/T leggo area... + if (currStrobe.HasFlag(StFlag8.B0) || currStrobe.HasFlag(StFlag8.B1) || currStrobe.HasFlag(StFlag8.B2)) + { + + // blocco memoria x lettura TUTTI i dati di buffer M/S/T: 26 short(16bit) x (12+7+7) aree (attenzione: secondo set di 2 bit è VUOTO...) + ushort[] MemBlock_W = new ushort[26]; + // leggo memoria! + readMST_data(idxPath, memIndexMST, ref MemBlock_W); + + // converto a byte x compatibilità... + byte[] MemBlock = new byte[MemBlock_W.Length * 2]; + Buffer.BlockCopy(MemBlock_W, 0, MemBlock, 0, MemBlock.Length); + + // check COD_M + bitNum = 0; + gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 0, MemBlock, "M", idxPath); + + // check COD_S + bitNum = 1; + gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 12, MemBlock, "S", idxPath); + + // check COD_T + bitNum = 2; + gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 19, MemBlock, "T", idxPath); + + } + + // check FILE DATI MODIFICATO: ricaricare... + bitNum = 3; + if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum))) + { + lg.Info("Notifica file modificato"); + try + { + // reload dati da file... + reloadDataFromFile(); + + // memorizzo allarme nel vettore ack.... + currACK_DW = utils.setBitOnStFlag(currACK_DW, true, bitNum); + } + catch + { + lg.Info("Errore lettura dati da file"); + } + } + + // AREA strobe USER ACTION + // chiamato Start... + bitNum = 4; + gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} START) ", idxPath)); + // chiamato Stop... + bitNum = 5; + gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} STOP) ", idxPath)); + // chiamato Reset... + bitNum = 6; + gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} RESET) ", idxPath)); + + } + else + { + // inizializzo 4 byte a zero!!! + currACK_DW = new byte[1]; + } + } + catch (Exception exc) + { + lg.Error(string.Format("Errore in strobe:{0}{1}", Environment.NewLine, exc)); + } + + // scrivo update ad ack SE VARIATO!!! + if (currAck != (StFlag8)currACK_DW[0]) + { + writeMST_ACK(memIndexAck, ref currACK_DW); + } + } + /// + /// Legge area memoria dati MST + /// + /// + /// + /// + /// + public virtual bool readMST_data(int idxPath, int memIndexMST, ref ushort[] MemBlock_W) + { + bool fatto = false; + return fatto; + } + /// + /// Scrive ACK x dati MST + /// + /// + /// + /// + /// + public virtual bool writeMST_ACK(int memIndexAck, ref byte[] currACK_DW) + { + bool fatto = false; + return fatto; } /// /// processo il vettore LOCALE degli allarmi diff --git a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs index a8c6c7e..c091be6 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs @@ -307,8 +307,6 @@ namespace MTC_Adapter /// public override void processStrobe() { - base.processStrobe(); - // inizializzo userAction string UserAction = ""; // oggetti "accessori" x processing (1 byte di strobe x ogni path) @@ -343,6 +341,7 @@ namespace MTC_Adapter // gestione bit di watchdog... sulal DWord successiva sendWatchDog(); } +#if false /// /// Processa strobe x un dato path /// @@ -444,7 +443,8 @@ namespace MTC_Adapter OsaiMemRW_Byte(W, OSAI.MemTypeWord.MW_CODE, memIndexAck, 0, ref currACK_DW); if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", currACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks); } - } + } +#endif /// /// Verifica strobe autotest /// diff --git a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs index 2f061f8..4836aa7 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs @@ -28,6 +28,7 @@ namespace MTC_Adapter /// protected int baseMemUO = 254; + /// /// wrapper chiamata lettura/scrittura SINGOLO BYTE... /// @@ -150,6 +151,7 @@ namespace MTC_Adapter tryConnect(); lg.Info("End init Adapter SIEMENS"); } + /// /// Override disconnessione /// @@ -259,8 +261,6 @@ namespace MTC_Adapter /// public override void processStrobe() { - base.processStrobe(); - // inizializzo userAction string UserAction = ""; // oggetti "accessori" x processing (1 byte di strobe x ogni path) @@ -296,107 +296,53 @@ namespace MTC_Adapter sendWatchDog(); } /// - /// Processa strobe x un dato path + /// Scrive ACK x dati MST /// - /// path corrente - /// Byte di strobe del path corrente - /// Byte di strobe del path corrente - /// indice x lettura memoria MST del path - /// indice x scrittura ACK x path - /// stringa COMPLESSIVA azioni utente - private void procPathStrobes(int idxPath, StFlag8 currStrobe, StFlag8 currAck, int memIndexMST, int memIndexAck, ref string UserAction) + /// + /// + /// + /// + public override bool writeMST_ACK(int memIndexAck, ref byte[] currACK_DW) { - // byte di strobe e di acknowledge... inizializzo!!! - byte[] currACK_DW = new byte[1]; - // altre variabili - int bitNum = 0; - inizio = DateTime.Now; - // incomincio vera e propria gestione... + bool fatto = false; try - { - // controllo TUTTI i flag: se ce ne sono di alzati DEVO processare... - if (currStrobe != StFlag8.NONE) - { - // se ho un M/S/T leggo area... - if (currStrobe.HasFlag(StFlag8.B0) || currStrobe.HasFlag(StFlag8.B1) || currStrobe.HasFlag(StFlag8.B2)) - { - - // blocco memoria x lettura TUTTI i dati di buffer M/S/T: 26 short(16bit) x (12+7+7) aree (attenzione: secondo set di 2 bit è VUOTO...) - ushort[] MemBlock_W = new ushort[26]; - - // leggo tutto!!! - inizio = DateTime.Now; - SIEMENSMemRW_Word(R, baseMemDb, memIndexMST, ref MemBlock_W); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW1-P{1:00}", MemBlock_W.Length, idxPath), DateTime.Now.Subtract(inizio).Ticks); - - // converto a byte x compatibilità... - byte[] MemBlock = new byte[MemBlock_W.Length * 2]; - Buffer.BlockCopy(MemBlock_W, 0, MemBlock, 0, MemBlock.Length); - - // check COD_M - bitNum = 0; - gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 0, MemBlock, "M", idxPath); - - // check COD_S - bitNum = 1; - gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 12, MemBlock, "S", idxPath); - - // check COD_T - bitNum = 2; - gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 19, MemBlock, "T", idxPath); - - } - - // check FILE DATI MODIFICATO: ricaricare... - bitNum = 3; - if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum))) - { - lg.Info("Notifica file modificato"); - try - { - // reload dati da file... - reloadDataFromFile(); - - // memorizzo allarme nel vettore ack.... - currACK_DW = utils.setBitOnStFlag(currACK_DW, true, bitNum); - } - catch - { - lg.Info("Errore lettura dati da file"); - } - } - - // AREA strobe USER ACTION - // chiamato Start... - bitNum = 4; - gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} START) ", idxPath)); - // chiamato Stop... - bitNum = 5; - gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} STOP) ", idxPath)); - // chiamato Reset... - bitNum = 6; - gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} RESET) ", idxPath)); - - } - else - { - // inizializzo 4 byte a zero!!! - currACK_DW = new byte[1]; - } - } - catch (Exception exc) - { - lg.Error(string.Format("Errore in strobe:{0}{1}", Environment.NewLine, exc)); - } - - // scrivo update ad ack SE VARIATO!!! - if (currAck != (StFlag8)currACK_DW[0]) { inizio = DateTime.Now; SIEMENSMemRW_Byte(W, baseMemDb, memIndexAck, ref currACK_DW); if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", currACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks); + fatto = true; } + catch (Exception exc) + { + lg.Error(string.Format("Errore in scrittura dati ACK MST:{0}{1}", Environment.NewLine, exc)); + } + return fatto; } + /// + /// Legge area memoria dati MST + /// + /// + /// + /// + /// + public override bool readMST_data(int idxPath, int memIndexMST, ref ushort[] MemBlock_W) + { + bool fatto = false; + try + { + // leggo tutto!!! + inizio = DateTime.Now; + SIEMENSMemRW_Word(R, baseMemDb, memIndexMST, ref MemBlock_W); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW1-P{1:00}", MemBlock_W.Length, idxPath), DateTime.Now.Subtract(inizio).Ticks); + fatto = true; + } + catch (Exception exc) + { + lg.Error(string.Format("Errore in lettura dati MST:{0}{1}", Environment.NewLine, exc)); + } + return fatto; + } + /// /// Verifica strobe autotest ///