# Error read/write Siemens Tag

**URL:** <https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [February 13, 2023, 11:11am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769 "2023-02-13T11:11:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefano.sforna](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@stefano.sforna](https://forum.inductiveautomation.com/u/stefano.sforna)\
**Post date:** [February 13, 2023, 11:11am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/1 "2023-02-13T11:11:22Z")

</div>

Goodmorning,

In the Wrapper.log, each 3-4 minutes I have this error message:

\*\*W [c.i.x.d.a.ScheduledRequest] [10:56:49]: Uncaught Throwable invoking class com.inductiveautomation.xopc.drivers.siemens.requests.ReadRequest#receiveMessage: java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 166 out of bounds for byte[142] \*\*  
**INFO | jvm 1 | 2023/02/13 11:57:10 |**

what is the cause???  
Error in function system.tag.readBlocking???

Thank You

Bye

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 13, 2023, 1:13pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/2 "2023-02-13T13:13:08Z")

</div>

That usually means you have an OPC tag pointing into a Siemens DB where the DB is actually shorter than where the tag is looking for your data. It tends to make bad quality in Ignition for the whole DB.

---

<div class="post-metadata">

**Author:** ![stefano.sforna](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@stefano.sforna](https://forum.inductiveautomation.com/u/stefano.sforna)\
**Post date:** [February 13, 2023, 4:33pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/3 "2023-02-13T16:33:13Z")

</div>

Ok,  
Can this error genetated with function system.tag.readBlocking or system.tag.writeBlocking ???

Thank You

Bye

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 13, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/4 "2023-02-13T17:43:23Z")

</div>

Not by readBlocking, no. That gets the most recent value delivered by the OPC subsystem. It isn't possible that writeBlocking could produce it, either, since the error says it was a "ReadRequest".

It **could** be produced by `system.opc.readValue()`, perhaps.

---

<div class="post-metadata">

**Author:** ![stefano.sforna](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@stefano.sforna](https://forum.inductiveautomation.com/u/stefano.sforna)\
**Post date:** [February 14, 2023, 7:37am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/5 "2023-02-14T07:37:28Z")

</div>

In the project, there isn't function `system.opc.readValue()`

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [February 14, 2023, 8:01am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/6 "2023-02-14T08:01:32Z")

</div>

Here is the documentation on system.opc.readValue:  
[https://docs.inductiveautomation.com/display/DOC81/system.opc.readValue](https://docs.inductiveautomation.com/display/DOC81/system.opc.readValue)

---

<div class="post-metadata">

**Author:** ![stefano.sforna](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@stefano.sforna](https://forum.inductiveautomation.com/u/stefano.sforna)\
**Post date:** [February 14, 2023, 8:20am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/7 "2023-02-14T08:20:24Z")

</div>

In my project, I don't use function system.opc.readValue

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [February 14, 2023, 8:21am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/8 "2023-02-14T08:21:39Z")

</div>

My apologies, it seems that I misunderstood.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 14, 2023, 1:15pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/9 "2023-02-14T13:15:37Z")

</div>

Then the only source for such a message would be an OPC tag's subscription.

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [September 14, 2023, 7:29am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/10 "2023-09-14T07:29:59Z")

</div>

I have a similar problem, I have the following DB:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/1/417b5ca484fd26c8170cff762a21a974789ad86c.png)

I’m trying to read the string located at address 200 which is a string of a length 42.  
No matter what I try I don’t get the correct value out of the PLC into Ignition.  
The only way I get something that is kind of correct is by doing:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/7/e7f62f4953a0b8cf45d3478d948e2d1f604a9a00.png)

You see the string: “Sphere REC ·Wk 37 – MaEoaEA--” The part of this string I need is: “Sphere REC” and for the string located at 244 I need the “Wk 37 - Ma” part of this string.  
When I use [RawMaterials]DB101,STRING200.42 the tag gives a bad value.  
I get the “arraycopy: last source index 151 out of bounds for byte[44]” error in the gateway.

Does somebody have the answer to my problem?

---

<div class="post-metadata">

