2021年10月2日 星期六

Node-red modbus FC=01 , 05 ,15

 Node-red  modbus FC=01 , 05 ,15

參考於 https://stevesnoderedguide.com/node-red-modbus








Function

內容

備註

Write 00001-1bit

var fc=5;

var sa=1;

var addresses=1;

var value=1;

 

//msg.slave_ip="192.168.1.76";

msg.slave_ip="127.0.0.1";

msg.payload={"value":value , 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };

return msg;

 

write 00002-0009

-8 bit

var fc=15;

var sa=2;

var addresses=8;

 

var values=[1,1,0,0,1,0,1,0];

 

//msg.slave_ip="192.168.1.76";

msg.slave_ip="127.0.0.1";

msg.payload={"value":values , 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };

return msg;

 

Read  1 Bit 00001-Boolean

var fc=1;

var sa=1;

var addresses=1;

 

var slave_ip=msg.payload.slave_ip;

//msg.slave_ip="192.168.1.31";

msg.slave_ip="127.0.0.1";

msg.payload={value: msg.payload, 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };

return msg;

 

Read  8 Bit 00002-00009-Boolean

var fc=1;

var sa=2;

var addresses=8;

 

var slave_ip=msg.payload.slave_ip;

//msg.slave_ip="192.168.1.31";

msg.slave_ip="127.0.0.1";

msg.payload={value: msg.payload, 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };

return msg;

 

Function

 

msg.value =msg.payload.buffer

return msg;

 

 

Modbus 部分功能碼

中文名稱

寄存器 PLC 位址

位操作/字操作

運算元量

01

  數字量輸出

00001-09999

位操作bit

單個或多個

02

  數字量輸入

10001 -19999

位操作 bit

單個或多個

03

  模擬量輸出

40001-49999

字操作 16bits

單個或多個

04

  模擬量輸入

30001-39999

字操作16bits

單個或多個

 

 

 

 

 

05

  單個數位量輸出

00001-09999

位操作 bit

單個

06

  單個模擬量輸出

40001-49999

字操作16bits

單個

15

  多個數位量輸出

00001-09999

位操作 bit

多個

16

  多個模擬量輸出

40001-49999

字操作16bits

多個

 

