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..7f4b3bc 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -2368,12 +2368,12 @@ 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 refreshRiscTermoCamTempSet(); - } + } // copio lista act in output currWarmerChannelList = ThermoWarmChannels; @@ -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(); @@ -3129,7 +3129,7 @@ namespace CMS_CORE_Library.S7Net else { libraryError = S7_PLC_EMPTY_READ; - } + } } /// /// Refresh Canali Riscaldi: SetPoint HMI @@ -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_WWarmerChTCamSetp(Dictionary newData) + 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; } @@ -3390,16 +3393,18 @@ 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 + // 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,18 +3413,80 @@ 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; + + return NO_ERROR; + } + + + /// + /// Set current Warmers Channels as enabled/disabled for working with thermo camera data + /// + /// + /// + public override CmsError PLC_WWarmerChTCamEnab(Dictionary newData) + { + // 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, 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; + + + // 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] = item.Value; + } + // return as list... + currMem = boolsToByteArray(newMem).ToList(); + + // scrivo sul PLC array di byte... + 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; + + 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 + /// + /// + /// + public override CmsError PLC_WTCamMode(bool enableTCam) + { +#if false + #endif return NO_ERROR; } + /// /// Set current Warmers Channels reflector's data ///