My problem is in the Modbus Flex Getter node.
If the injection node from bottom has a 10 secs interval then it works fine, but if I extend it to 20 secs or 1 min then the insert node fails because the modbus node fails to reconnect. That's really strange? I tried with others PLCs and the behaviour is the same.
The message error says "PortNotOpenError: Port Not Open".
Is this a bug of modbus node or is there a way to solve or go around the problem?
Thanks
[{"id":"9d833deb.fb5bd","type":"tab","label":"Trending","disabled":false,"info":""},{"id":"2479db21.006c34","type":"comment","z":"9d833deb.fb5bd","name":"Read tagsTrending","info":"","x":170,"y":80,"wires":[]},{"id":"4fc8c470.f493dc","type":"MSSQL","z":"9d833deb.fb5bd","mssqlCN":"a329c5c9.d096c8","name":"qView_TagsTrendingFieira","outField":"payload","returnType":0,"throwErrors":1,"query":"SELECT dbo.tagsTrending.idtag, dbo.tagsTrending.nome, dbo.plcs.nome AS plc, dbo.tagsTrending.idPlc, dbo.tagsTrending.pollG, dbo.tagsTrending.adress, dbo.tagsTrending.dtype\r\nFROM dbo.plcs RIGHT OUTER JOIN dbo.tagsTrending ON dbo.plcs.id = dbo.tagsTrending.idPlc\r\nWHERE (dbo.plcs.nome = N'Fieira')\r\nORDER BY plc, dbo.tagsTrending.pollG, dbo.tagsTrending.adress;","modeOpt":"","modeOptType":"query","queryOpt":"","queryOptType":"editor","paramsOpt":"","paramsOptType":"none","params":[],"x":440,"y":180,"wires":[["2e614a9b.1ee2f6"]]},{"id":"2e614a9b.1ee2f6","type":"function","z":"9d833deb.fb5bd","name":"Set var flow","func":"flow.set(\"tagsTrendingFieira\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":180,"wires":[["fe7a64d3.4ed968"]]},{"id":"43699646.3ce748","type":"MSSQL","z":"9d833deb.fb5bd","mssqlCN":"a329c5c9.d096c8","name":"qView_nTagsTrendingFieira","outField":"payload","returnType":0,"throwErrors":1,"query":"SELECT TOP (100) PERCENT COUNT(dbo.tagsTrending.idtag) AS nTags, MIN(dbo.tagsTrending.adress) AS minAdress, MAX(dbo.tagsTrending.adress) AS maxAdress\r\nFROM dbo.plcs RIGHT OUTER JOIN\r\n dbo.tagsTrending ON dbo.plcs.id = dbo.tagsTrending.idPlc\r\nGROUP BY dbo.plcs.nome\r\nHAVING (dbo.plcs.nome = N'Fieira')\r\nORDER BY dbo.plcs.nome","modeOpt":"","modeOptType":"query","queryOpt":"","queryOptType":"editor","paramsOpt":"","paramsOptType":"none","params":[],"x":440,"y":120,"wires":[["697a8009.7b5a","ee473d3a.bfa5f"]]},{"id":"697a8009.7b5a","type":"function","z":"9d833deb.fb5bd","name":"Set var flow","func":"flow.set(\"nTagsTrendingFieira\",msg.payload[0].nTags);\nflow.set(\"minAddressFieira\",(msg.payload[0]).minAdress);\nflow.set(\"maxAddressFieira\",(msg.payload[0]).maxAdress);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":120,"wires":[["4b1586c2.c1f5a8"]]},{"id":"4b1586c2.c1f5a8","type":"debug","z":"9d833deb.fb5bd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":910,"y":120,"wires":[]},{"id":"981998c1.e76dd8","type":"MSSQL","z":"9d833deb.fb5bd","mssqlCN":"a329c5c9.d096c8","name":"Insert_Trending","outField":"payload","returnType":0,"throwErrors":"0","query":"Insert into dbo.Trending(idtag,tempo,val)\nValues(@idtag,CURRENT_TIMESTAMP, @val)","modeOpt":"","modeOptType":"query","queryOpt":"payload","queryOptType":"msg","paramsOpt":"queryParams","paramsOptType":"msg","params":[{"output":false,"name":"SO2","type":"Int","valueType":"flow","value":"SO2_Value"},{"output":false,"name":"CO","type":"Int","valueType":"flow","value":"CO_Value"},{"output":false,"name":"idtag","type":"real","valueType":"msg","value":"topic"},{"output":false,"name":"val","type":"Real","valueType":"msg","value":"payload"}],"x":1300,"y":620,"wires":[["62a8f078.2ec69"]]},{"id":"20443e90.f228f2","type":"comment","z":"9d833deb.fb5bd","name":"Insert tagsTrending","info":"","x":170,"y":260,"wires":[]},{"id":"d82fd4ae.a6b538","type":"modbus-flex-getter","z":"9d833deb.fb5bd","name":"","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"server":"b99c43b9.d87ba","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":490,"y":480,"wires":[["33d4166c.56ef7a","b94469f1.f90148"],[]]},{"id":"ad8da4d6.0b9cb8","type":"function","z":"9d833deb.fb5bd","name":"","func":"var minAddress = flow.get(\"minAddressFieira\");\nvar maxAddress = flow.get(\"maxAddressFieira\");\nwordArrayL = maxAddress - minAddress + 2; //Comprimento de words no array de leitura - Permite a leitura de um float quando posicionado na última posição do array\nflow.set(\"wordArrayL_Fieira\",wordArrayL);\n//msg.payload = {value: '','fc': 3, 'unitid': 1, 'address': minAddress, 'quantity': wordArrayL};\nmsg.payload = {value: '','fc': 3, 'unitid': 1, 'address': minAddress - 1 , 'quantity': wordArrayL};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":480,"wires":[["d82fd4ae.a6b538","372c4de2.abb9b2"]]},{"id":"9b8e40f7.af1cd","type":"buffer-parser","z":"9d833deb.fb5bd","name":"bp_DynamicSpec","data":"payload","dataType":"msg","specification":"spec","specificationType":"msg","items":[],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"","msgPropertyType":"","resultType":"value","resultTypeType":"output","multipleResult":false,"setTopic":false,"x":910,"y":480,"wires":[["cc6d7c92.611e","acd947a3.f1bad8"]]},{"id":"cc6d7c92.611e","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1070,"y":560,"wires":[]},{"id":"5f72adc8.c759d4","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":400,"wires":[]},{"id":"33d4166c.56ef7a","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":550,"y":400,"wires":[]},{"id":"b94469f1.f90148","type":"function","z":"9d833deb.fb5bd","name":"Dynamic Spec","func":"var bpSpec = {\n \"options\": {\n \"byteSwap\": [\"swap16\"],\n \"resultType\": \"keyvalue\",\n \"multipleResult\": false,\n \"setTopic\": true,\n \"msgProperty\": \"payload\"\n },\n \"items\": [ ]\n}\n\nvar sizes = {\n \"byte\" : 1,\n \"int8\" : 1,\n \"uint8\" : 1,\n \"int16be\" : 2,\n \"int16le\" : 2,\n \"uint16be\" : 2,\n \"uint16le\" : 2,\n \"floatbe\" : 4,\n \"floatle\" : 4,\n \"int32be\" : 4,\n \"int32le\" : 4,\n \"uint32be\" : 4,\n \"uint32le\" : 4\n}\n\nvar dbGroup = flow.get(\"tagsTrendingFieira\"); // Array de elementos da db\nvar dbGroupL = flow.get(\"nTagsTrendingFieira\"); // Nº de elementos do grupo da db\nvar arrayL = flow.get(\"wordArrayL_Fieira\"); // Comprimento do array da sequência de words\nvar addressdb = 0; // Address do registo do grupo da base de dados\nvar addressIn = msg.modbusRequest.address + 1; // Address da word inicial associada ao array\nvar addressW = addressIn; // Address variável ao longo do loop\nvar qtW = 0; // Quantidade de words associada ao grupo\nvar val = 0; // Valor da variável aoosciada ao grupo \nlet offs = 0 // Avança sempre uma word ou 2 bytes na definição de variáveis do Buffer Parser\nvar offset = 0; // Calcula o offset da wordinicial pata cada leitura das variáveis definidas na base de dados\n\nfor (let index = 0; index < dbGroupL; index++) {\n //get the row of this group\n const row = dbGroup[index];\n addressdb = row.adress;\n qtW = arrayL;\n \n for (let indexW = 0; indexW < qtW; indexW++){\n if (addressdb == addressW){\n offset = (addressW - addressIn)*2;\n val = msg.payload[indexW];\n break;\n }\n addressW = addressW + 1;\n }\n \n //add a spec item to the buffer parser dynamic spec\n bpSpec.items.push( {\n \"idtag\": row.idtag,\n \"name\": row.nome,\n \"type\": row.dtype,\n \"offset\": offset,\n \"adress\": row.adress, //Não entra na especificação do node Buffer parser\n \"val\":val\n });\n offs = offs + 2;\n}\n\n//pass dynamic spec into buffer parser\nmsg.spec = bpSpec; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":700,"y":480,"wires":[["9b8e40f7.af1cd","5f72adc8.c759d4"]]},{"id":"fe7a64d3.4ed968","type":"debug","z":"9d833deb.fb5bd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":180,"wires":[]},{"id":"17e6b12f.450faf","type":"split","z":"9d833deb.fb5bd","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"arrayResults[0].idtag","x":1250,"y":480,"wires":[["9630d9f6.f4c028","bbb721fa.a7ea7"]]},{"id":"9630d9f6.f4c028","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1370,"y":400,"wires":[]},{"id":"acd947a3.f1bad8","type":"function","z":"9d833deb.fb5bd","name":"","func":"var data = [];\nvar currentdate = new Date().toISOString().slice(0, 19).replace('T', ' ');\n\nvar nItems = flow.get(\"nTagsTrendingFieira\");\nfor (let index = 0; index < nItems; index++) {\n data.push({\n \"idtag\": msg.arrayResults[index].idtag,\n \"tempo\": currentdate,\n \"val\": msg.arrayResults[index].value\n });\n}\nmsg.payload = data;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1100,"y":480,"wires":[["17e6b12f.450faf"]]},{"id":"bbb721fa.a7ea7","type":"template","z":"9d833deb.fb5bd","name":"Build SQL value list","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"({{payload.idtag}},'{{{payload.tempo}}}',{{{payload.val}}})\n","x":1430,"y":480,"wires":[["e7240a5b.13aeb8"]]},{"id":"e7240a5b.13aeb8","type":"join","z":"9d833deb.fb5bd","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1270,"y":560,"wires":[["c81fbe8d.ef28b"]]},{"id":"c81fbe8d.ef28b","type":"template","z":"9d833deb.fb5bd","name":"Create SQL Statement","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"insert into Trending ([idtag], [tempo], [val]) values \n{{{payload}}};","x":1460,"y":560,"wires":[["2ce0d12a.d8537e","981998c1.e76dd8"]]},{"id":"2ce0d12a.d8537e","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1530,"y":620,"wires":[]},{"id":"23ab73d5.479d7c","type":"inject","z":"9d833deb.fb5bd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":160,"wires":[["43699646.3ce748","4fc8c470.f493dc"]]},{"id":"ee473d3a.bfa5f","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":80,"wires":[]},{"id":"93804c73.a9c7d","type":"debug","z":"9d833deb.fb5bd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":330,"y":400,"wires":[]},{"id":"e5254222.7ee16","type":"inject","z":"9d833deb.fb5bd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":"0.2","topic":"","payload":"","payloadType":"date","x":120,"y":340,"wires":[["93804c73.a9c7d","ad8da4d6.0b9cb8"]]},{"id":"372c4de2.abb9b2","type":"debug","z":"9d833deb.fb5bd","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":440,"y":560,"wires":[]},{"id":"62a8f078.2ec69","type":"debug","z":"9d833deb.fb5bd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1350,"y":740,"wires":[]},{"id":"a329c5c9.d096c8","type":"MSSQL-CN","tdsVersion":"7_4","name":"hmiFscam_cnn","server":"192.168.1.17\\sqlexpress","port":"1433","encyption":false,"database":"hmiFscam","useUTC":false,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false,"enableArithAbort":true},{"id":"b99c43b9.d87ba","type":"modbus-client","name":"Fieira","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.27","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"2","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true}]