# Writing on PLC S7 node works only 25% of the times

**URL:** https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729
**Category:** Industrial
**Created:** [3 June 2020 18:35 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729 "2020-06-03T18:35:57Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [3 June 2020 18:35 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/1 "2020-06-03T18:35:57Z")

</div>

Hello every one! After digging about PLC conection, could find this "strange" problem here or in google. Thank you for taking the time to read!

I created a simple flow to control a PLC digital input (I0.0).  
I use "inject" to enter the "true" value into the PLC. Works, but I **need to press 3-4 times to make it work.** Sometimes it will work at the first atempt. So it hard to investigate as it randomly works.  
Im on win 10, PLC S/ 1200, ethernet direct connection, put/get allowed, disabled optimized access.  
The code:  
`[{"id":"11e16088.8ea65f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4a7fc439.439e2c","type":"s7 out","z":"11e16088.8ea65f","endpoint":"98c0118e.a1148","variable":"DIN1","name":"escritura_PLC_1200","x":860,"y":360,"wires":[]},{"id":"71217c4c.7c1c94","type":"inject","z":"11e16088.8ea65f","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":360,"wires":[["4a7fc439.439e2c","401f79be.d9d9a8"]]},{"id":"401f79be.d9d9a8","type":"debug","z":"11e16088.8ea65f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":560,"wires":[]},{"id":"b97d2639.d7c068","type":"inject","z":"11e16088.8ea65f","name":"RESET","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":420,"wires":[["d11c295a.59a6c8","401f79be.d9d9a8"]]},{"id":"d11c295a.59a6c8","type":"s7 out","z":"11e16088.8ea65f","endpoint":"98c0118e.a1148","variable":"Reset","name":"escritura_PLC_1200","x":860,"y":420,"wires":[]},{"id":"98c0118e.a1148","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.192","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"plc_s7_1200","vartable":[{"addr":"I0.0","name":"DIN1"},{"addr":"I0.4","name":"Reset"}]}]`

I attach a pic of the s7 node´s configuration  
Any suggestions?

 ![Anotación 2020-06-03 203205](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/4/b412dce67c4afc33e918c01e7bbef98b41da853d.png)

---

<div class="post-metadata">

### Author: ![machadotiago](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/machadotiago/32/23776_2.png) [@machadotiago](https://discourse.nodered.org/u/machadotiago)
#### Post date: [3 June 2020 20:45 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/2 "2020-06-03T20:45:11Z")

</div>

Hi,  
actually it should never work. As far as I can see from your flow you are setting I0.0 and I0.4 which are Input addresses. Those address should be used only for reading purposes (not writing).  
Once you command the PLC to set an Input to HIGH it will put the state of that address to HIGH but in the scan next cycle (which is just in a few milliseconds) the PLC will read the physical input value and set it to LOW.  
If you are just starting to learn, try using M0.0 or even M1.0 as an address for your tests ;).

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [3 June 2020 20:55 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/3 "2020-06-03T20:55:32Z")

</div>

Hello Tiago, its really nice to have you commenting my post 🙂  
I suspected that I should work with Memory yeah.  
Yes , im 2 weeks in PLC and Edge stuff so far... Just trying to understand it, im more interested in the data analytics side.  
The reason why it seldomnly works might be because of the latching:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/b/9b8d1b325dead72f3b681b2241618e83d9092fda.png)  
Thank you!

---

<div class="post-metadata">

### Author: ![machadotiago](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/machadotiago/32/23776_2.png) [@machadotiago](https://discourse.nodered.org/u/machadotiago)
#### Post date: [3 June 2020 21:04 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/4 "2020-06-03T21:04:39Z")

</div>

Great and welcome to the forum!  
Just please use this guide to share your flow next time [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506) 😉

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [3 June 2020 21:13 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/5 "2020-06-03T21:13:04Z")

</div>

Thanks! actually I followed those indications, pasted the code, selected it and pressed \</\>  
What am I missing?

