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 9b46c76..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; @@ -41,6 +42,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 = @"Dict\"; private static ushort SelectedProcess = 1; @@ -206,8 +209,6 @@ namespace CMS_CORE_Library.S7Net /// public override CmsError NC_GetTranslatedPlcMessages(string language, ref Dictionary messages) { - // FIXME TODO -#if false string filePath; try { @@ -228,14 +229,60 @@ 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); } -#endif - return FUNCTION_NOT_ALLOWED_ERROR; + 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) + { + return ManageException(ex); + } + return NO_ERROR; } /// /// Elenco lingue disponibili @@ -480,7 +527,7 @@ namespace CMS_CORE_Library.S7Net /// public override CmsError NC_RActiveAlarms(ref List alarms) { - return FUNCTION_NOT_ALLOWED_ERROR; + return NO_ERROR; } /// @@ -529,6 +576,7 @@ namespace CMS_CORE_Library.S7Net bool[] statusBits; int i = 0; List readValues = new List(); + List currMem = new List(); CmsError libraryError; try { @@ -545,15 +593,29 @@ 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 (bArray[i]) { // Calculate matching alarm byte info address int dataByteAddress = (i * 16) + ALARMS_NUMBER; @@ -626,7 +688,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 +697,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 @@ -1953,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 @@ -4349,7 +4441,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 +4450,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]); }