diff --git a/MTC_Adapter/.vs/MTC_Adapter.sqlite b/MTC_Adapter/.vs/MTC_Adapter.sqlite index 8f4e3b5..876f78a 100644 Binary files a/MTC_Adapter/.vs/MTC_Adapter.sqlite and b/MTC_Adapter/.vs/MTC_Adapter.sqlite differ diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs index c2f3bf8..0578886 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs @@ -862,10 +862,20 @@ namespace MTC_Adapter bool needSave = false; // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 14000; - byte[] tabDatiMtz = new byte[4 * maintData.Length]; + byte[] tabDatiMtzByte = new byte[4 * maintData.Length]; + uint[] tabDatiMtz = new uint[maintData.Length]; inizio = DateTime.Now; - FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiMtz); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiMtz", tabDatiMtz.Length), DateTime.Now.Subtract(inizio).Ticks); + FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiMtzByte); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiMtz", tabDatiMtzByte.Length), DateTime.Now.Subtract(inizio).Ticks); + // copio byte --> word! + Buffer.BlockCopy(tabDatiMtzByte, 0, tabDatiMtz, 0, tabDatiMtzByte.Length); + // decodifico aree memoria secondo tab configurazione + processMaintData(tabDatiMtz, maintData); + // verifica se debba salvare e mostrare dati + checkSavePersDataLayer(); + + // vecchia gestione con shift & co, ora gestito come OSAI con metodo da AdapterGeneric... +#if false // uno ad uno vado a inserirli nella mappa dei dati dell'adapter... int shift = 4; // 32bit int numero = 0; @@ -879,11 +889,11 @@ namespace MTC_Adapter if (maintData[i].varName == "ACC_TIME") { - istOreMaccOn = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istOreMaccOn = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } else if (maintData[i].varName == "ACC_TIME_WORK") { - istOreMaccLav = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istOreMaccLav = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } else if (maintData[i].varName.StartsWith("Path_")) { @@ -898,7 +908,7 @@ namespace MTC_Adapter } if (numero > 0) { - vettPath[numero - 1].mPathPartCount.Value = BitConverter.ToUInt32(tabDatiMtz, shift * i); + vettPath[numero - 1].mPathPartCount.Value = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } } @@ -914,7 +924,7 @@ namespace MTC_Adapter { } if (numero > 0) { - istDistMovAssi[numero - 1] = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istDistMovAssi[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } else if (maintData[i].varName.EndsWith("_Invers")) @@ -930,7 +940,7 @@ namespace MTC_Adapter // 2016.07.06 debug di valori che potrebbero essere nulli... try { - valRead = BitConverter.ToUInt32(tabDatiMtz, shift * i); + valRead = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } catch (Exception exc) { @@ -953,7 +963,7 @@ namespace MTC_Adapter // 2016.07.06 debug di valori che potrebbero essere nulli... try { - valRead = BitConverter.ToUInt32(tabDatiMtz, shift * i); + valRead = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } catch (Exception exc) { @@ -976,7 +986,7 @@ namespace MTC_Adapter { } if (numero > 0) { - istGiriElettrom[numero - 1] = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istGiriElettrom[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } else if (maintData[i].varName.EndsWith("_NumCambiUT")) @@ -989,7 +999,7 @@ namespace MTC_Adapter { } if (numero > 0) { - istNumCambiUt[numero - 1] = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istNumCambiUt[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } } @@ -1005,7 +1015,7 @@ namespace MTC_Adapter { } if (numero > 0) { - istVacPumpWrkTime[numero - 1] = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istVacPumpWrkTime[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } } @@ -1021,7 +1031,7 @@ namespace MTC_Adapter { } if (numero > 0) { - istVacActCount[numero - 1] = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istVacActCount[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } } @@ -1037,7 +1047,7 @@ namespace MTC_Adapter { } if (numero > 0) { - istLubroCount[numero - 1] = BitConverter.ToUInt32(tabDatiMtz, shift * i); + istLubroCount[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i); } } } @@ -1063,8 +1073,8 @@ namespace MTC_Adapter // salvo se necessario! if (needSave) parentForm.persistData(); // ------------------------------------------- - } - + } +#endif } /// diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs index 11d7786..c587c51 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs @@ -1954,6 +1954,214 @@ namespace MTC_Adapter { // da gestire su ogni adapter... legge tutto array STROBE!!! } + /// + /// Processa la tabella di memoria dei dati di manutenzione + /// + /// + public void processMaintData(uint[] tabDatiMtz, otherData[] maintData) + { + // uno ad uno vado a inserirli nella mappa dei dati dell'adapter... + int numero = 0; + uint valRead = 0; + for (int i = 0; i < maintData.Length; i++) + { + numero = 0; + valRead = 0; + + if (maintData[i].varName == "ACC_TIME") + { + istOreMaccOn = tabDatiMtz[i]; + } + else if (maintData[i].varName == "ACC_TIME_WORK") + { + istOreMaccLav = tabDatiMtz[i]; + } + else if (maintData[i].varName.StartsWith("Path_")) + { + if (maintData[i].varName.EndsWith("_PZ_TOT")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("Path_", "").Replace("_PZ_TOT", "")); + } + catch + { + } + if (numero > 0) + { + vettPath[numero - 1].mPathPartCount.Value = tabDatiMtz[i]; + } + } + } + else if (maintData[i].varName.StartsWith("Axis_")) + { + if (maintData[i].varName.EndsWith("_DistDone")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_DistDone", "")); + } + catch + { } + if (numero > 0) + { + istDistMovAssi[numero - 1] = tabDatiMtz[i]; + } + } + else if (maintData[i].varName.EndsWith("_Invers")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_Invers", "")); + } + catch + { } + if (numero > 0) + { + // 2016.07.06 debug di valori che potrebbero essere nulli... + try + { + valRead = tabDatiMtz[i]; + } + catch (Exception exc) + { + valRead = 0; + lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}i: {2}{0}Exc: {3}", Environment.NewLine, maintData[i].varName, i, exc)); + } + istNumInvAssi[numero - 1] = valRead; + } + } + else if (maintData[i].varName.EndsWith("_AccTime")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_AccTime", "")); + } + catch + { } + if (numero > 0) + { + // 2016.07.06 debug di valori che potrebbero essere nulli... + try + { + valRead = tabDatiMtz[i]; + } + catch (Exception exc) + { + valRead = 0; + lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}i: {2}{0}Exc: {3}", Environment.NewLine, maintData[i].varName, i, exc)); + } + istAccTimeAssi[numero - 1] = valRead; + } + } + } + else if (maintData[i].varName.StartsWith("UnOp_")) + { + if (maintData[i].varName.EndsWith("_AccTime")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("UnOp_", "").Replace("_AccTime", "")); + } + catch + { } + if (numero > 0) + { + istGiriElettrom[numero - 1] = tabDatiMtz[i]; + } + } + else if (maintData[i].varName.EndsWith("_NumCambiUT")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("UnOp_", "").Replace("_NumCambiUT", "")); + } + catch + { } + if (numero > 0) + { + istNumCambiUt[numero - 1] = tabDatiMtz[i]; + } + } + } + else if (maintData[i].varName.StartsWith("VacPump_")) + { + if (maintData[i].varName.EndsWith("_WrkTime")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("VacPump_", "").Replace("_WrkTime", "")); + } + catch + { } + if (numero > 0) + { + istVacPumpWrkTime[numero - 1] = tabDatiMtz[i]; + } + } + } + else if (maintData[i].varName.StartsWith("VacAct_")) + { + if (maintData[i].varName.EndsWith("_Count")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("VacAct_", "").Replace("_Count", "")); + } + catch + { } + if (numero > 0) + { + istVacActCount[numero - 1] = tabDatiMtz[i]; + } + } + } + else if (maintData[i].varName.StartsWith("Lubro_")) + { + if (maintData[i].varName.EndsWith("_Num")) + { + try + { + numero = Convert.ToInt32(maintData[i].varName.Replace("Lubro_", "").Replace("_Num", "")); + } + catch + { } + if (numero > 0) + { + istLubroCount[numero - 1] = tabDatiMtz[i]; + } + } + } + } + } + /// + /// processa dataLayer e se necessario salva/mostra + /// + public void checkSavePersDataLayer() + { + if (persistenceLayer != null) + { + bool needSave = false; + // verifica se si debba aggiornare XML (e salva in adapter dati vari) + needSave = procOreMaccOn(needSave); + needSave = procOreMaccLav(needSave); + needSave = procProgrName(needSave); + needSave = procPartId(needSave); + needSave = procPzProd(needSave); + needSave = procGiriTotUnOp(needSave); + needSave = procNumCU(needSave); + needSave = procMovTotAssi(needSave); + needSave = procAccTimeAssi(needSave); + needSave = procNumInvAssi(needSave); + needSave = procVacPump(needSave); + needSave = procVacAct(needSave); + needSave = procLubro(needSave); + + // salvo se necessario! + if (needSave) parentForm.persistData(); + // ------------------------------------------- + } + } #endregion diff --git a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs index 197d70c..76d23d5 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs @@ -1108,210 +1108,19 @@ namespace MTC_Adapter /// private void getMtzDataFromPlc() { - bool needSave = false; // recupero i dati di manutenzione dall'area di memoria IN BLOCCO int memIndex = 19166; uint[] tabDatiMtz = new uint[maintData.Length]; inizio = DateTime.Now; OsaiMemRW_DWord(R, OSAI.MemTypeWord.MW_CODE, memIndex, ref tabDatiMtz); if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiMtz", tabDatiMtz.Length * 4), DateTime.Now.Subtract(inizio).Ticks); - // uno ad uno vado a inserirli nella mappa dei dati dell'adapter... - int numero = 0; - uint valRead = 0; - for (int i = 0; i < maintData.Length; i++) - { - numero = 0; - valRead = 0; - - if (maintData[i].varName == "ACC_TIME") - { - istOreMaccOn = tabDatiMtz[i]; - } - else if (maintData[i].varName == "ACC_TIME_WORK") - { - istOreMaccLav = tabDatiMtz[i]; - } - else if (maintData[i].varName.StartsWith("Path_")) - { - if (maintData[i].varName.EndsWith("_PZ_TOT")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("Path_", "").Replace("_PZ_TOT", "")); - } - catch - { - } - if (numero > 0) - { - vettPath[numero - 1].mPathPartCount.Value = tabDatiMtz[i]; - } - } - } - else if (maintData[i].varName.StartsWith("Axis_")) - { - if (maintData[i].varName.EndsWith("_DistDone")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_DistDone", "")); - } - catch - { } - if (numero > 0) - { - istDistMovAssi[numero - 1] = tabDatiMtz[i]; - } - } - else if (maintData[i].varName.EndsWith("_Invers")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_Invers", "")); - } - catch - { } - if (numero > 0) - { - // 2016.07.06 debug di valori che potrebbero essere nulli... - try - { - valRead = tabDatiMtz[i]; - } - catch (Exception exc) - { - valRead = 0; - lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}i: {2}{0}Exc: {3}", Environment.NewLine, maintData[i].varName, i, exc)); - } - istNumInvAssi[numero - 1] = valRead; - } - } - else if (maintData[i].varName.EndsWith("_AccTime")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_AccTime", "")); - } - catch - { } - if (numero > 0) - { - // 2016.07.06 debug di valori che potrebbero essere nulli... - try - { - valRead = tabDatiMtz[i]; - } - catch (Exception exc) - { - valRead = 0; - lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}i: {2}{0}Exc: {3}", Environment.NewLine, maintData[i].varName, i, exc)); - } - istAccTimeAssi[numero - 1] = valRead; - } - } - } - else if (maintData[i].varName.StartsWith("UnOp_")) - { - if (maintData[i].varName.EndsWith("_AccTime")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("UnOp_", "").Replace("_AccTime", "")); - } - catch - { } - if (numero > 0) - { - istGiriElettrom[numero - 1] = tabDatiMtz[i]; - } - } - else if (maintData[i].varName.EndsWith("_NumCambiUT")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("UnOp_", "").Replace("_NumCambiUT", "")); - } - catch - { } - if (numero > 0) - { - istNumCambiUt[numero - 1] = tabDatiMtz[i]; - } - } - } - else if (maintData[i].varName.StartsWith("VacPump_")) - { - if (maintData[i].varName.EndsWith("_WrkTime")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("VacPump_", "").Replace("_WrkTime", "")); - } - catch - { } - if (numero > 0) - { - istVacPumpWrkTime[numero - 1] = tabDatiMtz[i]; - } - } - } - else if (maintData[i].varName.StartsWith("VacAct_")) - { - if (maintData[i].varName.EndsWith("_Count")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("VacAct_", "").Replace("_Count", "")); - } - catch - { } - if (numero > 0) - { - istVacActCount[numero - 1] = tabDatiMtz[i]; - } - } - } - else if (maintData[i].varName.StartsWith("Lubro_")) - { - if (maintData[i].varName.EndsWith("_Num")) - { - try - { - numero = Convert.ToInt32(maintData[i].varName.Replace("Lubro_", "").Replace("_Num", "")); - } - catch - { } - if (numero > 0) - { - istLubroCount[numero - 1] = tabDatiMtz[i]; - } - } - } - } - - if (persistenceLayer != null) - { - // verifica se si debba aggiornare XML (e salva in adapter dati vari) - needSave = procOreMaccOn(needSave); - needSave = procOreMaccLav(needSave); - needSave = procProgrName(needSave); - needSave = procPartId(needSave); - needSave = procPzProd(needSave); - needSave = procGiriTotUnOp(needSave); - needSave = procNumCU(needSave); - needSave = procMovTotAssi(needSave); - needSave = procAccTimeAssi(needSave); - needSave = procNumInvAssi(needSave); - needSave = procVacPump(needSave); - needSave = procVacAct(needSave); - needSave = procLubro(needSave); - - // salvo se necessario! - if (needSave) parentForm.persistData(); - // ------------------------------------------- - } - + // decodifico aree memoria secondo tab configurazione + processMaintData(tabDatiMtz, maintData); + // verifica se debba salvare e mostrare dati + checkSavePersDataLayer(); } + + /// /// Gestione lettura dati status da PLC ///