From 8a67bd6a6e375317bd2ddf7041c2e4c322eb1744 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 13 Nov 2019 21:58:41 +0100 Subject: [PATCH] fix parametro lenght stringa... --- IOB-WIN/IobSiemens.cs | 71 ++++++++++++++++++++++++++++++++----------- Jenkinsfile | 2 +- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/IOB-WIN/IobSiemens.cs b/IOB-WIN/IobSiemens.cs index 952458c3..841b8384 100644 --- a/IOB-WIN/IobSiemens.cs +++ b/IOB-WIN/IobSiemens.cs @@ -52,6 +52,52 @@ namespace IOB_WIN #region area metodi lettura/Scrittura + /// + /// Inserimento/aggiornamento chiavi/valore in currProdData + /// + /// + /// + public void upsertKey(string chiave, string valore) + { + if (currProdData.ContainsKey(chiave)) + { + currProdData[chiave] = valore; + } + else + { + currProdData.Add(chiave, valore); + } + } + /// + /// Converte direttamente un valore stringa su un oggetto byte[] (senza limitazioni di dimensione) + /// + /// + /// Dimensione massima ammessa per la stringa + /// + public byte[] stringToByte(string valore, int maxLenght) + { + byte[] answ = new byte[1]; + byte[] stringPar = new byte[2]; + byte[] strByte = S7.Net.Types.String.ToByteArray(valore); + int shiftStrByte = writePre ? 2 : 0; + int byteLen = strByte.Length <= maxLenght ? strByte.Length : maxLenght; + if (writePre) + { + // tolgo 2 alla lunghezza... SE > 2 + if (byteLen > 2) + { + byteLen = byteLen - 2; + } + // MAX LUN + stringPar[1] = (byte)maxLenght; + // LUNGH STRING + stringPar[0] = (byte)byteLen; + Buffer.BlockCopy(stringPar, 0, answ, 0, shiftStrByte); + } + Buffer.BlockCopy(strByte, 0, answ, shiftStrByte, byteLen); + return answ; + } + /// /// Salvo in memblock il valore stringa indicato con formattazione siemens /// @@ -111,22 +157,6 @@ namespace IOB_WIN } } - /// - /// Inserimento/aggiornamento chiavi/valore in currProdData - /// - /// - /// - public void upsertKey(string chiave, string valore) - { - if (currProdData.ContainsKey(chiave)) - { - currProdData[chiave] = valore; - } - else - { - currProdData.Add(chiave, valore); - } - } /// /// Salvo in memblock il valore Int indicato con formattazione siemens /// @@ -1159,7 +1189,14 @@ namespace IOB_WIN saveRealOnMemBlock(ref MemBlock, 0, currMem.value); break; case plcDataType.String: - saveStringOnMemBlock(ref MemBlock, 0, currMem.value.Length, currMem.value); + if (true) + { + saveStringOnMemBlock(ref MemBlock, 0, currMem.size, currMem.value); + } + else + { + MemBlock = stringToByte(currMem.value, currMem.size); + } break; default: break; diff --git a/Jenkinsfile b/Jenkinsfile index f3bb33c9..278d5993 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,7 +16,7 @@ pipeline { /* calcolo numero versione... diverso x branch MASTER/DEVELOP */ script { - withEnv(['NEXT_BUILD_NUMBER=520']) { + withEnv(['NEXT_BUILD_NUMBER=521']) { // env.versionNumber = VersionNumber(versionNumberString : '2.4.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true) env.versionNumber = VersionNumber(versionNumberString : '2.4.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}') env.APP_NAME = 'MAPO-IOB-WIN'