# system.opc.readValue config error

**URL:** <https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916>\
**Category:** Ignition\
**Created:** [May 20, 2020, 4:56pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916 "2020-05-20T16:56:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 20, 2020, 4:56pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/1 "2020-05-20T16:56:44Z")

</div>

I am trying to test the OPC scripting function to read a tag. I enabled "Anonymous Access" in the OPC UA server settings, all my project tags are visible in the OPC UA tag browser. I copied the tag path of one of the tags and tried to read its value with the following code copied from the scripting examples, which is called in gateway startup script.

```python
def opctest():
	server = "Ignition OPC-UA Server"
	path = "ns=2;s=[default]/Tag 0"
	qualifiedValue = system.opc.readValue(server, path)
	print "Value: " + str(qualifiedValue.getValue())
	print "Quality: " + qualifiedValue.getQuality().toString()
	print "Timestamp: " + qualifiedValue.getTimestamp().toString()

```

I get error-

```python
INFO | jvm 1 | 2020/05/20 22:13:27 | Value: None
INFO | jvm 1 | 2020/05/20 22:13:27 | Quality: Error_Configuration
INFO | jvm 1 | 2020/05/20 22:13:27 | Timestamp: Sat May 16 21:53:21 IST 2020

```

What could be going wrong? I have the gateway server running, not in freeze.

---

<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:** [May 20, 2020, 5:09pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/2 "2020-05-20T17:09:17Z")

</div>

It’s probably because you copied the tag path instead of the OPC Item Path.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 20, 2020, 5:43pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/3 "2020-05-20T17:43:06Z")

</div>

I got the problem! Its is the server name " **Ignition OPC-UA Server**" given in the code snippet of the script function, should **not** have a **hyphen** , it should be " **Ignition OPC UA Server**"! That's something in the documentation of scripting function to be changed by you guys at IA! The code snippet contains a hyphen in the server name where as the actual OPC UA server name (atleast in version 8) doesn't have a hyphen! its working fine with that change.

```python
INFO | jvm 1 | 2020/05/20 23:07:08 | Value: 50.0
INFO | jvm 1 | 2020/05/20 23:07:08 | Quality: Good
INFO | jvm 1 | 2020/05/20 23:07:08 | Timestamp: Wed May 20 23:07:08 IST 2020

```

the code is:

```python
def opctest():
	server = "Ignition OPC UA Server"
	path = "ns=2;s=[default]/Tag 0"
	qualifiedValue = system.opc.readValue(server, path)
	print "Value: " + str(qualifiedValue.getValue())
	print "Quality: " + qualifiedValue.getQuality().toString()
	print "Timestamp: " + qualifiedValue.getTimestamp().toString()

```

Please notice, the earlier code (copied from the code snippet), had a hyphen in the server name.

---

<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:** [May 20, 2020, 5:48pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/4 "2020-05-20T17:48:04Z")

</div>

Yeah… I guess we could update that snippet, but then if your system was an upgrade it would be wrong because upgrades still have the hyphen in the name.

Removing that hyphen in the name of the default/loopback OPC UA connection on new installs of 8 was an unfortunate mistake that didn’t get caught before Ignition 8 was released.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 20, 2020, 5:50pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/5 "2020-05-20T17:50:26Z")

</div>

Oh, that's ok then.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 20, 2020, 5:56pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/6 "2020-05-20T17:56:35Z")

</div>

Another strange thing I found , I just tried to increment the value by one and write back to tag and print it. I find the value is not incremented, though , it changes in Tag DB eventually ! So there is a delay . Is it due to write being async!

code is :

