2024年4月5日 星期五

泛用程式 NODE-RED 控制 Modbus ADAM-6017

 泛用程式 NODE-RED 控制 Modbus ADAM-6017








NODE-RED 程式

[{"id":"ee694368.3972f","type":"debug","z":"d9626aca.91e21","name":"received","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":320,"y":580,"wires":[]},{"id":"b839b204.440808","type":"function","z":"d9626aca.91e21","name":"","func":"\nvar fc=msg.payload.fc;\nvar sa=msg.payload.sa;\nvar addresses=msg.payload.addresses;\nvar slave_ip=msg.payload.slave_ip;\nvar payload={ 'fc': fc, 'unitid': 1, 'address': sa , 'quantity': addresses };\nmsg.payload=JSON.stringify(payload);\nreturn msg","outputs":1,"noerr":0,"x":610,"y":100,"wires":[["ffd00ac8.95bca","89afe41a.edf1b"]]},{"id":"beba480e.211a78","type":"function","z":"d9626aca.91e21","name":"write mqtt","func":"var fc=msg.payload.fc;\nvar sa=msg.payload.sa;\nvar addresses=msg.payload.addresses;\nvar value=msg.payload.value;\nvar values=msg.payload.values;\nvar slave_ip=msg.payload.slave_ip;\nif (fc==16 || fc==15){\n     value=JSON.parse(msg.payload.values);\n    node.log(value);\n}\npayload={\"value\":value , 'fc': fc, 'unitid': 1, 'address': sa , 'quantity': addresses };\n\nmsg.payload=JSON.stringify(payload);\nreturn msg\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["257946b2.2703da","94e6a9dbe7119f1b"]]},{"id":"89afe41a.edf1b","type":"debug","z":"d9626aca.91e21","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":850,"y":120,"wires":[]},{"id":"b2ee29d7.deb458","type":"ui_form","z":"d9626aca.91e21","name":"","label":"Read MQTT fc=Codes 1(S_Coil 00001-),2,(D_In 10001-),3(Holding_R 40001-),4(IN_reg 30001-)","group":"19dad5af.6814ca","order":1,"width":9,"height":1,"options":[{"label":"Function Code","value":"fc","type":"number","required":true,"rows":null},{"label":"Slave_ip","value":"slave_ip","type":"text","required":false,"rows":null},{"label":"start address","value":"sa","type":"number","required":true,"rows":null},{"label":"number to read","value":"addresses","type":"number","required":true,"rows":null}],"formValue":{"fc":"","slave_ip":"","sa":"","addresses":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","topicType":"str","splitLayout":false,"className":"","x":390,"y":20,"wires":[["b839b204.440808"]]},{"id":"1c2da2ca.175045","type":"function","z":"d9626aca.91e21","name":"","func":"node.log(\"payload \"+msg.payload);\ndata=msg.payload[0]*65535 +msg.payload[1];\nnode.log(\"payload \"+data);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":120,"wires":[["89afe41a.edf1b"]]},{"id":"edcec760.6c2e2","type":"inject","z":"d9626aca.91e21","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":60,"wires":[["348e0b65.748344"]]},{"id":"348e0b65.748344","type":"function","z":"d9626aca.91e21","name":"","func":"var fc=3;\nvar sa=0;\nvar addresses=20;\nvar slave_ip=\"192.168.1.68\";\nmsg.payload={value: msg.payload, 'fc': fc, 'unitid': 1, 'address': sa , 'quantity': addresses };\n\nreturn msg;","outputs":1,"noerr":0,"x":350,"y":60,"wires":[["b839b204.440808"]]},{"id":"ffd00ac8.95bca","type":"mqtt out","z":"d9626aca.91e21","name":"commands/read","topic":"alex9ufo/modbus/commands/read","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":880,"y":80,"wires":[]},{"id":"f0b386ab.d3a888","type":"mqtt in","z":"d9626aca.91e21","name":"response/#","topic":"alex9ufo/modbus/response/#","qos":"1","datatype":"json","broker":"603bb104.d6134","nl":false,"rap":false,"inputs":0,"x":100,"y":200,"wires":[["7b4fc821.22c538","ddd2489fc08a6d02"]]},{"id":"257946b2.2703da","type":"mqtt out","z":"d9626aca.91e21","name":"commands/write","topic":"alex9ufo/modbus/commands/write","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":780,"y":440,"wires":[]},{"id":"7b4fc821.22c538","type":"switch","z":"d9626aca.91e21","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"alex9ufo/modbus/response/read","vt":"str"},{"t":"eq","v":"alex9ufo/modbus/response/write","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":200,"wires":[["480a9070b5dffe65"],["6d2babe78e644577"]]},{"id":"29c8bd31.ddd502","type":"ui_text","z":"d9626aca.91e21","group":"b1e93ddb.38aa38","order":2,"width":9,"height":1,"name":"","label":"Result Write","format":"{{msg.write}}","layout":"row-left","className":"","x":490,"y":300,"wires":[]},{"id":"bfa650ea.0fdd6","type":"ui_form","z":"d9626aca.91e21","name":"","label":"Write MQTT Codes 5(SC 00001-單個),6(SR40001-單個),15(MC 00001-多個),16(MR40001-多個)","group":"b1e93ddb.38aa38","order":1,"width":9,"height":1,"options":[{"label":"Function Code","value":"fc","type":"number","required":true,"rows":null},{"label":"Slave_ip","value":"slave_ip","type":"text","required":false,"rows":null},{"label":"start address","value":"sa","type":"number","required":true,"rows":null},{"label":"number to write","value":"addresses","type":"number","required":true,"rows":null},{"label":"Value [單個]","value":"value","type":"number","required":false,"rows":null},{"label":"Values[多個]","value":"values","type":"text","required":false,"rows":null}],"formValue":{"fc":"","slave_ip":"","sa":"","addresses":"","value":"","values":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","topicType":"str","splitLayout":false,"className":"","x":350,"y":380,"wires":[["beba480e.211a78"]]},{"id":"a6570060.1cf24","type":"mqtt in","z":"d9626aca.91e21","name":"commands/read","topic":"alex9ufo/modbus/commands/read","qos":"1","datatype":"json","broker":"603bb104.d6134","nl":false,"rap":false,"inputs":0,"x":120,"y":460,"wires":[["b89db30c.a37a68","0618820bcb5bb0da"]]},{"id":"f56b2fb.642915","type":"mqtt out","z":"d9626aca.91e21","name":"alex9ufo/modbus/response","topic":"","qos":"1","retain":"true","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"603bb104.d6134","x":820,"y":560,"wires":[]},{"id":"b89db30c.a37a68","type":"modbus-flex-getter","z":"d9626aca.91e21","name":"local getter","showStatusActivities":true,"showErrors":true,"showWarnings":true,"logIOActivities":false,"server":"e93ff165.6c49b8","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":330,"y":460,"wires":[[],["5517ba73.9f0d24","9907658f.e99d88"]]},{"id":"5517ba73.9f0d24","type":"debug","z":"d9626aca.91e21","name":"out","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":420,"wires":[]},{"id":"4ecdcbf7.dc8a8c","type":"debug","z":"d9626aca.91e21","name":"received","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":320,"y":340,"wires":[]},{"id":"3038d2ee.9e2bf6","type":"mqtt in","z":"d9626aca.91e21","name":"commands/write","topic":"alex9ufo/modbus/commands/write","qos":"1","datatype":"json","broker":"603bb104.d6134","nl":false,"rap":false,"inputs":0,"x":120,"y":520,"wires":[["ee694368.3972f","8aba8951.d541a"]]},{"id":"8aba8951.d541a","type":"modbus-flex-write","z":"d9626aca.91e21","name":"","showStatusActivities":false,"showErrors":false,"showWarnings":true,"server":"e93ff165.6c49b8","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":350,"y":520,"wires":[[],["6850eba3.a0cb84","9c9f9498af2d04b6"]]},{"id":"9907658f.e99d88","type":"change","z":"d9626aca.91e21","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"alex9ufo/modbus/response/read","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":460,"wires":[["f56b2fb.642915"]]},{"id":"6850eba3.a0cb84","type":"change","z":"d9626aca.91e21","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"alex9ufo/modbus/response/write","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":560,"wires":[["f56b2fb.642915"]]},{"id":"7652b3d7.11683c","type":"ui_text","z":"d9626aca.91e21","group":"19dad5af.6814ca","order":2,"width":9,"height":1,"name":"","label":"Result read","format":"{{msg.read}}","layout":"row-left","className":"","x":650,"y":260,"wires":[]},{"id":"0618820bcb5bb0da","type":"debug","z":"d9626aca.91e21","name":"received","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":320,"y":420,"wires":[]},{"id":"ddd2489fc08a6d02","type":"debug","z":"d9626aca.91e21","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":330,"y":160,"wires":[]},{"id":"480a9070b5dffe65","type":"debug","z":"d9626aca.91e21","name":"debug  read","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":180,"wires":[]},{"id":"6d2babe78e644577","type":"debug","z":"d9626aca.91e21","name":"debug  write","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":220,"wires":[]},{"id":"94e6a9dbe7119f1b","type":"debug","z":"d9626aca.91e21","name":"debug 287","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":360,"wires":[]},{"id":"993ce7aa7d1c2c3e","type":"inject","z":"d9626aca.91e21","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":120,"wires":[["1c2da2ca.175045"]]},{"id":"e6bf086ed7928a25","type":"mqtt in","z":"d9626aca.91e21","name":"response/read","topic":"alex9ufo/modbus/response/read","qos":"1","datatype":"json","broker":"603bb104.d6134","nl":false,"rap":false,"inputs":0,"x":110,"y":260,"wires":[["4ecdcbf7.dc8a8c","b5ed74cae708a927"]]},{"id":"b88ab998a150abbe","type":"mqtt in","z":"d9626aca.91e21","name":"response/write","topic":"alex9ufo/modbus/response/write","qos":"1","datatype":"json","broker":"603bb104.d6134","nl":false,"rap":false,"inputs":0,"x":120,"y":300,"wires":[["4ecdcbf7.dc8a8c","29c8bd31.ddd502"]]},{"id":"b5ed74cae708a927","type":"function","z":"d9626aca.91e21","name":"","func":"var data0=msg.payload.data[0]\nvar data1=msg.payload.data[1]\nvar data2=msg.payload.data[2]\n\n\nvar maxRange = 20 ;\nvar minRange = 4;\nvar range = (maxRange - minRange)/(65535-0 ) ;\n\nvar d0 = (range * (data0-0) +4).toFixed(3);\nvar d1 = (range * (data1-0) +4).toFixed(3);\nvar d2 = (range * (data2-0) +4).toFixed(3);\n\nmsg.read=d0+ ', ' + d1+ ', ' +d2;\nreturn msg;\n\n// 直線方程式\n// y-y0=m (x-x0)\n// m= (y2-y1)/(x2-x1)\n// y = m (x-x1) + y0","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":260,"wires":[["7652b3d7.11683c"]]},{"id":"9c9f9498af2d04b6","type":"debug","z":"d9626aca.91e21","name":"out","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":530,"y":520,"wires":[]},{"id":"19dad5af.6814ca","type":"ui_group","name":"Read","tab":"c6d493fc.df122","order":1,"disp":true,"width":"9","collapse":false},{"id":"603bb104.d6134","type":"mqtt-broker","name":"","broker":"broker.mqtt-dashboard.com","port":"1883","clientid":"","autoConnect":true,"usetls":false,"compatmode":false,"protocolVersion":"4","keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""},{"id":"b1e93ddb.38aa38","type":"ui_group","name":"Write","tab":"c6d493fc.df122","order":2,"disp":true,"width":"9","collapse":false},{"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":"c6d493fc.df122","type":"ui_tab","name":"Modbus","icon":"dashboard","disabled":false,"hidden":false}]

沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...