Node-Red & Modbus TCP/IP ADAM6017 Analog in /Data out
計算直線方程
直線方程可以用多種形式表示,以下是幾種常見的直線方程公式:點斜式方程:y – y1 = m(x – x1),其中 m 為斜率,(x1, y1) 為直線上的一點。 m= (y2 – y1)/(x2 – x1)
1) pc 與 adam6017 同網段
2) 利用 Advantech ADAM/APAX Utility (Win32) 設定Adam6017
3) ModBus FC function code 功能碼
var D0= msg.payload.data[0];
var maxRange = 20 ;
var minRange = 4;
var range = 65535 / (20 - minRange);
msg.payload = ((D0 / range)+minRange).toFixed(3);
return msg;
4) 轉換 公式 4mA-20mA 轉成 0-100% , 0-100°C
var x=msg.payload;
var y2=100,y1=0;
var x2=20 ,x1=4 ;
var m= (y2-y1)/ (x2-x1) ;
var y= m* (x-x1) + y1 ;
msg.payload=parseFloat(y).toFixed( 2 );
return msg;
5) 線路圖與實驗結果
6) Node-Red 程式
[{"id":"a262acb464ae315f","type":"modbus-read","z":"19ce39ded2268bc9","name":"","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"showWarnings":true,"unitid":"","dataType":"InputRegister","adr":"0","quantity":"3","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"e93ff165.6c49b8","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":190,"y":100,"wires":[[],["fcec656f8c3c40e8","6f229770d6b292ec","71f830527d099c08","4fbd61cb577961a6"]]},{"id":"fcec656f8c3c40e8","type":"debug","z":"19ce39ded2268bc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":390,"y":60,"wires":[]},{"id":"6f229770d6b292ec","type":"function","z":"19ce39ded2268bc9","name":"","func":"var D0= msg.payload.data[0];\n\nvar maxRange = 20 ;\nvar minRange = 4;\nvar range = 65535 / (20 - minRange);\n\nmsg.payload = ((D0 / range)+minRange).toFixed(3);\nreturn msg;\n\n\n//var y=((20-4)/(65536-0))*D0+4\n//msg.payload=y;\n//return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":120,"wires":[["c771dfe60782bb4e","a4339977c08663e7"]]},{"id":"c771dfe60782bb4e","type":"debug","z":"19ce39ded2268bc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":80,"wires":[]},{"id":"71f830527d099c08","type":"function","z":"19ce39ded2268bc9","name":"","func":"var D1= msg.payload.data[1];\n\n\nvar maxRange = 20 ;\nvar minRange = 4;\nvar range = 65535 / (20 - minRange);\n\nmsg.payload = ((D1 / range)+minRange).toFixed(3);\nreturn msg;\n\n//var y=((20-4)/(65536-0))*D1+4\n//msg.payload=y;\n//return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":240,"wires":[["9f12791d682f8767","d82fa7435f095570"]]},{"id":"9f12791d682f8767","type":"debug","z":"19ce39ded2268bc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":200,"wires":[]},{"id":"4fbd61cb577961a6","type":"function","z":"19ce39ded2268bc9","name":"","func":"var D2= msg.payload.data[2];\n\nvar maxRange = 20 ;\nvar minRange = 4;\nvar range = 65535 / (20 - minRange);\n\nmsg.payload = ((D2 / range)+minRange).toFixed(3);\nreturn msg;\n\n//var y=((20-4)/(65536-0))*D2+4\n//msg.payload=y;\n//return msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":340,"wires":[["13b2406aa0c47c71","fb397dd725d1c697"]]},{"id":"13b2406aa0c47c71","type":"debug","z":"19ce39ded2268bc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":340,"wires":[]},{"id":"a4339977c08663e7","type":"function","z":"19ce39ded2268bc9","name":"","func":"var x=msg.payload;\n//var y= (x-4)/0.16\nvar y2=100,y1=0;\nvar x2=20 ,x1=4 ;\nvar m= (y2-y1)/ (x2-x1) ;\nvar y= m* (x-x1) + y1 ;\nmsg.payload=parseFloat(y).toFixed( 2 );\nreturn msg;\n\n\n// 4mA----0\n//20mA----100\n// (20-4)/(100-0) = 0.16\n//y= (x-4) / 0.16\n//\n//1)\t m=(y2-y1)/(x2-x1)= (100-0)/(20-4) \n//2)\t y= mx+k \n//3)\t y= (100-0)/(20-4) * (x-4) + 0\n//4)\t If x= 4 then y=0 , x=20 then y=100\n\n//m= (y2-y1)/(x2-x1)\t\n//y= m (x-x1) + y1\t\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":120,"wires":[["de1dfb0910dc87df","6521cfa3203d42b1"]]},{"id":"de1dfb0910dc87df","type":"debug","z":"19ce39ded2268bc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":160,"wires":[]},{"id":"d82fa7435f095570","type":"function","z":"19ce39ded2268bc9","name":"","func":"var x=msg.payload;\n\nvar y2=100,y1=0;\nvar x2=20 ,x1=4 ;\nvar m= (y2-y1)/ (x2-x1) ;\nvar y= m* (x-x1) + y1 ;\nmsg.payload=parseFloat(y).toFixed( 2 );\nreturn msg;\n\n\n// 4mA----0\n//20mA----100\n// (20-4)/(100-0) = 0.16\n//y= (x-4) / 0.16\n//","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":240,"wires":[["952d2bf2546734a8","56afb0bb859ba303"]]},{"id":"952d2bf2546734a8","type":"debug","z":"19ce39ded2268bc9","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":280,"wires":[]},{"id":"fb397dd725d1c697","type":"function","z":"19ce39ded2268bc9","name":"","func":"var x=msg.payload;\n\nvar y2=100,y1=0;\nvar x2=20 ,x1=4 ;\nvar m= (y2-y1)/ (x2-x1) ;\nvar y= m* (x-x1) + y1 ;\nmsg.payload=parseFloat(y).toFixed( 2 );\nreturn msg;\n\n\n// 4mA----0\n//20mA----100\n// (20-4)/(100-0) = 0.16\n//y= (x-4) / 0.16\n//","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":380,"wires":[["1d7dc97bfcba1f48","3f164e89c620e44a"]]},{"id":"1d7dc97bfcba1f48","type":"debug","z":"19ce39ded2268bc9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":420,"wires":[]},{"id":"6521cfa3203d42b1","type":"ui_gauge","z":"19ce39ded2268bc9","name":"","group":"fe5ef04de40b1339","order":2,"width":4,"height":3,"gtype":"gage","title":"輸入","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":830,"y":120,"wires":[]},{"id":"56afb0bb859ba303","type":"ui_gauge","z":"19ce39ded2268bc9","name":"","group":"fe5ef04de40b1339","order":10,"width":4,"height":3,"gtype":"gage","title":"濕度","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":830,"y":240,"wires":[]},{"id":"3f164e89c620e44a","type":"ui_gauge","z":"19ce39ded2268bc9","name":"","group":"fe5ef04de40b1339","order":18,"width":4,"height":3,"gtype":"gage","title":"溫度","label":"°C","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","className":"","x":830,"y":380,"wires":[]},{"id":"eae8aae562330674","type":"modbus-read","z":"19ce39ded2268bc9","name":"","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"showWarnings":true,"unitid":"1","dataType":"Coil","adr":"16","quantity":"2","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"e93ff165.6c49b8","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":130,"y":460,"wires":[[],[]]},{"id":"865f932a12694a3c","type":"function","z":"19ce39ded2268bc9","name":"","func":"\nmsg.payload=msg.payload[0];\nreturn msg;\n\n//FC=1 address=16","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":480,"wires":[["e47260eb5cd5f661","17bd400d9c33ff92"]]},{"id":"e47260eb5cd5f661","type":"ui_led","z":"19ce39ded2268bc9","order":2,"group":"1ee8af2e195a6fb3","width":4,"height":4,"label":"D0","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":490,"y":480,"wires":[]},{"id":"ea1cdf3cc283acd1","type":"function","z":"19ce39ded2268bc9","name":"","func":"msg.payload=msg.payload[1];\nreturn msg;\n\n//FC=1 address=17","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":560,"wires":[["7ba667c5dc42031a","9f43e3178af3e42e"]]},{"id":"7ba667c5dc42031a","type":"ui_led","z":"19ce39ded2268bc9","order":12,"group":"1ee8af2e195a6fb3","width":4,"height":4,"label":"D1","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":490,"y":560,"wires":[]},{"id":"5853a931f4ccaf89","type":"debug","z":"19ce39ded2268bc9","name":"debug 291","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":440,"wires":[]},{"id":"4219c9c7511f27b3","type":"inject","z":"19ce39ded2268bc9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":320,"wires":[["cbf9fc83ec3ced87"]]},{"id":"cbf9fc83ec3ced87","type":"modbus-getter","z":"19ce39ded2268bc9","name":"","showStatusActivities":false,"showErrors":false,"showWarnings":true,"logIOActivities":false,"unitid":"1","dataType":"Coil","adr":"16","quantity":"2","server":"e93ff165.6c49b8","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":140,"y":400,"wires":[["865f932a12694a3c","ea1cdf3cc283acd1","5853a931f4ccaf89"],[]]},{"id":"17bd400d9c33ff92","type":"debug","z":"19ce39ded2268bc9","name":"debug 292","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":520,"wires":[]},{"id":"9f43e3178af3e42e","type":"debug","z":"19ce39ded2268bc9","name":"debug 293","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":600,"wires":[]},{"id":"e93ff165.6c49b8","type":"modbus-client","name":"ADAM6017","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":false,"tcpHost":"192.168.1.108","tcpPort":"502","tcpType":"TCP-RTU-BUFFERED","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"None","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":false,"reconnectTimeout":"2000","parallelUnitIdsAllowed":false},{"id":"fe5ef04de40b1339","type":"ui_group","name":"ANALOG_TRH-300","tab":"90e8f7e65e87056a","order":1,"disp":true,"width":6,"collapse":false,"className":""},{"id":"1ee8af2e195a6fb3","type":"ui_group","name":"Digital Out -2","tab":"90e8f7e65e87056a","order":2,"disp":true,"width":6,"collapse":false,"className":""},{"id":"90e8f7e65e87056a","type":"ui_tab","name":"ADAM6017","icon":"dashboard","order":115,"disabled":false,"hidden":false}]
沒有留言:
張貼留言