```python
def opctest():
	server = "Ignition OPC UA Server"
	path = "ns=2;s=[default]/Tag 0"
	qualifiedValue = system.opc.readValue(server, path)
	print "Value: " + str(qualifiedValue.getValue())
	print "Quality: " + qualifiedValue.getQuality().toString()
	print "Timestamp: " + qualifiedValue.getTimestamp().toString()
	

	oldQualifiedValue = system.opc.readValue(server, path)
	newValue = oldQualifiedValue.getValue() + 1
	returnQuality = system.opc.writeValue(server, path, newValue)
	if returnQuality.isGood():
		print "Write was successful"
		print "Value: " + str(qualifiedValue.getValue())
		print "Quality: " + qualifiedValue.getQuality().toString()
		print "Timestamp: " + qualifiedValue.getTimestamp().toString()
	else:
		print "Write failed"

```

Output is-

```python
INFO | jvm 1 | 2020/05/20 23:21:41 | Value: 51.0
INFO | jvm 1 | 2020/05/20 23:21:41 | Quality: Good
INFO | jvm 1 | 2020/05/20 23:21:41 | Timestamp: Wed May 20 23:21:41 IST 2020
INFO | jvm 1 | 2020/05/20 23:21:41 | Write was successful
INFO | jvm 1 | 2020/05/20 23:21:41 | Value: 51.0
INFO | jvm 1 | 2020/05/20 23:21:41 | Quality: Good
INFO | jvm 1 | 2020/05/20 23:21:41 | Timestamp: Wed May 20 23:21:41 IST 2020

```

---

<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:** [May 20, 2020, 5:59pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/7 "2020-05-20T17:59:39Z")

</div>

You’re not reading the value back at any point after you write it. The QualifiedValue object is never going to change or update.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 20, 2020, 6:06pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/8 "2020-05-20T18:06:00Z")

</div>

Oh silly me! It works with reading new value after write

```python
def opctest():
	server = "Ignition OPC UA Server"
	path = "ns=2;s=[default]/Tag 0"
	qualifiedValue = system.opc.readValue(server, path)
	print "Value: " + str(qualifiedValue.getValue())
	print "Quality: " + qualifiedValue.getQuality().toString()
	print "Timestamp: " + qualifiedValue.getTimestamp().toString()
	

	oldQualifiedValue = system.opc.readValue(server, path)
	newValue = oldQualifiedValue.getValue() + 1
	returnQuality = system.opc.writeValue(server, path, newValue)
	qualifiedValue = system.opc.readValue(server, path)
	if returnQuality.isGood():
		print "Write was successful"
		print "Value: " + str(qualifiedValue.getValue())
		print "Quality: " + qualifiedValue.getQuality().toString()
		print "Timestamp: " + qualifiedValue.getTimestamp().toString()
	else:
		print "Write failed"

```

output is-

```python
INFO | jvm 1 | 2020/05/20 23:33:18 | Value: 52.0
INFO | jvm 1 | 2020/05/20 23:33:18 | Quality: Good
INFO | jvm 1 | 2020/05/20 23:33:18 | Timestamp: Wed May 20 23:33:18 IST 2020
INFO | jvm 1 | 2020/05/20 23:33:18 | Write was successful
INFO | jvm 1 | 2020/05/20 23:33:18 | Value: 53.0
INFO | jvm 1 | 2020/05/20 23:33:18 | Quality: Good
INFO | jvm 1 | 2020/05/20 23:33:18 | Timestamp: Wed May 20 23:33:18 IST 2020

```

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 21, 2020, 5:28am UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/9 "2020-05-21T05:28:39Z")

</div>

I have a few more questions -

1. Does the Ignition OPC UA server provide the subscription function ? Why is it not supported in the scripting library?
2. Are all the client methods defined in the spec for client classes implemented in the server?
3. Is there any sample client code available in java or any other language like python for reference?

---

<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:** [May 21, 2020, 11:51am UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/10 "2020-05-21T11:51:50Z")

</div>

> 1. Does the Ignition OPC UA server provide the subscription function ? Why is it not supported in the scripting library?

Yes, but there's not really a compelling reason to make it available via scripting. Most scripts don't have an appropriate lifecycle to create a monitored item and delete it when they are done, and if you want a continually updated value you can already just access an OPC tag from scripting.

> 1. Are all the client methods defined in the spec for client classes implemented in the server?

