# Mc protocol - how to use mc write node

**URL:** <https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529>\
**Category:** Industrial\
**Created:** [25 November 2020 20:52 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529 "2020-11-25T20:52:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 20:52 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/1 "2020-11-25T20:52:55Z")

</div>

good day,

I managed to use node-contrib-mcprotocol for fetching status & analog value. However, i cant send command @ write value using MC Write node. It keeps writing error 'the value must be between \>= 0 and \<= 0. How to solve this ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 20:56 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/2 "2020-11-25T20:56:14Z")

</div>

Hi, could you post your flow please (only the relevant parts).

A screenshot of the error (and a copy of debug output would be good too)

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 21:39 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/3 "2020-11-25T21:39:13Z")

</div>

Attached here the screenshot from command line

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78221f2e8e50c445705bfcb16430f52b60b21c15.png) ![mc_write_node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3ebb183ca598fba90341cca751d4d54c34ac711a.png)

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 21:41 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/4 "2020-11-25T21:41:16Z")

</div>

I found that my customer uses M114 (BOOL datatype) for this command from their HMI.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 21:57 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/5 "2020-11-25T21:57:48Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/a/eaa3de7291d4fbbcd353b487150fc00f0e7c98f1.png)

You are trying to write a string of true to a bit

change it to number and value 1

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/4/94caabe9c4435be7904187131c709051975d0e5a.png)

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 22:09 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/6 "2020-11-25T22:09:49Z")

</div>

Still the same offset out of range error. Is my address definition correct in the node ? I'm not quiet understand the definition from the mc-write help notice

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 22:14 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/7 "2020-11-25T22:14:53Z")

</div>

Add a catch node and debug nodes

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

ensure debug nodes are set to show full message

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/894f7a891114fac4f95d447b380e5e53e004c220.png)

then copy any output from the debug window using the copy button

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

and paste any debug output in a reply

`````  
`paste between backticks like this`  
`````

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 22:19 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/8 "2020-11-25T22:19:05Z")

</div>

Also, could you please export your MC Write node.

select the node, press CTRL+E, click "copy" then paste the flow in a reply  
`````  
`paste like this`  
`````

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 22:33 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/9 "2020-11-25T22:33:48Z")

</div>

```auto
mcWriteDetails: object
isGood: false
quality: 0
TAG: "Y30"
addr: "Y30"
timeTaken: 0
timeStamp: 1606276033084
problem: true

```

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 22:36 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/10 "2020-11-25T22:36:39Z")

</div>

```auto
[{"id":"d54d6867.815788","type":"MC Write","z":"d6b1168b.3df54","name":"","topic":"","connection":"bce6340b.f635c8","data":"1","address":"Y30","addressType":"str","dataType":"num","errorHandling":"throw","outputs":1,"x":490,"y":100,"wires":[["85c23b34.9d16d8"]]},{"id":"adb82038.ff9dd","type":"MC Write","z":"d6b1168b.3df54","name":"","topic":"","connection":"bce6340b.f635c8","data":"1","address":"M125","addressType":"str","dataType":"num","errorHandling":"throw","outputs":1,"x":500,"y":220,"wires":[["9fca7a94.cf41d"]]},{"id":"bce6340b.f635c8","type":"MC Protocol Connection","name":"3403","host":"192.168.1.171","port":"2020","protocol":"TCP","frame":"3E","plcType":"Q","ascii":false,"PLCStation":"","PCStation":"","PLCModuleNo":"","network":"","octalInputOutput":false}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 22:51 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/11 "2020-11-25T22:51:07Z")

</div>

You have not copied like i said

> [@Steve-Mcl](#):
>
> then copy any output from the debug window using the copy button
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e3f3992b7f0e1ec50837cde62183b5e1f21625f8.png)
> 
> and paste any debug output in a reply

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 23:12 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/12 "2020-11-25T23:12:09Z")

</div>

```auto
{"_msgid":"33f0801f.b2dd4","payload":false,"topic":"","mcWriteDetails":{"isGood":false,"quality":0,"TAG":"M116,1","addr":"M116,1","timeTaken":0,"timeStamp":1606345908216,"problem":true}}

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 23:17 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/13 "2020-11-25T23:17:23Z")