**Author:** ![Hayden\_Watson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/hayden_watson/32/48792_2.png) [@Hayden\_Watson](https://forum.inductiveautomation.com/u/Hayden_Watson)\
**Post date:** [September 14, 2023, 7:43am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/11 "2023-09-14T07:43:16Z")

</div>

When you're reading a Siemens string keep in mind two bytes contain meta data.

So in my system we have a String[200] at offset 450, so my tag is configured to  
`ns=1;s=[{PLC Device Name}]DB100,STRING450.198`

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [September 14, 2023, 8:18am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/12 "2023-09-14T08:18:39Z")

</div>

This results in the following:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/8165999e57a2b0c234e1a0398c2bb9fb62dd5484.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/79f98323bd2aa5f54b5eb09c41caf8f49f819f48.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 14, 2023, 11:52am UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/13 "2023-09-14T11:52:16Z")

</div>

Can you get a Wireshark capture or something?

It seems that maybe the one or both of the length prefix bytes are indicating the wrong length.

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [September 14, 2023, 12:28pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/14 "2023-09-14T12:28:26Z")

</div>

Of course, I added to this post.  
The Ignition server IP is: 192.168.150.253  
The PLC IP is: 192.168.200.10  
The tag completed the read on: 2023-09-14 02:24:59PM  
[wiresharkForum.pcapng](https://forum.inductiveautomation.com/uploads/short-url/uJEQfF3hi7WroPquTot7YVNO0mQ.pcapng) (4.7 MB)

Also, I don't know if this can cause the problem but the load factor of the PLC is very high.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 14, 2023, 12:40pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/15 "2023-09-14T12:40:26Z")

</div>

> [@indenkleefj](#):
>
> 192.168.200.10

There is no traffic on this IP address in the capture.

Was the capture taken on the Gateway or on your own machine?

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [September 14, 2023, 12:53pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/16 "2023-09-14T12:53:31Z")

</div>

Sorry, I used the wrong network port.  
I used the server.  
Find the new attached.  
[wiresharkForum1.pcapng](https://forum.inductiveautomation.com/uploads/short-url/zdnX8kFZGmolC77KZ0E3XccKDzN.pcapng) (1.4 MB)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 14, 2023, 1:04pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/17 "2023-09-14T13:04:04Z")

</div>

The string is not being stored in correct S7 format in the PLC.

This is the resulting bytes for that read:

```auto
0000 20 95 53 70 68 65 72 65 20 52 45 43 00 00 00 00
0010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0020 00 00 00 00 00 00 00 00 00 00

```

The first two bytes indicate max length and actual length.

In this case:

- max length = 0x20 = 32
- actual length = 0x95 = 149

---

<div class="post-metadata">

**Author:** ![taglias](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@taglias](https://forum.inductiveautomation.com/u/taglias)\
**Post date:** [September 14, 2023, 1:12pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/18 "2023-09-14T13:12:24Z")

</div>

You should have two tags with item paths:  
[RawMaterials]DB101,STRING200.42  
[RawMaterials]DB101,STRING244.10

The string of length 42 occupies 44 bytes (the first byte is the maximum length, the second one actual length, or viceversa, I don't remember). If you declare these tags you should have no problem, unless you do something wrong on the PLC when writing the strings (you should use Siemens string functions, or be careful to write the first two bytes accordingly).

If you want to try if the problem is in the declaration of this two tags, just create a new device, RawMaterials2, and declare the two tags with item paths [RawMaterials2]... and verify if you still have the same error

---

<div class="post-metadata">

**Author:** ![indenkleefj](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/indenkleefj/32/10961_2.png) [@indenkleefj](https://forum.inductiveautomation.com/u/indenkleefj)\
**Post date:** [September 14, 2023, 1:52pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/19 "2023-09-14T13:52:50Z")

</div>

@Kevin.Herron this means I never will get a good result without changing the PLC?  
@taglias I tried these addresses and splitting but nothing is working.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 14, 2023, 1:54pm UTC](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769/20 "2023-09-14T13:54:29Z")

</div>

> [@indenkleefj](#):
>
> this means I never will get a good result without changing the PLC?

Yes, the strings are not being stored in the correct format, as @taglias mentioned as well.

> [@taglias](#):
>
> unless you do something wrong on the PLC when writing the strings (you should use Siemens string functions, or be careful to write the first two bytes accordingly).

[Next page](https://forum.inductiveautomation.com/t/error-read-write-siemens-tag/69769.md?page=2)