---

<div class="post-metadata">

### Author: ![machadotiago](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/machadotiago/32/23776_2.png) [@machadotiago](https://discourse.nodered.org/u/machadotiago)
#### Post date: [3 June 2020 21:56 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/6 "2020-06-03T21:56:01Z")

</div>

Not sure what went wrong, but it should look like this:

```auto
[{"id":"11e16088.8ea65f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4a7fc439.439e2c","type":"s7 out","z":"11e16088.8ea65f","endpoint":"98c0118e.a1148","variable":"DIN1","name":"escritura_PLC_1200","x":860,"y":360,"wires":[]},{"id":"71217c4c.7c1c94","type":"inject","z":"11e16088.8ea65f","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":360,"wires":[["4a7fc439.439e2c","401f79be.d9d9a8"]]},{"id":"401f79be.d9d9a8","type":"debug","z":"11e16088.8ea65f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":560,"wires":[]},{"id":"b97d2639.d7c068","type":"inject","z":"11e16088.8ea65f","name":"RESET","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":370,"y":420,"wires":[["d11c295a.59a6c8","401f79be.d9d9a8"]]},{"id":"d11c295a.59a6c8","type":"s7 out","z":"11e16088.8ea65f","endpoint":"98c0118e.a1148","variable":"Reset","name":"escritura_PLC_1200","x":860,"y":420,"wires":[]},{"id":"98c0118e.a1148","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.192","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"plc_s7_1200","vartable":[{"addr":"I0.0","name":"DIN1"},{"addr":"I0.4","name":"Reset"}]}]

```

Probably there were some line jumps in your flow and it caused the wrong format.

---

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [3 June 2020 22:23 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/7 "2020-06-03T22:23:34Z")

</div>

You need to export it as "compact", not "formatted" to get the one line version. You can select that at the bottom of the export dialog.

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [3 June 2020 22:50 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/8 "2020-06-03T22:50:06Z")

</div>

Thanks kuema,  
I did use "compact" exporting, and after selecting and pressing \</\> no changes:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7fb177aff10e3963502b2bdf845c92477e28f042.png)  
must be something else?

---

<div class="post-metadata">

### Author: ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)
#### Post date: [4 June 2020 04:29 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/9 "2020-06-04T04:29:21Z")

</div>

Ah, you need to use three backticks, in the screenshot I can see only one.

Like

````
```
(flow json as compact one-liner)
```

````

But the `</>` button should do exactly that. Strange. 🤔

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [4 June 2020 08:14 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/10 "2020-06-04T08:14:01Z")

</div>

