在nodered中,用json实现一个按钮的取反功能,通过modbus 写入到PLC的M0中,部分功能实现了

在nodered中,用json实现一个按钮的取反功能,通过modbus 写入到PLC的M0中。现在已经可以实现按下,按钮变成红色,同时M0置ON,再按一次按钮,按钮变成灰色,但M0没有OFF。请教一下大神们,如何实现这个功能?

代码如下:[
{
“id”: “950bb224f8a56d5b”,
“type”: “ui_button”,
“z”: “01513c307c3a679a”,
“name”: “”,
“group”: “c070ecdb.6d5ce”,
“order”: 0,
“width”: “0”,
“height”: “0”,
“passthru”: false,
“label”: “{{payload}}”,
“tooltip”: “”,
“color”: “”,
“bgcolor”: “{{colour}}”,
“className”: “”,
“icon”: “”,
“payload”: “true”,
“payloadType”: “bool”,
“topic”: “1010”,
“topicType”: “str”,
“x”: 760,
“y”: 360,
“wires”: [
[
“db3302e93cd28bc2”,
“9f5564304b867d4c”
]
]
},
{
“id”: “1f314764b3d65dc4”,
“type”: “change”,
“z”: “01513c307c3a679a”,
“name”: “”,
“rules”: [
{
“t”: “set”,
“p”: “colour”,
“pt”: “msg”,
“to”: “green”,
“tot”: “str”
},
{
“t”: “set”,
“p”: “payload”,
“pt”: “msg”,
“to”: “<i class="fa fa-rotate-90 fa-folder-open-o"> OPEN2”,
“tot”: “str”
}
],
“action”: “”,
“property”: “”,
“from”: “”,
“to”: “”,
“reg”: false,
“x”: 500,
“y”: 315,
“wires”: [
[
“950bb224f8a56d5b”
]
]
},
{
“id”: “db3302e93cd28bc2”,
“type”: “function”,
“z”: “01513c307c3a679a”,
“name”: “state”,
“func”: “var state = context.state || false;\nstate = !state;\ncontext.state = state;\nif (state) { return [msg,null]; }\nelse { return [null,msg]; }\n”,
“outputs”: 2,
“timeout”: “”,
“noerr”: 0,
“initialize”: “”,
“finalize”: “”,
“libs”: [],
“x”: 220,
“y”: 420,
“wires”: [
[
“1f314764b3d65dc4”
],
[
“85099a15f3fd2aac”
]
]
},
{
“id”: “85099a15f3fd2aac”,
“type”: “change”,
“z”: “01513c307c3a679a”,
“name”: “”,
“rules”: [
{
“t”: “set”,
“p”: “colour”,
“pt”: “msg”,
“to”: “red”,
“tot”: “str”
},
{
“t”: “set”,
“p”: “payload”,
“pt”: “msg”,
“to”: “<i class="fa fa-rotate-90 fa-folder-o"> 关”,
“tot”: “str”
}
],
“action”: “”,
“property”: “”,
“from”: “”,
“to”: “”,
“reg”: false,
“x”: 500,
“y”: 360,
“wires”: [
[
“950bb224f8a56d5b”
]
]
},
{
“id”: “9f5564304b867d4c”,
“type”: “modbus-write”,
“z”: “01513c307c3a679a”,
“name”: “Agilox_smalldoor”,
“showStatusActivities”: false,
“showErrors”: true,
“showWarnings”: true,
“unitid”: “”,
“dataType”: “Coil”,
“adr”: “00001”,
“quantity”: “1”,
“server”: “a3833dbd829cceee”,
“emptyMsgOnFail”: false,
“keepMsgProperties”: false,
“delayOnStart”: false,
“startDelayTime”: “”,
“x”: 960,
“y”: 360,
“wires”: [
[],
[]
]
},
{
“id”: “c070ecdb.6d5ce”,
“type”: “ui_group”,
“z”: “01513c307c3a679a”,
“name”: “Click”,
“tab”: “7d974e73.cf8f9”,
“order”: 1,
“disp”: true,
“width”: “5”
},
{
“id”: “a3833dbd829cceee”,
“type”: “modbus-client”,
“name”: “”,
“clienttype”: “tcp”,
“bufferCommands”: true,
“stateLogEnabled”: false,
“queueLogEnabled”: false,
“failureLogEnabled”: true,
“tcpHost”: “192.168.10.56”,
“tcpPort”: “502”,
“tcpType”: “DEFAULT”,
“serialPort”: “/dev/ttyUSB”,
“serialType”: “RTU-BUFFERD”,
“serialBaudrate”: “9600”,
“serialDatabits”: “8”,
“serialStopbits”: “1”,
“serialParity”: “none”,
“serialConnectionDelay”: “100”,
“serialAsciiResponseStartDelimiter”: “0x3A”,
“unit_id”: “1”,
“commandDelay”: “1”,
“clientTimeout”: “1000”,
“reconnectOnTimeout”: true,
“reconnectTimeout”: “2000”,
“parallelUnitIdsAllowed”: true,
“showWarnings”: true,
“showLogs”: true
},
{
“id”: “7d974e73.cf8f9”,
“type”: “ui_tab”,
“z”: “01513c307c3a679a”,
“name”: “Home”,
“icon”: “link”,
“order”: 1
}
]