From a7a49ec19b367573111592b93c8119f11f14cca7 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 29 Jun 2020 15:02:32 +0200 Subject: [PATCH 1/3] S7Net: start alarm decoding --- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 9b46c76..80ff905 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -480,7 +480,7 @@ namespace CMS_CORE_Library.S7Net /// public override CmsError NC_RActiveAlarms(ref List alarms) { - return FUNCTION_NOT_ALLOWED_ERROR; + return NO_ERROR; } /// @@ -529,6 +529,7 @@ namespace CMS_CORE_Library.S7Net bool[] statusBits; int i = 0; List readValues = new List(); + List currMem = new List(); CmsError libraryError; try { @@ -545,15 +546,30 @@ namespace CMS_CORE_Library.S7Net if (libraryError.IsError()) return libraryError; + // leggo a BYTE + libraryError = MEM_RWByteList(R, 0, + ALARMS_STATUS.MemType, + ALARMS_STATUS.Address, + ALARMS_STATUS.SubAddress, + 0, + (ALARMS_STATUS.Size), // status_bytes / 4 + data_word / 2 + ref currMem); + + if (libraryError.IsError()) + return libraryError; + alarms.Clear(); // Convert integer array into bit array statusBits = IntToBits(readValues.ToArray()); + BitArray bArray = new BitArray(currMem.ToArray()); + for (i = 0; i < ALARMS_STATUS.Size * 8; i++) { // If alarm is active - if (statusBits[i]) + //if (statusBits[i]) + if (bArray[i]) { // Calculate matching alarm byte info address int dataByteAddress = (i * 16) + ALARMS_NUMBER; @@ -626,7 +642,7 @@ namespace CMS_CORE_Library.S7Net CmsError libraryError = NO_ERROR; List currMem = new List(); - libraryError = MEM_RWByteList(R, 0, PRE_POST_POWER_ON.MemType, PRE_POST_POWER_ON.Address, PRE_POST_POWER_ON.SubAddress,0, 4, ref currMem); + libraryError = MEM_RWByteList(R, 0, PRE_POST_POWER_ON.MemType, PRE_POST_POWER_ON.Address, PRE_POST_POWER_ON.SubAddress, 0, 4, ref currMem); if (libraryError.IsError()) return libraryError; @@ -635,7 +651,7 @@ namespace CMS_CORE_Library.S7Net // Convert int into to true/false array //bits = IntToBits(readValue); - var bArray = new BitArray(currMem.ToArray()); + var bArray = new BitArray(currMem.ToArray()); bArray.CopyTo(bits, 0); // Create adn set pre power on object @@ -4349,7 +4365,7 @@ namespace CMS_CORE_Library.S7Net memByteRead = currMem.Skip(4).Take(22).ToArray(); outVal = ""; numByte = memByteRead[1]; - for (int i = 2; i < numByte+2; i++) + for (int i = 2; i < numByte + 2; i++) { outVal += Char.ConvertFromUtf32(memByteRead[i]); } @@ -4358,7 +4374,7 @@ namespace CMS_CORE_Library.S7Net memByteRead = currMem.Skip(26).Take(18).ToArray(); outVal = ""; numByte = memByteRead[1]; - for (int i = 2; i < numByte+2; i++) + for (int i = 2; i < numByte + 2; i++) { outVal += Char.ConvertFromUtf32(memByteRead[i]); } From 02aa343f99a6d5d0a1d748f5f318e5f8f736108f Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 29 Jun 2020 18:56:26 +0200 Subject: [PATCH 2/3] Added path for PLC Alarm/message decoding + other translations --- CMS_CORE_Library/S7Net/Nc_S7Net.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 80ff905..147d314 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -41,6 +41,8 @@ namespace CMS_CORE_Library.S7Net // Alarms data private static Dictionary PlcMessages; + private const string PLC_MESSAGE_PATH = "C:/CMS/S7NET/"; + private const string THERMO_DICT_PATH = "C:/CMS/ThermoActive/Dict/"; private static ushort SelectedProcess = 1; @@ -206,8 +208,6 @@ namespace CMS_CORE_Library.S7Net /// public override CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary messages) { - // FIXME TODO -#if false string filePath; try { @@ -234,8 +234,7 @@ namespace CMS_CORE_Library.S7Net { return ManageException(ex); } -#endif - return FUNCTION_NOT_ALLOWED_ERROR; + return NO_ERROR; } /// /// Elenco lingue disponibili @@ -568,7 +567,6 @@ namespace CMS_CORE_Library.S7Net for (i = 0; i < ALARMS_STATUS.Size * 8; i++) { // If alarm is active - //if (statusBits[i]) if (bArray[i]) { // Calculate matching alarm byte info address From c78f1875238de1e4e098356ff310954a97e310b8 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 30 Jun 2020 11:30:22 +0200 Subject: [PATCH 3/3] manage label translation messages + ack for prod --- CMS_CORE_Library/NcThermo.cs | 12 +++++ CMS_CORE_Library/S7Net/Nc_S7Net.cs | 82 +++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/CMS_CORE_Library/NcThermo.cs b/CMS_CORE_Library/NcThermo.cs index 5e68f5a..471203b 100644 --- a/CMS_CORE_Library/NcThermo.cs +++ b/CMS_CORE_Library/NcThermo.cs @@ -272,6 +272,8 @@ namespace CMS_CORE_Library public abstract CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary messages); + public abstract CmsError NC_GetTranslatedThermoLabels(string language, ref Dictionary messages); + public abstract CmsError NC_GetAvailableLanguages(ref ICollection languages); /** @@ -639,6 +641,16 @@ namespace CMS_CORE_Library /// /// public abstract CmsError PLC_WAckProdUpdate(); + /// + /// Process start prod ack + /// + /// + public abstract CmsError PLC_WAckPzProdStart(); + /// + /// Process end prod ack + /// + /// + public abstract CmsError PLC_WAckPzProdEnd(); /// /// Get current recipe parameter list diff --git a/CMS_CORE_Library/S7Net/Nc_S7Net.cs b/CMS_CORE_Library/S7Net/Nc_S7Net.cs index 147d314..96417c2 100644 --- a/CMS_CORE_Library/S7Net/Nc_S7Net.cs +++ b/CMS_CORE_Library/S7Net/Nc_S7Net.cs @@ -8,6 +8,7 @@ using System.IO; using System.Linq; using System.Net; using System.Net.NetworkInformation; +using System.ServiceModel.Channels; using System.Text; using System.Threading; using static CMS_CORE_Library.Models.DataStructures; @@ -42,7 +43,7 @@ namespace CMS_CORE_Library.S7Net // Alarms data private static Dictionary PlcMessages; private const string PLC_MESSAGE_PATH = "C:/CMS/S7NET/"; - private const string THERMO_DICT_PATH = "C:/CMS/ThermoActive/Dict/"; + private const string THERMO_DICT_PATH = @"Dict\"; private static ushort SelectedProcess = 1; @@ -228,7 +229,54 @@ namespace CMS_CORE_Library.S7Net .Where(line => line.Count() == 2) .ToDictionary(line => Convert.ToInt32(line[0]), line => line[1].Trim()); - return NO_ERROR; + } + catch (Exception ex) + { + return ManageException(ex); + } + return NO_ERROR; + } + /// + /// Compilazione dizionario traduzioni THermo + /// + /// + /// + /// + public override CmsError NC_GetTranslatedThermoLabels(string language, ref Dictionary messages) + { + string filePath; + Dictionary dict01 = new Dictionary(); + Dictionary dict02 = new Dictionary(); + try + { + CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(language); + string langName = ""; + if (cultureInfo.IsNeutralCulture) + langName = cultureInfo.EnglishName; + else + langName = cultureInfo.Parent.EnglishName; + + // Setup the Path for enums + filePath = THERMO_DICT_PATH + @"Enums_" + language + @".txt"; + + // Read From File... + dict01 = File.ReadAllLines(filePath, Encoding.Default) + .Select(line => line.Split(',')) + .Where(line => line.Count() == 2) + .ToDictionary(line => line[0].Trim(), line => line[1].Trim()); + + // Setup the Path for labels + filePath = THERMO_DICT_PATH + @"labels_" + language + @".txt"; + + // Read From File... + dict02 = File.ReadAllLines(filePath, Encoding.Default) + .Select(line => line.Split(',')) + .Where(line => line.Count() == 2) + .ToDictionary(line => line[0].Trim(), line => line[1].Trim()); + + // combine 2 dictionary... + messages = dict01.Union(dict02).ToDictionary(d => d.Key, d => d.Value); + } catch (Exception ex) { @@ -1967,6 +2015,36 @@ namespace CMS_CORE_Library.S7Net return libraryError; } + /// + /// Process start prod ack + /// + /// + public override CmsError PLC_WAckPzProdStart() + { + CmsError libraryError = NO_ERROR; + + // Call ack for prod update + libraryError = PLC_WAck(REQ_CONF_ACK, REQ_CONF_STROBE, 11); + if (libraryError.IsError()) + return libraryError; + + return libraryError; + } + /// + /// Process end prod ack + /// + /// + public override CmsError PLC_WAckPzProdEnd() + { + CmsError libraryError = NO_ERROR; + + // Call ack for prod update + libraryError = PLC_WAck(REQ_CONF_ACK, REQ_CONF_STROBE, 12); + if (libraryError.IsError()) + return libraryError; + + return libraryError; + } /// /// read current recipe parameter list