The spec defines services. The server implements the required ones for the "Standard UA Server" profile.

> 1. Is there any sample client code available in java or any other language like python for reference?

Not really sure what you're asking for here. Sample client code to talk an OPC UA server outside of Ignition?

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 21, 2020, 11:55am UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/11 "2020-05-21T11:55:40Z")

</div>

> [@Kevin.Herron](#):
>
> Yes, but there’s not really a compelling reason to make it available via scripting. Most scripts don’t have an appropriate lifecycle to create a monitored item and delete it when they are done, and if you want a continually updated value you can already just access an OPC tag from scripting.

Makes sense! Its useful only for external applications

> [@Kevin.Herron](#):
>
> The spec defines services. The server implements the required ones for the “Standard UA Server” profile.

Got it. Thanks.

> [@Kevin.Herron](#):
>
> Not really sure what you’re asking for here. Sample client code to talk an OPC UA server outside of Ignition?

Exactly! Something in java or python , so that we can use code snippets from it!.

---

<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:** [May 21, 2020, 11:56am UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/12 "2020-05-21T11:56:35Z")

</div>

> [@prafull\_j](#):
>
> Exactly! Something in java or python , so that we can use code snippets from it!.

Use them where? You can't use it in Ignition so I'm not sure what the purpose would be.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 21, 2020, 11:58am UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/13 "2020-05-21T11:58:02Z")

</div>

> [@Kevin.Herron](#):
>
> Use them where? You can’t use it in Ignition so I’m not sure what the purpose would be.

In our modules for ignition.

---

<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:** [May 21, 2020, 12:00pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/14 "2020-05-21T12:00:09Z")

</div>

Only a driver module would have any kind of access to OPC UA APIs, and even then it’s only the server API.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 21, 2020, 12:04pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/15 "2020-05-21T12:04:33Z")

</div>

No our external applications will access the Ignition opc ua server thru the services to browse its address space, subscribe to events, tags etc.

---

<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:** [May 21, 2020, 12:05pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/16 "2020-05-21T12:05:31Z")

</div>

Then your external applications are presumably using some kind of OPC UA toolkit or SDK and you should find code examples that are specific to that SDK.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 21, 2020, 12:08pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/17 "2020-05-21T12:08:33Z")

</div>

Ok, that's what I was also thinking about. I did see the prosys sdk some time back for examples. However you had mentioned on the forum or LinkedIn some python based library. I think it would also be a good reference.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 23, 2020, 12:58pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/18 "2020-05-23T12:58:26Z")

</div>

While trying to connect to Ignition OPC UA server with py commands "client=Client("opc.tcp://127.0.0.1:62541")" and "client.connect()" on localhost, I get following error:

`ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it`

The Ignition server is running on local mode. What could be the problem.

---

<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:** [May 23, 2020, 1:02pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/19 "2020-05-23T13:02:57Z")

</div>

Does it work if you use “localhost” instead of 127.0.0.1? Is the Ignition loopback connection good?

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [May 23, 2020, 1:05pm UTC](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916/20 "2020-05-23T13:05:11Z")

</div>

No, the same error

```python
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python38\lib\site-packages\opcua\client\client.py", line 272, in connect
    self.connect_socket()
  File "C:\Python38\lib\site-packages\opcua\client\client.py", line 297, in connect_socket
    self.uaclient.connect_socket(self.server_url.hostname, self.server_url.port)
  File "C:\Python38\lib\site-packages\opcua\client\ua_client.py", line 256, in connect_socket
    return self._uasocket.connect_socket(host, port)
  File "C:\Python38\lib\site-packages\opcua\client\ua_client.py", line 155, in connect_socket
    sock = socket.create_connection((host, port), timeout=self.timeout)
  File "C:\Python38\lib\socket.py", line 808, in create_connection
    raise err
  File "C:\Python38\lib\socket.py", line 796, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

```

[Next page](https://forum.inductiveautomation.com/t/system-opc-readvalue-config-error/34916.md?page=2)
