节点 - 红色序列答案

时间:2018-01-31 00:42:22

标签: serial-port raspberry-pi3 uart node-red

我遇到了node-red的问题。 作为输入,我将串行端口输入设置为115200bps 8N1。 收到表格中的消息" st& 00&"它会将该消息拆分为字符串数组。在第一个字符串将是" st"在第二个将是" 00"。那很有效。在此之后,我需要检查该数组中的第一个字符串是否包含" st"如果是,则通过串口发回响应。而且有一个问题。我能够发送该响应,但发送它需要80多秒。你知道如何加快速度吗? 谢谢

我的代码:

[{"id":"8bfa007f.4e988","type":"serial in","z":"7a60b001.10afb","name":"","serial":"c68e363c.cfacd8","x":84,"y":128,"wires":[["b63c025e.3e288","e151751a.d6fde8"]]},{"id":"1be68e76.7f0352","type":"debug","z":"7a60b001.10afb","name":"","active":true,"console":"false","complete":"payload","x":599,"y":73,"wires":[]},{"id":"b63c025e.3e288","type":"function","z":"7a60b001.10afb","name":"split to arrays","func":"var vstup = msg.payload;\nvar vystup = vstup.split(\"&\");\nvar data = parseInt(vystup[1]);\nswitch (vystup[0])\n{\n    case \"st\":      //st = start\n        global.set(\"zaciatok\", true);\n        global.set(\"zariadenie\", data);\n        msg.payload = \"ok\";\n    break;\n    case \"ok\":      //potvrdzovacia sprava\n        global.set(\"potvrdenie\", true);\n        global.set(\"zariadenie\", data);\n        msg.payload = null;\n    break;\n    case \"sp\":  //sp = stop\n        global.set(\"koniec\", true);\n        global.set(\"zariadenie\", data);\n        msg.payload = null;\n    break;\n    case \"_\":\n        global.set(\"hodnota\", true);\n        global.set(\"cislo\", data);\n        msg.payload = null;\n    break;\n}\nreturn msg;","outputs":"1","noerr":0,"x":258,"y":128,"wires":[["7fc79a7f.5ef3b4"]]},{"id":"1f97ffe.6cb02","type":"serial out","z":"7a60b001.10afb","name":"","serial":"c68e363c.cfacd8","x":564,"y":20,"wires":[]},{"id":"67a1de88.afaee","type":"function","z":"7a60b001.10afb","name":"split to OPC","func":"var start = global.get(\"zaciatok\");\nvar ID_zar = global.get(\"zariadenie\");\nvar ok = global.get(\"potvrdenie\");\nvar stop = global.get(\"koniec\");\nvar data = global.get(\"cislo\");\nvar nastav = global.get(\"hodnota\")\nvar msg1 = {};\nvar msg2 = {};\n\nif (start === true)\n{\n    msg1 = {\n        payload : true,\n        topic : \"ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.GVL.start\",\n        datatype : \"Boolean\",\n        browserName : \"\"\n        };\n     msg2 = {\n        payload : ID_zar,\n        topic : \"ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.GVL.ID_zar\",\n        datatype :\"Int16\",\n        browserName : \"\"\n        };\n        global.set(\"zaciatok\",false);\n        global.set(\"ID_zar\", 0);\n}\nelse if (stop === true)\n{\n    msg1 = {\n        payload : true,\n        topic : \"ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.GVL.stop\",\n        datatype : \"Boolean\",\n        browserName : \"\"\n        };\n     msg2 = {\n        payload : ID_zar,\n        topic : \"ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.GVL.ID_zar\",\n        datatype :\"Int16\",\n        browserName : \"\"\n        };\n        global.set(\"koniec\",false);\n        global.set(\"ID_zar\", 0);\n}\nelse if (nastav === true)\n{\n   msg1 = {\n        payload : data,\n        topic : \"ns=4;s=|var|CODESYS Control for Raspberry Pi SL.Application.GVL.data\",\n        datatype : \"Int16\",\n        browserName : \"\"\n        };\n     msg2.payload = null;\n}\nreturn [msg1,msg2];","outputs":"2","noerr":0,"x":526,"y":146,"wires":[["7f8798f8.5574b8"],["7f8798f8.5574b8"]]},{"id":"7f8798f8.5574b8","type":"OpcUa-Client","z":"7a60b001.10afb","endpoint":"c03b2244.09eb4","action":"write","time":10,"timeUnit":"s","name":"","x":720,"y":144,"wires":[[]]},{"id":"7fc79a7f.5ef3b4","type":"function","z":"7a60b001.10afb","name":"","func":"if (msg.payload !== null)\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":32,"wires":[["1f97ffe.6cb02","67a1de88.afaee","1be68e76.7f0352"]]},{"id":"e151751a.d6fde8","type":"debug","z":"7a60b001.10afb","name":"","active":true,"console":"false","complete":"false","x":212,"y":255,"wires":[]},{"id":"c68e363c.cfacd8","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":true},{"id":"c03b2244.09eb4","type":"OpcUa-Endpoint","z":"","endpoint":"opc.tcp://192.168.1.201:4840","secpol":"None","secmode":"NONE","login":false}]

0 个答案:

没有答案