diff --git a/IOB-WIN/IobFanuc.cs b/IOB-WIN/IobFanuc.cs index 84a3f684..fec9c38e 100644 --- a/IOB-WIN/IobFanuc.cs +++ b/IOB-WIN/IobFanuc.cs @@ -30,14 +30,6 @@ namespace IOB_WIN /// protected byte[] MemBlockY = new byte[2]; /// - /// Ultimo invio contapezzi (x invio delayed) - /// - protected DateTime lastPzCountSend; - /// - /// Ritardo minimo x invio contapezzi - /// - protected int pzCountDelay; - /// /// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO /// Dictionary signLUT = new Dictionary(); diff --git a/IOB-WIN/IobGeneric.cs b/IOB-WIN/IobGeneric.cs index 063df4b4..56f0cd05 100644 --- a/IOB-WIN/IobGeneric.cs +++ b/IOB-WIN/IobGeneric.cs @@ -27,6 +27,14 @@ namespace IOB_WIN /// protected Int32 lastCountCNC; /// + /// Ultimo invio contapezzi (x invio delayed) + /// + protected DateTime lastPzCountSend; + /// + /// Ritardo minimo x invio contapezzi + /// + protected int pzCountDelay; + /// /// Abilitazione lettura PrgName /// public bool enablePrgName = true; diff --git a/IOB-WIN/IobSiemensTorri.cs b/IOB-WIN/IobSiemensTorri.cs index e56281fc..85b001ae 100644 --- a/IOB-WIN/IobSiemensTorri.cs +++ b/IOB-WIN/IobSiemensTorri.cs @@ -159,6 +159,10 @@ namespace IOB_WIN /// public IobSiemensTorri(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf) { + // gestione invio ritardato contapezzi + pzCountDelay = utils.CRI("pzCountDelay"); + lastPzCountSend = DateTime.Now; + // init conf _IOBConf = IOBConf; // inizializzo parametri... parametri = new connParamS7Torri() @@ -547,20 +551,42 @@ namespace IOB_WIN { // init a zero... B_input = 0; - - // temporaneamente decodifico HARD CODED... poi implementerò da MemMap... - - // leggo i byte interessati... + // TORRI: leggo i primi 8 bit hard coded... int byteSem = RawInput[0]; - + // azzero i bit NON gestiti (2-5-6-7) + byteSem &= ~(1 << 2); + byteSem &= ~(1 << 5); + byteSem &= ~(1 << 6); + byteSem &= ~(1 << 7); + // salvo infine variabile bit x invio B_input = byteSem; - - // log opzionale! - if (verboseLog) lgInfo(string.Format("Trasformazione B_input: {0}", B_input)); + // 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)) + { + // verifico se variato contapezzi in area STD PAR6711... 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 FANUC: {0} | Contapezzi interno {1}", lastCountCNC, contapezzi)); + } + else if (contapezzi > lastCountCNC) // in questo caso resetto + { + contapezzi = lastCountCNC; + } + // invio a server contapezzi (aggiornato) + utils.callUrl(urlSetPzCount + contapezzi.ToString()); + // resetto timer... + lastPzCountSend = DateTime.Now; + } #if false - // SE SI E' CONNESSO al FANUC allora è 1=powerON... - if (FANUC_ref.Connected) + // SE SI E' CONNESSO al PLC allora è 1=powerON... + if (connectionOk) { B_input += 1 << 0; } @@ -664,29 +690,16 @@ namespace IOB_WIN B_input += 1 << i; } } - -#if false - // da rivedere x gestione contapezzi a bit... - // verifico se si tratta di un segnale contapezzo... nel qual caso conteggio ed invio... - if (currIobConf.optPar["PZCOUNT_MODE"].StartsWith("BIT")) - { - // salvo nuovo contapezzi (incremento di 1...) - contapezzi++; - // invio a server contapezzi (aggiornato) - utils.callUrl(urlSetPzCount + contapezzi.ToString()); - lgInfo("Aggiornato contapezzi: {0}", contapezzi); - // resetto timer... - lastPzCountSend = DateTime.Now; - } -#endif } } } // log opzionale! if (verboseLog) lgInfo(string.Format("Trasformazione B_input: {0}", B_input)); -#endif +#endif + // log opzionale! + if (verboseLog) lgInfo(string.Format("Trasformazione B_input: {0}", B_input)); } /// /// Recupero programma in lavorazione