# What does unitid and address in modbus node mean?

**URL:** <https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890>\
**Category:** General\
**Tags:** modbus\
**Created:** [14 June 2022 05:03 UTC](https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890 "2022-06-14T05:03:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SP-Mushrooms](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sp-mushrooms/32/61710_2.png) [@SP-Mushrooms](https://discourse.nodered.org/u/SP-Mushrooms)\
**Post date:** [14 June 2022 05:03 UTC](https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890/1 "2022-06-14T05:03:43Z")

</div>

I have a qn I am trying to use write modbus to a modbus relay to on and off I can't get it to work. It has a defalt address of 0xFF (255) when I have a unitid other that 0 I get a error like  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21ea19979bdd524eced895f91eb0855a066ea690.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/471ad43dbfe23fed87e18e700ee88f87ef375dfa.png)

But when I put unitid of 0 the out put is this  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f96e507efc7bc5a0ec6c613a01a17a08a9a1ccb.png)

So I would like to ask what do unitid and address mean to the modbus node

This is my flow

```auto
[{"id":"bc242f2150ad2d9e","type":"function","z":"5166dd2a7e38940b","name":"open","func":"msg.payload={ \"value\": Buffer.from([0xFF, \"0x05\", 0x00, 0x01,0xFF, 0x00, 0x99, 0xe4]) , \n 'fc': 16, \n 'unitid': 255, \n 'address': 0 , \n 'quantity': 8 }; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":150,"y":100,"wires":[["1402d00f97dd21b6","22a9c32181f56c47"]]},{"id":"f47f15618e6fabae","type":"inject","z":"5166dd2a7e38940b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":190,"y":40,"wires":[["bc242f2150ad2d9e"]]},{"id":"1402d00f97dd21b6","type":"modbus-flex-write","z":"5166dd2a7e38940b","name":"","showStatusActivities":true,"showErrors":true,"server":"64e234ec8ad4b896","emptyMsgOnFail":true,"keepMsgProperties":true,"x":210,"y":220,"wires":[["247db663721c8432","7c35516b0b4c471b"],["bd76ad027244bf4b","24630d69f1cd5be9"]]},{"id":"22a9c32181f56c47","type":"debug","z":"5166dd2a7e38940b","name":"Relay output 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":340,"y":120,"wires":[]},{"id":"247db663721c8432","type":"debug","z":"5166dd2a7e38940b","name":"Relay output 12e","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":470,"y":200,"wires":[]},{"id":"7c35516b0b4c471b","type":"modbus-response","z":"5166dd2a7e38940b","name":"123e","registerShowMax":20,"x":430,"y":200,"wires":[]},{"id":"bd76ad027244bf4b","type":"debug","z":"5166dd2a7e38940b","name":"Relay output 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":460,"y":240,"wires":[]},{"id":"24630d69f1cd5be9","type":"modbus-response","z":"5166dd2a7e38940b","name":"dsf","registerShowMax":20,"x":430,"y":240,"wires":[]},{"id":"64e234ec8ad4b896","type":"modbus-client","name":"RS485-1","clienttype":"simpleser","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":1,"commandDelay":200,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d0bd744cefdb59f65916dfb717dab4950b4ea2e.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [14 June 2022 10:46 UTC](https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890/2 "2022-06-14T10:46:42Z")

</div>

Hello ..

the `unitid` is the id of the modbus slave device  
( as mentioned in the help file of the node that is in the range 0..255 tcp | 0..247 serial )  
I see you have the communication as Serial rs485 so the address cannot exceed 247

Can your modbus relay device be configured to address id 1 ?  
Whats strange is that you get a reply when you request with id 0 ? .. so it must be 0 😉  
Any way to double check ? Can you share any documentation for the device ?

the `address` is the address of the modbus register from which you want to start reading or writing

i see you use FC16 (Function code 16) which is used to set Multiple Analog Output Registers  
is your device controlled using a decimal value to a register that the relay device then translates to on/off ?  
im asking because setting Multiple Coils is FC15  
we need to check the documentation of the device

* * *

[Article about Modbus](https://ipc2u.com/articles/knowledge-base/modbus-rtu-made-simple-with-detailed-descriptions-and-examples/)

---

<div class="post-metadata">

**Author:** ![SP-Mushrooms](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sp-mushrooms/32/61710_2.png) [@SP-Mushrooms](https://discourse.nodered.org/u/SP-Mushrooms)\
**Post date:** [14 June 2022 12:41 UTC](https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890/3 "2022-06-14T12:41:53Z")

</div>

Thanks for replying I will check it tomorrow. Sorry if my qns seem dumb or it is another basic question as I don't really know modbus I looked at your link and I think I understand my code abit better thanks.

This is the document I recived but it is in chinese  
[2ch\_relay\_modbus\_cmd.pdf](https://discourse.nodered.org/uploads/short-url/3g4nZQ19jOUhfRMk968wYxHb0Nr.pdf) (3.1 MB)  
And this is a google link if you dont want to download the document

> **[2ch\_relay\_modbus\_cmd.pdf](https://drive.google.com/file/d/1iSsqfZlNNC0T-MfZ4ovYfSuuns2DdozP/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [14 June 2022 20:24 UTC](https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890/4 "2022-06-14T20:24:44Z")

</div>

i believe i have found an english version of the docs of the device  
[http://www.chinalctech.com/m/view.php?aid=455](http://www.chinalctech.com/m/view.php?aid=455)

Try FC15 .. this should turn both relays on

```auto

msg.payload = { value: [1,1], 'fc': 15, 'unitid': 255, 'address': 0, 'quantity': 2 }

return msg

```

The array `value : [1,1]` is to set both to ON. try different compinations also [0,1] etc

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 August 2022 20:25 UTC](https://discourse.nodered.org/t/what-does-unitid-and-address-in-modbus-node-mean/63890/5 "2022-08-13T20:25:04Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
