# Omron NJ OPC UA write to the PLC not working

**URL:** <https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446>\
**Category:** Industrial\
**Created:** [28 June 2022 08:41 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446 "2022-06-28T08:41:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMSMARTINS](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@AMSMARTINS](https://discourse.nodered.org/u/AMSMARTINS)\
**Post date:** [28 June 2022 08:41 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/1 "2022-06-28T08:41:51Z")

</div>

Hi all.  
After trying everything , I get into a dead end.  
I know there is some similar topics on this forum but I tried everything and so far no luck to get the OPCUA to write values into the plc.  
I tried with the OCPUA item before the OCPUA Client , without OCPUA Item ...  
I can **READ** values form the NJ PLC (I'm using **UA Expert** ) with no problems.  
Did anyone tried to do the same with a Omron NJ PLC?  
Bellow some print screens showing what I have done so far.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85d66a969aa7aa123795ccc3607a6b39202012d9.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/0/70fd49fb3b85310c7adad5274d0f18e1a08d2f34.png)

FYI: I tried as well with the extension ns=4;s=NodeRed\_Start,datatype:Boolean in the inject object but no difference at all .

Thanks in advance

---

<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:** [28 June 2022 09:11 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/2 "2022-06-28T09:11:28Z")

</div>

I didnt have much success with writing via OPC to NJ PLC but I did with FINS using `node-red-contrib-omron-fins`

From the [readme](https://flows.nodered.org/node/node-red-contrib-omron-fins):

> FINS works with PLC Addresses. NJ and NX PLCs do NOT have direct addresses to addresses like DM or E0\_, E1\_.
> 
> - In order to use C Series addresses in an N Series PLC, you will need to create a variable in the PLC and set its `AT` property. E.G. If you want to read and write 40 WDs from E0\_9000 ~ E0\_9039 then you need to add a TAG like this `TAG_NAME ARRAY[0..39] Of WORD %E0_9000` [![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/3/d3c7409d9107ff46342038ee61a2eaebfc8aae32.png)](https://user-images.githubusercontent.com/44235289/85562713-a619ad80-b624-11ea-971b-dc22754d7cf1.png)

---

<div class="post-metadata">

**Author:** ![AMSMARTINS](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@AMSMARTINS](https://discourse.nodered.org/u/AMSMARTINS)\
**Post date:** [28 June 2022 10:04 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/3 "2022-06-28T10:04:30Z")

</div>

Thanks for your reply.  
I think write values to the NJ doesn't work, and probably I have to try FINS.  
Have you got smc sysmac file that you can share ?  
Thanks

---

<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:** [28 June 2022 10:26 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/4 "2022-06-28T10:26:19Z")

</div>

> [@AMSMARTINS](#):
>
> Have you got smc sysmac file that you can share ?

Sorry, no (ex company property)

But really easy - just add global tags and assign `AT` addresses. Then read/write from FINS to those `AT` addresses.

To keep things simple and consistent, I strongly recommend you create 2 arrays of WORD (100 long) - something like "DATA\_TO\_NODE\_RED" and "DATA\_FROM\_NODE\_RED" and assign them to something like `E0_1000` and `E0_2000` - this gives you plenty scope for future additions. Also, since values will be read/written in contiguous blocks, the data is consistent (i.e. read+written on the same scan of the PLC)

To help with conversion of data types (bytes, strings, floats etc), there is the companion nodes in the node-red-contrib-buffer-parser package.

---

<div class="post-metadata">

**Author:** ![AMSMARTINS](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@AMSMARTINS](https://discourse.nodered.org/u/AMSMARTINS)\
**Post date:** [28 June 2022 12:22 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/5 "2022-06-28T12:22:05Z")

</div>

Hi Steve.  
Thanks again for your reply.  
Don't know for sure what I'm doing wrong but , still not working.  
Please, can you look at the pictures bellow and give me some advise.

Sysmac settings for FINS

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

Node Red

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

Thanks again

---

<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:** [28 June 2022 12:32 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/6 "2022-06-28T12:32:10Z")

</div>

Read the Omron nodes built in help. The fins address should not start with a %.

Also, why are you specifying an array of 40 bools? Fins works with 16bit words.

I recommend you set-up as I proposed earlier then you can share the whole address range with other tags in the PLC without having to modify the coms in the future

---

<div class="post-metadata">

**Author:** ![AMSMARTINS](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@AMSMARTINS](https://discourse.nodered.org/u/AMSMARTINS)\
**Post date:** [28 June 2022 12:37 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/7 "2022-06-28T12:37:29Z")

</div>

Hi Steve.  
I manage to get it working.  
Sorry for my lack of knowledge, I thought could work with array of bool .  
I cant use as you said % before the address.  
So far not to bad.  
Thanks again Steve for your time.

---

<div class="post-metadata">

**Author:** ![AMSMARTINS](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@AMSMARTINS](https://discourse.nodered.org/u/AMSMARTINS)\
**Post date:** [28 June 2022 13:43 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/8 "2022-06-28T13:43:14Z")

</div>

Hi Steve , just another question.  
I have created and array of 40 positions of 16 bit Words.  
I can see as well the values are coming into the plc in Hex format.  
I would like to know if is possible to change the state of the 16 bits individually for example  
Array[0]= 0000 0000 0000 0001 or 0000 0000 0000 0010 from red-node.  
If not there is always the option to send an Hex value and use it on the plc.

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

Thanks again

---

<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:** [28 June 2022 14:38 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/9 "2022-06-28T14:38:54Z")

</div>

> [@AMSMARTINS](#):
>
> I would like to know if is possible to change the state of the 16 bits individually for example  
> Array[0]= 0000 0000 0000 0001 or 0000 0000 0000 0010 from red-node

No, FINS reads and writes in WORD values

> [@AMSMARTINS](#):
>
> If not there is always the option to send an Hex value and use it on the plc.

Yes, use function node or JSONata in change node or the buffer-maker node to generate a WORD and write that.  
BUT: Be mindful if you set a BIT in a WORD, all BITS will be written.

There are several options...

1. it is safer to use 1 WORD per BIT
2. Use status numbers (e.g. 1 = RUN, 2=STOP, 3=MANUAL MODE) etc
3. Read WORD → set/reset BIT → WRITE WORD (see example below)

![chrome_Q03hqBCBoM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae0ca8c71186684bae1a781f62fb8c788306eadc.gif)

Demo Flow (use CTRL+I to import)

```auto
[{"id":"ca252362.2b25d","type":"inject","z":"d8bcc25e815f0bc3","name":"....... SET BIT 7 (0000 0000 1000 0000)","props":[{"p":"topic","vt":"str"},{"p":"bit","v":"7","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SET","x":210,"y":840,"wires":[["5c3706dc0fedcf96"]]},{"id":"5c3706dc0fedcf96","type":"function","z":"d8bcc25e815f0bc3","name":"(FAKE) Read PLC D100","func":"msg.payload = flow.get(\"D100\") || 0\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":840,"wires":[["ab3d83e36d37d5af"]]},{"id":"ab3d83e36d37d5af","type":"function","z":"d8bcc25e815f0bc3","name":"Bit Operations","func":"\nconst ops = {\n GET(num, bit) {\n return ((num >> bit) % 2 != 0)\n },\n SET(num, bit) {\n return num | 1 << bit;\n },\n RESET(num, bit) {\n return num & ~(1 << bit);\n },\n TOGGLE(num, bit) {\n return ops.GET(num, bit) ? ops.RESET(num, bit) : ops.SET(num, bit);\n }\n}\n\nconst op = ops[msg.topic];\nif(!op) {\n node.error(`Bad topic '${msg.topic}'. Expected one of \"GET\",\"SET\",\"RESET\" or \"TOGGLE\" `, msg);\n}\nmsg.payload = op(msg.payload, msg.bit)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":840,"wires":[["91eb7a105be43c2d"]]},{"id":"02cd37dadd749199","type":"inject","z":"d8bcc25e815f0bc3","name":".. RESET BIT 7 (0000 0000 1000 0000)","props":[{"p":"topic","vt":"str"},{"p":"bit","v":"7","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"RESET","x":210,"y":880,"wires":[["5c3706dc0fedcf96"]]},{"id":"e8b5505c20f9e30e","type":"inject","z":"d8bcc25e815f0bc3","name":"TOGGLE BIT 2 (0000 0000 0000 0100)","props":[{"p":"topic","vt":"str"},{"p":"bit","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"TOGGLE","x":210,"y":800,"wires":[["5c3706dc0fedcf96"]]},{"id":"91eb7a105be43c2d","type":"function","z":"d8bcc25e815f0bc3","name":"(FAKE) Write PLC D100","func":"flow.set(\"D100\", msg.payload) \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":900,"wires":[["321cb40e7f7bfed4"]]},{"id":"321cb40e7f7bfed4","type":"debug","z":"d8bcc25e815f0bc3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":770,"y":900,"wires":[]}]

```

---

<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:** [27 August 2022 14:39 UTC](https://discourse.nodered.org/t/omron-nj-opc-ua-write-to-the-plc-not-working/64446/10 "2022-08-27T14:39:45Z")

</div>

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