> [@Fdelahoya](#):
>
> after selecting and pressing \</\> no changes

You have to click the button, then paste the code between the lines with backticks.

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [4 June 2020 18:20 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/11 "2020-06-04T18:20:37Z")

</div>

Using M´s worked perfectly, thank you very much @machadotiago😉  
In the other hand, @Colin, it worked, now I can post the one-lined code. Just so you know, I would rewrite the explanatory post, as it says to PAste, select code, and then press \</\>, will lead to error.  
Thank you all!!!!

```auto
[{"id":"11e16088.8ea65f","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4a7fc439.439e2c","type":"s7 out","z":"11e16088.8ea65f","endpoint":"98c0118e.a1148","variable":"input 1","name":"escritura_PLC_1200","x":860,"y":360,"wires":[]},{"id":"71217c4c.7c1c94","type":"inject","z":"11e16088.8ea65f","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":510,"y":240,"wires":[["4a7fc439.439e2c","401f79be.d9d9a8"]]},{"id":"401f79be.d9d9a8","type":"debug","z":"11e16088.8ea65f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":650,"y":560,"wires":[]},{"id":"b97d2639.d7c068","type":"inject","z":"11e16088.8ea65f","name":"true","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":490,"y":400,"wires":[["401f79be.d9d9a8","4a7fc439.439e2c"]]},{"id":"6a99d2ab.f0faac","type":"s7 out","z":"11e16088.8ea65f","endpoint":"98c0118e.a1148","variable":"input 2","name":"escritura_PLC_1200","x":860,"y":420,"wires":[]},{"id":"98c0118e.a1148","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.192","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"2","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"plc_s7_1200","vartable":[{"addr":"M0.0","name":"input 1"},{"addr":"M0.1","name":"input 2"}]}]

```

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [4 June 2020 18:24 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/12 "2020-06-04T18:24:05Z")

</div>

I would like to emphatize that you guys made me feel really good, this is my first post and got help in minutes , amazing people here, you rock. 😘

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [4 June 2020 20:53 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/13 "2020-06-04T20:53:41Z")

</div>

> [@Fdelahoya](#):
>
> I would rewrite the explanatory post, as it says to PAste, select code, and then press \</\>, will lead to error.

I hadn't realised that you could do it that way, but I see you can. If you select a number of whole lines and then click the button it does add the backticks before and after it.  
Are you saying that does not work for you?  
I see in the example you posted that it has put single ticks in, which is what happens for me if you just select part of a line.  
What browser are you using?

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [4 June 2020 21:25 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/14 "2020-06-04T21:25:07Z")

</div>

Im using updated Chrome on win10.

So the instructions say: "The easiest way to do that is to paste in your code or flow json, select it all, then click the 'Preformatted Text' button in the toolbar:"

So I was doing that, and then only 1 tick appears, even if hardwrote 2 more, would not work.  
If you 1st press \</\>, then paste, it works fine.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 June 2020 07:57 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/15 "2020-06-05T07:57:04Z")

</div>

> [@Fdelahoya](#):
>
> even if hardwrote 2 more,

Can you post an image showing three backticks and it not working please? Are you definitely using backticks, not single quotes?

The select and click method works for me with Waterfox on Ubuntu, I don't use Windows so am unable to test it there.  
Perhaps someone else can try it with Chrome on Win 10 and confirm whether they also see an issue there.

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [5 June 2020 10:12 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/16 "2020-06-05T10:12:33Z")

</div>

![Anotación 2020-06-05 121327](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/0/0072311b202da10cdd5d1ea3f3723b66090a7785.png)

So if you follow the instructions, and paste the code, select , and then press \</\> you get the tick in the same line, therefore even if you put 3 ticks , wont work, beacause you dont have the line jump.  
If you press enter to do a line jump, it will work.  
Basically, it need to be clear that step one is pressing \</\>, and then paste the code, and not the other way around.

yes , I used backticks, as I just copied the auto-generated first tick.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [5 June 2020 10:34 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/17 "2020-06-05T10:34:24Z")

</div>

I have just tried it with Chrome (83.0.4103.97) on Ubuntu and selecting then clicking the button works, so I guess it must just be a Windows issue, or the specific version of Chrome, or something particular about your system.

---

<div class="post-metadata">

### Author: ![Fdelahoya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/fdelahoya/32/23262_2.png) [@Fdelahoya](https://discourse.nodered.org/u/Fdelahoya)
#### Post date: [5 June 2020 11:15 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/18 "2020-06-05T11:15:04Z")

</div>

My version is 83.0.4103.97 (Build oficial) (64 bits)  
Anyways, it works fine clicking then pasting.

---

<div class="post-metadata">

### Author: ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)
#### Post date: [6 June 2020 10:54 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/19 "2020-06-06T10:54:03Z")

</div>

I think the issue might be that the backticks need to be on separate lines.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 June 2020 12:24 UTC](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729/20 "2020-06-06T12:24:10Z")

</div>

Yes, but selecting multiple lines then clicking the button is supposed to put them in on separate lines (and does for me).

[Next page](https://discourse.nodered.org/t/writing-on-plc-s7-node-works-only-25-of-the-times/27729.md?page=2)
