Hello again! I hope we can solve this problem together. Sorry for disturbing again. I can take values from my electric screwdriver. I used the Modbus-read command for that. But I would like to vice versa now. I have 4 different values. These are Speed, Torque, Turns, and Total Time. For example, I want to enter some values myself via the node-red form command to my machine. I hope my question is clear. Thank you in advance!
In addition, I found this information in the handbook of the machine I was using. Do you think it will help?
Have you tried simply injecting a value into the desired register.
Inject node -> modbus setter node
That information is about the modbus protocol. Since you are using the modbus contrib nodes, you do not need to worry about the modbus protocol data format or CRC calculations (the node-red modbus nodes take care of all that)
Thank you for the reply. Actually, I do not have an idea how to start this issue. I tried some ways. For example
[
{
"id": "861c4316c2c95c49",
"type": "tab",
"label": "Flow 6",
"disabled": false,
"info": "",
"env": []
},
{
"id": "942bc905179e4f82",
"type": "inject",
"z": "861c4316c2c95c49",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[500,0.100,0.250,3]",
"payloadType": "json",
"x": 310,
"y": 120,
"wires": [
[
"f5b646ee1cc58fba"
]
]
},
{
"id": "f5b646ee1cc58fba",
"type": "function",
"z": "861c4316c2c95c49",
"name": "function 1",
"func": "msg.payload = {\n value: msg.payload,\n 'fc': 16,\n 'unitid': 1,\n 'address': 47,\n 'quantity': 4\n}\nreturn msg\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 500,
"y": 120,
"wires": [
[
"89eece315318016d"
]
]
},
{
"id": "89eece315318016d",
"type": "modbus-flex-write",
"z": "861c4316c2c95c49",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"server": "531e73b33af62948",
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 690,
"y": 120,
"wires": [
[
"afa6fe85f707e69c"
],
[]
]
},
{
"id": "afa6fe85f707e69c",
"type": "debug",
"z": "861c4316c2c95c49",
"name": "debug 17",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 880,
"y": 120,
"wires": []
},
{
"id": "6f1275c0188d92c4",
"type": "inject",
"z": "861c4316c2c95c49",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "[500,0.100,0.250,3]",
"payloadType": "json",
"x": 330,
"y": 340,
"wires": [
[
"40dcca967927f991"
]
]
},
{
"id": "40dcca967927f991",
"type": "modbus-write",
"z": "861c4316c2c95c49",
"name": "",
"showStatusActivities": false,
"showErrors": false,
"showWarnings": true,
"unitid": "1",
"dataType": "MHoldingRegisters",
"adr": "47",
"quantity": "4",
"server": "531e73b33af62948",
"emptyMsgOnFail": false,
"keepMsgProperties": false,
"delayOnStart": false,
"startDelayTime": "",
"x": 580,
"y": 340,
"wires": [
[
"cf472c941df32640"
],
[]
]
},
{
"id": "cf472c941df32640",
"type": "debug",
"z": "861c4316c2c95c49",
"name": "debug 18",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 820,
"y": 340,
"wires": []
},
{
"id": "531e73b33af62948",
"type": "modbus-client",
"name": "",
"clienttype": "serial",
"bufferCommands": true,
"stateLogEnabled": false,
"queueLogEnabled": false,
"failureLogEnabled": true,
"tcpHost": "127.0.0.1",
"tcpPort": "502",
"tcpType": "DEFAULT",
"serialPort": "COM3",
"serialType": "RTU-BUFFERD",
"serialBaudrate": "115200",
"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
}
]
But I can not see these values on my machine screen. You can see my screen below. I would like to change these values by node-red.
I am sure that I should add some things. But have no idea!
This...
msg.payload = {
value: msg.payload,
'fc': 16,
'unitid': 1,
'address': 47,
'quantity': 4
}
will instruct the ModBus node to write data to 4 elements starting at register 47 (i.e. 47 will receive 500
, 48 will get 0.1
, 49 will get 0.25
and 50 will get 3
)
If you recall from our other thread, ModBus works with UINT16 values. So sending 0.1
and 0.25
will fail anyway! You need to pack the float values into a UINT.
Additionally, if I remember from your other thread, you actually want to write to registers 47, 56, 58 and 59 (not 47, 48, 49 and 50) right? For that, you will need to send the values individually.
Here is how I would approach it...
Demo Flow:
[{"id":"942bc905179e4f82","type":"inject","z":"861c4316c2c95c49","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":295,"y":260,"wires":[["bb3003f2ef165a35"]],"l":false},{"id":"604a6bb0442a8f9a","type":"link call","z":"861c4316c2c95c49","name":"","links":["286db99f79e92ef2"],"linkType":"static","timeout":"30","x":890,"y":260,"wires":[["5b78a7f4471448b2","b42ffec33b201c57"]]},{"id":"bb3003f2ef165a35","type":"change","z":"861c4316c2c95c49","name":"REG:47, Value: 500","rules":[{"t":"set","p":"topic","pt":"msg","to":"47","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"500","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":260,"wires":[["604a6bb0442a8f9a"]]},{"id":"5b78a7f4471448b2","type":"change","z":"861c4316c2c95c49","name":"REG:56, Value: 0.1","rules":[{"t":"set","p":"topic","pt":"msg","to":"56","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"0.1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":300,"wires":[["a6694cd7240ee8c1"]]},{"id":"87b2b98f1cc35658","type":"link call","z":"861c4316c2c95c49","name":"","links":["286db99f79e92ef2"],"linkType":"static","timeout":"30","x":890,"y":300,"wires":[["5de7fe4342c645f1","3e863779ec6e2638"]]},{"id":"5de7fe4342c645f1","type":"change","z":"861c4316c2c95c49","name":"REG:58, Value: 0.25","rules":[{"t":"set","p":"topic","pt":"msg","to":"58","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"0.25","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":340,"wires":[["3ab8bfe253426d2e"]]},{"id":"1b5b2e6739b0788d","type":"link call","z":"861c4316c2c95c49","name":"","links":["286db99f79e92ef2"],"linkType":"static","timeout":"30","x":890,"y":340,"wires":[["7330fc6ad5bda771","9852a0a9efb3fd33"]]},{"id":"7330fc6ad5bda771","type":"change","z":"861c4316c2c95c49","name":"REG:59, Value: 3","rules":[{"t":"set","p":"topic","pt":"msg","to":"47","tot":"num"},{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":380,"wires":[["54b692f7e79948e9"]]},{"id":"54b692f7e79948e9","type":"link call","z":"861c4316c2c95c49","name":"","links":["286db99f79e92ef2"],"linkType":"static","timeout":"30","x":890,"y":380,"wires":[["3561eaa40827e2a7"]]},{"id":"a6694cd7240ee8c1","type":"link call","z":"861c4316c2c95c49","name":"","links":["06e8463bb48c80ad"],"linkType":"static","timeout":"30","x":650,"y":300,"wires":[["87b2b98f1cc35658"]]},{"id":"3ab8bfe253426d2e","type":"link call","z":"861c4316c2c95c49","name":"","links":["06e8463bb48c80ad"],"linkType":"static","timeout":"30","x":650,"y":340,"wires":[["1b5b2e6739b0788d"]]},{"id":"b42ffec33b201c57","type":"debug","z":"861c4316c2c95c49","name":"debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":260,"wires":[]},{"id":"3e863779ec6e2638","type":"debug","z":"861c4316c2c95c49","name":"debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":300,"wires":[]},{"id":"9852a0a9efb3fd33","type":"debug","z":"861c4316c2c95c49","name":"debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":340,"wires":[]},{"id":"3561eaa40827e2a7","type":"debug","z":"861c4316c2c95c49","name":"debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":380,"wires":[]},{"id":"b3aeeb0cd653ab43","type":"group","z":"861c4316c2c95c49","name":"SUBROUTINE: Write 1 UINT to ModBus","style":{"fill":"#ffffbf","label":true,"stroke":"#ffbfbf","color":"#000000"},"nodes":["286db99f79e92ef2","bd512936ca2df06c","94cda51f698985c8","89eece315318016d"],"x":254,"y":19,"w":782,"h":82},{"id":"286db99f79e92ef2","type":"link in","z":"861c4316c2c95c49","g":"b3aeeb0cd653ab43","name":"Write 1 UINT to ModBus (FC6)","links":[],"x":295,"y":60,"wires":[["94cda51f698985c8"]]},{"id":"bd512936ca2df06c","type":"link out","z":"861c4316c2c95c49","g":"b3aeeb0cd653ab43","name":"link out 40","mode":"return","links":[],"x":995,"y":60,"wires":[]},{"id":"94cda51f698985c8","type":"function","z":"861c4316c2c95c49","g":"b3aeeb0cd653ab43","name":"Setup payload","func":"msg.payload = {\n value: msg.payload,\n 'fc': 6,\n 'unitid': msg.unit || 1,\n 'address': msg.topic,\n 'quantity': 1\n}\nreturn msg\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":60,"wires":[["89eece315318016d"]]},{"id":"89eece315318016d","type":"modbus-flex-write","z":"861c4316c2c95c49","g":"b3aeeb0cd653ab43","name":"","showStatusActivities":false,"showErrors":false,"server":"531e73b33af62948","emptyMsgOnFail":false,"keepMsgProperties":false,"x":740,"y":60,"wires":[["bd512936ca2df06c"],[]]},{"id":"531e73b33af62948","type":"modbus-client","name":"","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"COM3","serialType":"RTU-BUFFERD","serialBaudrate":"115200","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"2e869ad80ee4016b","type":"group","z":"861c4316c2c95c49","name":"SUBROUTINE: Convert 1 Float to a UINT value for ModBus","style":{"stroke":"#0070c0","fill":"#bfdbef","label":true,"color":"#000000"},"nodes":["06e8463bb48c80ad","ba82d013eccbe4fc","651d03f969ae5789","ac4640d4f6ddc59c","f9d57256c1997818"],"x":254,"y":119,"w":782,"h":82},{"id":"06e8463bb48c80ad","type":"link in","z":"861c4316c2c95c49","g":"2e869ad80ee4016b","name":"Float to UINT","links":[],"x":295,"y":160,"wires":[["651d03f969ae5789"]]},{"id":"ba82d013eccbe4fc","type":"link out","z":"861c4316c2c95c49","g":"2e869ad80ee4016b","name":"link out 41","mode":"return","links":[],"x":995,"y":160,"wires":[]},{"id":"651d03f969ae5789","type":"buffer-maker","z":"861c4316c2c95c49","g":"2e869ad80ee4016b","name":"Convert 1 float to a buffer","specification":"spec","specificationType":"ui","items":[{"name":"item1","type":"floatbe","length":1,"dataType":"msg","data":"payload"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","x":450,"y":160,"wires":[["ac4640d4f6ddc59c"]]},{"id":"ac4640d4f6ddc59c","type":"buffer-parser","z":"861c4316c2c95c49","g":"2e869ad80ee4016b","name":"Buffer to UINT","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"value","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":true,"setTopic":false,"outputs":1,"x":670,"y":160,"wires":[["f9d57256c1997818"]]},{"id":"f9d57256c1997818","type":"change","z":"861c4316c2c95c49","g":"2e869ad80ee4016b","name":"move to payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":160,"wires":[["ba82d013eccbe4fc"]]}]
untested, since I do not have your device
Thank you for the solution. Sorry for the mistakes of my addresses. When I checked the write address, it was totally different. But I changed the REG numbers on your chart. Unfortunanely I did not see any changeable on my device. It worked after I changed the registration addresses on the first chart which I sent. Thanks a lot!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.