</div>

> [@tunbendahara](#):
>
> `M116,1`

that is a different address to the flow you posted.

So are you still getting the error `"the value must be between >= 0 and <= 0"`?

Are you able to read any values?

Also, what happens if you set `address` to `M116,1` and the "data" dropdown to `csv` with a value of `1`  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a3d16d651e2508f7484d996610ccdf12467b25f8.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 23:18 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/14 "2020-11-25T23:18:54Z")

</div>

Also, unless you Reply to me, I dont get a notification.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/673d75e84ec4faac412b8edd7b13c2b87070e782.png)

Also, you are not using backticks ````` to format your code - it is un-importable.

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 23:19 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/15 "2020-11-25T23:19:33Z")

</div>

Still same problem. fortunately it works when i simulate using script from peopleplc/mcprotocol (not trying to compare 🙏)

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 23:20 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/16 "2020-11-25T23:20:44Z")

</div>

Still same problem. fortunately it works when i simulate using script from peopleplc/mcprotocol (not trying to compare 🙏)

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 23:22 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/17 "2020-11-25T23:22:27Z")

</div>

'''  
[{"id":"adb82038.ff9dd","type":"MC Write","z":"d6b1168b.3df54","name":"","topic":"","connection":"bce6340b.f635c8","data":"1","address":"M118,1","addressType":"str","dataType":"csv","errorHandling":"throw","outputs":1,"x":500,"y":220,"wires":[["9fca7a94.cf41d"]]},{"id":"bce6340b.f635c8","type":"MC Protocol Connection","name":"3403","host":"192.168.1.171","port":"2020","protocol":"TCP","frame":"3E","plcType":"Q","ascii":false,"PLCStation":"","PCStation":"","PLCModuleNo":"","network":"","octalInputOutput":false}]  
'''

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [25 November 2020 23:22 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/18 "2020-11-25T23:22:57Z")

</div>

could you answer questions?

> [@Steve-Mcl](#):
>
> Are you able to read any values?

> [@Steve-Mcl](#):
>
> So are you still getting the error `"the value must be between >= 0 and <= 0"` ?

* * *

NOTE...

I am not in a position to test this with a PLC right now.

Will take a look tomorrow if I get a chance.

---

<div class="post-metadata">

**Author:** ![tunbendahara](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@tunbendahara](https://discourse.nodered.org/u/tunbendahara)\
**Post date:** [25 November 2020 23:23 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/19 "2020-11-25T23:23:00Z")

</div>

'''  
{"isGood":false,"quality":0,"TAG":"M118,1","addr":"M118,1","timeTaken":0,"timeStamp":1606346503368,"problem":true}  
'''

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 November 2020 20:48 UTC](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529/20 "2020-11-26T20:48:24Z")

</div>

@tunbendahara Please try the latest update now in flows library ( ~~V1.1.6~~ V1.1.7)

you can update via node-red manage pallete (but you will need to restart node-red afterwards)

You can set individual buts using bools `true` / `false` or ints `0` / `1`

If you wish to set multiples bits you can send an array

#### Address Examples...

- Write 4 bits
  - Address: `M110,4`
  - Value Type: csv
  - Value `0,1,0,1`

- Write 1 int16
  - Address: `K4M110`
  - Value Type: number
  - Value `12345`

| Address Example | Data Type | Notes |
| --- | --- | --- |
| K4Y0 | int16 | `−32,768` to `32,767` |
| DSTR0,10 | string | Up to 10 chars long |
| DUINT0,10 | UINT[10] | 10 WD array containing values `0` to `65535` |
| Y0 | bit | 0 / 1 |
| RINT0,20 | int16 | Array of ints `−32,768` to `32,767` |
| D4800.0,16 | bool array | Array of 16 bools `D4800.0` ~ `D4800.F` |

[Next page](https://discourse.nodered.org/t/mc-protocol-how-to-use-mc-write-node/36529.md?page=2)