[{"id":"60ab7032.9cb8e","type":"modbus-flex-getter","z":"b17040cd.3c6cc","name":"local getter","showStatusActivities":true,"showErrors":true,"logIOActivities":false,"server":"54dde46e.53267c","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":570,"y":340,"wires":[[],["3165ba03.664ac6"]]},{"id":"9355a885.8a8b68","type":"debug","z":"b17040cd.3c6cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":420,"wires":[]},{"id":"73d84d00.da0084","type":"function","z":"b17040cd.3c6cc","name":"1 Bit 00001-Boolean","func":"\nvar fc=1;\nvar sa=1;\nvar addresses=1;\n\n\nvar slave_ip=msg.payload.slave_ip;\n//msg.slave_ip=\"192.168.1.31\";\nmsg.slave_ip=\"127.0.0.1\";\nmsg.payload={value: msg.payload, 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":340,"wires":[["60ab7032.9cb8e"]]},{"id":"43f63747.b34ef8","type":"inject","z":"b17040cd.3c6cc","name":"Read 1bit  Boolean","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":340,"wires":[["73d84d00.da0084"]]},{"id":"3165ba03.664ac6","type":"function","z":"b17040cd.3c6cc","name":"","func":"\nmsg.value =msg.payload.buffer\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":710,"y":340,"wires":[["9355a885.8a8b68"]]},{"id":"830579e3.aa9648","type":"debug","z":"b17040cd.3c6cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":710,"y":86,"wires":[]},{"id":"a29f1c22.5c6e8","type":"inject","z":"b17040cd.3c6cc","name":"Write 8 bits","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":160,"wires":[["d99443.86e92bc"]]},{"id":"d99443.86e92bc","type":"function","z":"b17040cd.3c6cc","name":"write 00002-0009 -8 bit","func":"\nvar fc=15;\nvar sa=2;\nvar addresses=8;\n\nvar values=[1,1,0,0,1,0,1,0];\n\n//msg.slave_ip=\"192.168.1.76\";\nmsg.slave_ip=\"127.0.0.1\";\nmsg.payload={\"value\":values , 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":160,"wires":[["98be5c76.584c","54fa0613.8fe2f8"]]},{"id":"98be5c76.584c","type":"modbus-flex-write","z":"b17040cd.3c6cc","name":"","showStatusActivities":false,"showErrors":true,"server":"54dde46e.53267c","emptyMsgOnFail":false,"keepMsgProperties":false,"x":550,"y":160,"wires":[[],["2c09f9b4.138cc6"]]},{"id":"3511635b.b8bd8c","type":"inject","z":"b17040cd.3c6cc","name":"Write 1 bit ","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":80,"wires":[["f9a99aa8.143d18"]]},{"id":"f9a99aa8.143d18","type":"function","z":"b17040cd.3c6cc","name":"Write 00001-1bit","func":"\nvar fc=5;\nvar sa=1;\nvar addresses=1;\nvar value=1;\n\n//msg.slave_ip=\"192.168.1.76\";\nmsg.slave_ip=\"127.0.0.1\";\nmsg.payload={\"value\":value , 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":80,"wires":[["a421dcd1.8e64a"]]},{"id":"a421dcd1.8e64a","type":"modbus-flex-write","z":"b17040cd.3c6cc","name":"","showStatusActivities":false,"showErrors":true,"server":"54dde46e.53267c","emptyMsgOnFail":false,"keepMsgProperties":false,"x":530,"y":80,"wires":[[],["830579e3.aa9648"]]},{"id":"54fa0613.8fe2f8","type":"debug","z":"b17040cd.3c6cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":510,"y":220,"wires":[]},{"id":"48d1a170.cb35f","type":"comment","z":"b17040cd.3c6cc","name":"read functionm","info":"read functionm\n function codes 1,2,3 and 4 \n \nFunction Code\tAction\tTable Name\n01\tRead\tDiscrete Output Coils\n02\tRead\tDiscrete Input Contacts\n04\tRead\tAnalogue Input Registers\n03\tRead\tAnalogue Output Holding Registers\n\n\nCoil/Register Numbers\tType\tTable Name\tData Addresses\tData Type\n\n1-9999\tRead-Write\tDiscrete Output Coils\t0000 to 270E\t**Boolean**\n10001-19999\tRead-Only\tDiscrete Input Coils\t0000 to 270E\t**Boolean**\n\n30001-39999\tRead-Only\tAnalogue Input Registers\t0000 to 270E\t**Unsigned Word**\n\n40001-49999\tRead-Write\tAnalogue Output Holding Registers\t0000 to 270E\t**Unsigned Word**","x":120,"y":220,"wires":[]},{"id":"bd47e943.1b3858","type":"comment","z":"b17040cd.3c6cc","name":"write  functionm","info":"read functionm\n function codes 5,15,6 and 16 \n \n \nFunction Code\t  Action   \tTable Name\n05\tWrite single\tDiscrete Output Coil\n15\tWrite multiple\tDiscrete Output Coils\n06\tWrite single\tAnalogue Output Holding Register\n16\tWrite multiple\tAnalogue Output Holding Registers\n\n\n\nCoil/Register Numbers\tType\tTable Name\tData Addresses\tData Type\n\n1-9999\tRead-Write\tDiscrete Output Coils\t0000 to 270E\t**Boolean**\n10001-19999\tRead-Only\tDiscrete Input Coils\t0000 to 270E\t**Boolean**\n\n30001-39999\tRead-Only\tAnalogue Input Registers\t0000 to 270E\t**Unsigned Word**\n\n40001-49999\tRead-Write\tAnalogue Output Holding Registers\t0000 to 270E\t**Unsigned Word**","x":300,"y":220,"wires":[]},{"id":"2c09f9b4.138cc6","type":"debug","z":"b17040cd.3c6cc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":710,"y":167,"wires":[]},{"id":"3c887b5c.4fbd84","type":"inject","z":"b17040cd.3c6cc","name":"Read 8bit I Boolean","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":420,"wires":[["2dffc47b.ce9dec"]]},{"id":"2dffc47b.ce9dec","type":"function","z":"b17040cd.3c6cc","name":"8 Bit 00002-00009-Boolean","func":"\nvar fc=1;\nvar sa=2;\nvar addresses=8;\n\nvar slave_ip=msg.payload.slave_ip;\n//msg.slave_ip=\"192.168.1.31\";\nmsg.slave_ip=\"127.0.0.1\";\nmsg.payload={value: msg.payload, 'fc': fc, 'unitid': 3, 'address': sa , 'quantity': addresses };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":420,"wires":[["60ab7032.9cb8e"]]},{"id":"4958c6b1.158978","type":"comment","z":"b17040cd.3c6cc","name":"映射地址","info":"\n## 代码 中文名称 寄存器 PLC 地址 位操作/字操作 操作数量\n## 01   读数字量输出 00001-09999 位操作 单个或多个\n## 02   读数字量输入 10001-19999 位操作 单个或多个\n## 03   读模拟量输出 40001-49999 字操作 单个或多个\n## 04   读模拟量输入 30001-39999 字操作 单个或多个\n## \n## 05   写单个数字量输出 00001-09999 位操作 单个\n## 06   写单个模拟量输出 40001-49999 字操作 单个\n## 15   写多个数字量输出 00001-09999 位操作 多个\n## 16   写多个模拟量输出 40001-49999 字操作 多个","x":120,"y":280,"wires":[]},{"id":"d984b57a.6d8728","type":"comment","z":"b17040cd.3c6cc","name":"","info":"fc (function code)\n(fc=1  <--> fc 5,15)\nread \n读数字量输出\nfc=1 , 00001-09999\nwrite\n写单个数字量输出\nfc =5 , 00001-09999\n写多个数字量输出\nfc =15 , 00001-09999\n\nread \n读数字量输出\nfc=2 , 10001-19999\nfc=4 ,30001-39999\n\n\n(fc=3 <--> fc 6,16)\nread \n读模拟量输出出\nfc=3 , 40001-49999\nwrite\n写单个模拟量输出\nfc =6 , 40001-49999\nwrite\n写单个模拟量输出\nfc =16 , 40001-49999\n\n\n\n","x":290,"y":280,"wires":[]},{"id":"2abbfd75.a4d1c2","type":"comment","z":"b17040cd.3c6cc","name":"FC = 5   00001-09999","info":"","x":130,"y":40,"wires":[]},{"id":"15baebcd.f5f9b4","type":"comment","z":"b17040cd.3c6cc","name":"FC = 15  00001-09999","info":"","x":140,"y":120,"wires":[]},{"id":"c00ac7fe.5792b8","type":"comment","z":"b17040cd.3c6cc","name":"FC =1   00001-09999 ","info":"","x":130,"y":380,"wires":[]},{"id":"ea373c7f.24be","type":"comment","z":"b17040cd.3c6cc","name":"FC =1   00001-09999 ","info":"","x":130,"y":460,"wires":[]},{"id":"54dde46e.53267c","type":"modbus-client","name":"local_3","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":true,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":3,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":false,"reconnectTimeout":2000,"parallelUnitIdsAllowed":false}]

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...