From 293eaf4ab6e6accea8ae717f39ef099d0bbe231f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 24 Oct 2020 15:26:23 +0200 Subject: [PATCH 1/3] New write call mockup 4 TCam --- CMS_CORE_Library/NcThermo.cs | 20 ++++++++-- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 61 ++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index bb125ad..2e2f572 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -685,17 +685,29 @@ namespace CMS_CORE_Library /// public abstract CmsError PLC_WWarmerChSetpHmi(Dictionary newData); /// - /// Set current Warmers Channels ThermocamSetpoints (°C) + /// Set current Warmers Channels Temperature Set as reference (°C) /// /// /// - public abstract CmsError PLC_WWarmerChTCamSetp(Dictionary newData); + public abstract CmsError PLC_WWarmerChTCamTempSet(Dictionary newData); /// - /// Set current Warmers Channels Thermocam read (actual) value (°C) + /// Set current Warmers Channels Thermocam LAST READ value (°C) /// /// /// - public abstract CmsError PLC_WWarmerChTCamActual(Dictionary newData); + public abstract CmsError PLC_WWarmerChTCamTempAct(Dictionary newData); + /// + /// Set current Warmers Channels as enabled/disabled for working with thermo camera data + /// + /// + /// + public abstract CmsError PLC_WWarmerChTCamEnab(Dictionary newData); + /// + /// Set ThermoCamera mode + /// + /// + /// + public abstract CmsError PLC_WTCamMode(bool enableTCam); /// /// Set current Warmers Channels reflector's data /// diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 41073c7..8a5780a 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2373,7 +2373,7 @@ namespace CMS_CORE_Library.S7Net refreshRiscTermoCamTempAct(); // refresh temp canale impostata x thermoCam | Write refreshRiscTermoCamTempSet(); - } + } // copio lista act in output currWarmerChannelList = ThermoWarmChannels; @@ -3129,7 +3129,7 @@ namespace CMS_CORE_Library.S7Net else { libraryError = S7_PLC_EMPTY_READ; - } + } } /// /// Refresh Canali Riscaldi: SetPoint HMI @@ -3355,7 +3355,7 @@ namespace CMS_CORE_Library.S7Net /// /// /// - public override CmsError PLC_WWarmerChTCamSetp(Dictionary newData) + public override CmsError PLC_WWarmerChTCamTempSet(Dictionary newData) { // FIXME TODO serve nuova area termocamera #if false @@ -3390,7 +3390,7 @@ namespace CMS_CORE_Library.S7Net /// /// /// - public override CmsError PLC_WWarmerChTCamActual(Dictionary newData) + public override CmsError PLC_WWarmerChTCamTempAct(Dictionary newData) { // FIXME TODO serve nuova area termocamera #if false @@ -3420,6 +3420,59 @@ namespace CMS_CORE_Library.S7Net return NO_ERROR; } + + + /// + /// Set current Warmers Channels as enabled/disabled for working with thermo camera data + /// + /// + /// + public override CmsError PLC_WWarmerChTCamEnab(Dictionary newData) + { + // FIXME TODO serve nuova area termocamera +#if false + // memory area + byte[] newMem = new byte[newData.Count]; + List currMem = new List(); + + // read actual data on memory... + CmsError libraryError = MEM_RWByteList(R, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); + if (libraryError.IsError()) + return libraryError; + + newMem = currMem.ToArray(); + + // update only given data... + foreach (var item in newData) + { + newMem[item.Key - 1] = (byte)item.Value; + } + // return as list... + currMem = newMem.ToList(); + // scrivo sul PLC array di byte... + libraryError = MEM_RWByteList(W, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); + if (libraryError.IsError()) + return libraryError; +#endif + + return NO_ERROR; + } + + + /// + /// Set ThermoCamera mode + /// + /// + /// + public override CmsError PLC_WTCamMode(bool enableTCam) + { +#if false + +#endif + + return NO_ERROR; + } + /// /// Set current Warmers Channels reflector's data /// From ca6dde4614b3518013265e4abaf98b6efc572fcb Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 24 Oct 2020 15:39:48 +0200 Subject: [PATCH 2/3] Prototipe for Temp ThermoCam write --- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 48 +++++++++++++++++------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 8a5780a..2ae830f 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -3351,20 +3351,22 @@ namespace CMS_CORE_Library.S7Net return NO_ERROR; } /// - /// Set current Warmers Channels ThermocamSetpoints (°C) + /// Set current Warmers Channels Temp REF Setpoints (1/10 °C) /// /// /// public override CmsError PLC_WWarmerChTCamTempSet(Dictionary newData) { - // FIXME TODO serve nuova area termocamera -#if false + // valori in 1/10 di °C + int dataScale = 10; // memory area - byte[] newMem = new byte[newData.Count]; - List currMem = new List(); + short[] newMem = new short[newData.Count]; + // leggo DB624 x Setpoint Temp richiesti + List currMem = new List(); + + // leggo da PLC a array di byte di appoggio... + CmsError libraryError = MEM_RWShortList(R, 0, TCAM_TEMP_REQ_DATA.MemType, TCAM_TEMP_REQ_DATA.Address, TCAM_TEMP_REQ_DATA.SubAddress, TCAM_TEMP_REQ_DATA.Size, ref currMem); - // read actual data on memory... - CmsError libraryError = MEM_RWByteList(R, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); if (libraryError.IsError()) return libraryError; @@ -3373,15 +3375,16 @@ namespace CMS_CORE_Library.S7Net // update only given data... foreach (var item in newData) { - newMem[item.Key - 1] = (byte)item.Value; + // attenzione: effettua scalatura dati! + newMem[item.Key - 1] = (short)(dataScale * item.Value); } // return as list... currMem = newMem.ToList(); + // scrivo sul PLC array di byte... - libraryError = MEM_RWByteList(W, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); + libraryError = MEM_RWShortList(W, 0, TCAM_TEMP_REQ_DATA.MemType, TCAM_TEMP_REQ_DATA.Address, TCAM_TEMP_REQ_DATA.SubAddress, TCAM_TEMP_REQ_DATA.Size, ref currMem); if (libraryError.IsError()) - return libraryError; -#endif + return libraryError; return NO_ERROR; } @@ -3392,14 +3395,16 @@ namespace CMS_CORE_Library.S7Net /// public override CmsError PLC_WWarmerChTCamTempAct(Dictionary newData) { - // FIXME TODO serve nuova area termocamera -#if false + // valori in 1/10 di °C + int dataScale = 10; // memory area - byte[] newMem = new byte[newData.Count]; - List currMem = new List(); + short[] newMem = new short[newData.Count]; + // leggo DB624 x Setpoint Temp richiesti + List currMem = new List(); + + // leggo da PLC a array di byte di appoggio... + CmsError libraryError = MEM_RWShortList(R, 0, TCAM_TEMP_ACT_DATA.MemType, TCAM_TEMP_ACT_DATA.Address, TCAM_TEMP_ACT_DATA.SubAddress, TCAM_TEMP_ACT_DATA.Size, ref currMem); - // read actual data on memory... - CmsError libraryError = MEM_RWByteList(R, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); if (libraryError.IsError()) return libraryError; @@ -3408,15 +3413,16 @@ namespace CMS_CORE_Library.S7Net // update only given data... foreach (var item in newData) { - newMem[item.Key - 1] = (byte)item.Value; + // attenzione: effettua scalatura dati! + newMem[item.Key - 1] = (short)(dataScale * item.Value); } // return as list... currMem = newMem.ToList(); + // scrivo sul PLC array di byte... - libraryError = MEM_RWByteList(W, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); + libraryError = MEM_RWShortList(W, 0, TCAM_TEMP_ACT_DATA.MemType, TCAM_TEMP_ACT_DATA.Address, TCAM_TEMP_ACT_DATA.SubAddress, TCAM_TEMP_ACT_DATA.Size, ref currMem); if (libraryError.IsError()) - return libraryError; -#endif + return libraryError; return NO_ERROR; } From 481e4323568e2b63a90536d1ad36c9d0602ddaca Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 24 Oct 2020 16:07:43 +0200 Subject: [PATCH 3/3] Scratch write enab TCam Ch --- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 32 +++++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 2ae830f..7f4b3bc 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2368,7 +2368,7 @@ namespace CMS_CORE_Library.S7Net if (!useCache) { // refresh abilitazione canale x thermoCam | Write - refreshRiscTermoCamAbilit(); + refreshRiscTermoCamEnab(); // refresh ultima temp canale letta da thermoCam | Write refreshRiscTermoCamTempAct(); // refresh temp canale impostata x thermoCam | Write @@ -3087,7 +3087,7 @@ namespace CMS_CORE_Library.S7Net /// /// Refresh dati ThermoCamera dal PLC x area command/status /// - private void refreshRiscTermoCamAbilit() + private void refreshRiscTermoCamEnab() { // leggo DB664 x abilitazione ch alla termocamera List currMem = new List(); @@ -3435,35 +3435,43 @@ namespace CMS_CORE_Library.S7Net /// public override CmsError PLC_WWarmerChTCamEnab(Dictionary newData) { - // FIXME TODO serve nuova area termocamera -#if false - // memory area - byte[] newMem = new byte[newData.Count]; + // leggo DB664 x abilitazione ch alla termocamera + bool[] newMem = new bool[TCAM_CH_ENAB_DATA.Size * 8]; List currMem = new List(); // read actual data on memory... - CmsError libraryError = MEM_RWByteList(R, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); + CmsError libraryError = MEM_RWByteList(R, 0, TCAM_CH_ENAB_DATA.MemType, TCAM_CH_ENAB_DATA.Address, TCAM_CH_ENAB_DATA.SubAddress, 0, TCAM_CH_ENAB_DATA.Size, ref currMem); if (libraryError.IsError()) return libraryError; - newMem = currMem.ToArray(); + + // Convert int into to true/false array + BitArray bArray = new BitArray(currMem.ToArray()); + bArray.CopyTo(newMem, 0); // update only given data... foreach (var item in newData) { - newMem[item.Key - 1] = (byte)item.Value; + newMem[item.Key - 1] = item.Value; } // return as list... - currMem = newMem.ToList(); + currMem = boolsToByteArray(newMem).ToList(); + // scrivo sul PLC array di byte... - libraryError = MEM_RWByteList(W, 0, RISC_CHP_DATA.MemType, RISC_CHP_DATA.Address, RISC_CHP_DATA.SubAddress, 0, RISC_CHP_DATA.Size, ref currMem); + libraryError = MEM_RWByteList(W, 0, TCAM_CH_ENAB_DATA.MemType, TCAM_CH_ENAB_DATA.Address, TCAM_CH_ENAB_DATA.SubAddress, 0, TCAM_CH_ENAB_DATA.Size, ref currMem); if (libraryError.IsError()) return libraryError; -#endif return NO_ERROR; } + public static byte[] boolsToByteArray(bool[] bits) + { + byte[] ret = new byte[(bits.Length - 1) / 8 + 1]; + bits.CopyTo(ret, 0); + return ret; + } + /// /// Set ThermoCamera mode