From 88dcb99b9d49e27568b070eaf8b5922de9be7c6a Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Thu, 18 May 2017 17:27:14 +0200 Subject: [PATCH] commentata chiaata utensili (da rimappare) + fix try/catch letture memorie --- MTC_Adapter/MTC_Adapter/AdapterSiemens.cs | 60 +++++++++++++++++------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs index f68b2e9..78f9ec5 100644 --- a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs +++ b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs @@ -40,10 +40,20 @@ namespace MTC_Adapter public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte Value) { bool answ = false; - // chiamo la versione multibyte... - byte[] ValArray = new byte[1]; - SIEMENSMemRW_Byte(bWrite, MemType, memIndex, ref ValArray); - Value = ValArray[0]; + if (SIEMENS_ref.Connected) + { + try + { + // chiamo la versione multibyte... + byte[] ValArray = new byte[1]; + SIEMENSMemRW_Byte(bWrite, MemType, memIndex, ref ValArray); + Value = ValArray[0]; + } + catch (Exception exc) + { + lg.Error(string.Format("Eccezione in SIEMENSMemRW_Byte: {0}{1}", Environment.NewLine, exc)); + } + } return answ; } /// @@ -63,8 +73,10 @@ namespace MTC_Adapter { answ = SIEMENS_ref.S_RW_Byte(bWrite, MemType, memIndex, ref Value); } - catch - { } + catch (Exception exc) + { + lg.Error(string.Format("Eccezione in SIEMENSMemRW_ByteArray: {0}{1}", Environment.NewLine, exc)); + } } return answ; } @@ -85,8 +97,10 @@ namespace MTC_Adapter { answ = SIEMENS_ref.S_RW_Word(bWrite, MemType, memIndex, ref Value); } - catch - { } + catch (Exception exc) + { + lg.Error(string.Format("Eccezione in SIEMENSMemRW_Word: {0}{1}", Environment.NewLine, exc)); + } } return answ; } @@ -107,8 +121,10 @@ namespace MTC_Adapter { answ = SIEMENS_ref.S_RW_DWord(bWrite, MemType, memIndex, ref Value); } - catch - { } + catch(Exception exc) + { + lg.Error(string.Format("Eccezione in SIEMENSMemRW_DWord: {0}{1}", Environment.NewLine, exc)); + } } return answ; } @@ -643,9 +659,11 @@ namespace MTC_Adapter public override int getDatiUt_step4(ref byte[] int32Mem, int j) { int memIndex = 13100 + 4 * j; +#if false inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref int32Mem); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-VitaRes", int32Mem.Length), DateTime.Now.Subtract(inizio).Ticks); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-VitaRes", int32Mem.Length), DateTime.Now.Subtract(inizio).Ticks); +#endif return memIndex; } /// @@ -657,9 +675,11 @@ namespace MTC_Adapter public override int getDatiUt_step3b(ref byte int8Mem, int j) { int memIndex = 10700 + 1 * j; +#if false inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref int8Mem); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", 8), DateTime.Now.Subtract(inizio).Ticks); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", 8), DateTime.Now.Subtract(inizio).Ticks); +#endif return memIndex; } /// @@ -670,9 +690,11 @@ namespace MTC_Adapter public override int getDatiUt_step3a(ref byte[] tabFam_FamUt) { int memIndex = 8900; +#if false inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref tabFam_FamUt); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabFamUT-FamUT", tabFam_FamUt.Length), DateTime.Now.Subtract(inizio).Ticks); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabFamUT-FamUT", tabFam_FamUt.Length), DateTime.Now.Subtract(inizio).Ticks); +#endif return memIndex; } /// @@ -684,9 +706,11 @@ namespace MTC_Adapter public override int getDatiUt_step2b(ref byte[] int16Mem, int j) { int memIndex = 11700 + 2 * j; +#if false inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref int16Mem); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", int16Mem.Length), DateTime.Now.Subtract(inizio).Ticks); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", int16Mem.Length), DateTime.Now.Subtract(inizio).Ticks); +#endif return memIndex; } /// @@ -697,9 +721,11 @@ namespace MTC_Adapter public override int getDatiUt_step2a(ref byte[] tabUt_UT) { int memIndex = 11300; +#if false inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref tabUt_UT); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-UT", tabUt_UT.Length), DateTime.Now.Subtract(inizio).Ticks); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-UT", tabUt_UT.Length), DateTime.Now.Subtract(inizio).Ticks); +#endif return memIndex; } /// @@ -710,9 +736,11 @@ namespace MTC_Adapter public override int getDatiUt_step1(ref byte[] elencoUtMem) { int memIndex = 2960; +#if false inizio = DateTime.Now; SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref elencoUtMem); - if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-NUMUT", elencoUtMem.Length), DateTime.Now.Subtract(inizio).Ticks); + if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-NUMUT", elencoUtMem.Length), DateTime.Now.Subtract(inizio).Ticks); +#endif return memIndex; }