You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by na...@apache.org on 2020/03/03 16:52:32 UTC
[plc4x] branch fix-OPC-wrong-paramhandling updated: [fix] Bug in
the regular expression of the variable address which includes the fix of
the issue #PLC4X-142 OPC-UA read variables
This is an automated email from the ASF dual-hosted git repository.
nalim2 pushed a commit to branch fix-OPC-wrong-paramhandling
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/fix-OPC-wrong-paramhandling by this push:
new 1775743 [fix] Bug in the regular expression of the variable address which includes the fix of the issue #PLC4X-142 OPC-UA read variables
1775743 is described below
commit 17757431e76f645ebb4e53bfc2e1731d0f771a60
Author: Matthias Milan Strljic <Ma...@gmail.com>
AuthorDate: Tue Mar 3 17:51:56 2020 +0100
[fix] Bug in the regular expression of the variable address which includes the fix of the issue #PLC4X-142 OPC-UA read variables
---
plc4j/drivers/opcua/pom.xml | 7 +++
.../plc4x/java/opcua/protocol/OpcuaField.java | 2 +-
.../apache/plc4x/java/opcua/ManualPLC4XOpcua.java | 55 ++++++++++++----------
3 files changed, 38 insertions(+), 26 deletions(-)
diff --git a/plc4j/drivers/opcua/pom.xml b/plc4j/drivers/opcua/pom.xml
index 77d0e5d..bcea377 100644
--- a/plc4j/drivers/opcua/pom.xml
+++ b/plc4j/drivers/opcua/pom.xml
@@ -61,6 +61,13 @@
</dependency>
<dependency>
+ <groupId>org.eclipse.milo</groupId>
+ <artifactId>server-examples</artifactId>
+ <version>0.3.6</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
index d304fd9..5f89516 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
@@ -31,7 +31,7 @@ import java.util.regex.Pattern;
*/
public class OpcuaField implements PlcField {
- public static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?<namespace>\\d+);(?<identifierType>[isgb])=((?<identifier>[\\w(.)-=]+))?");
+ public static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?<namespace>\\d+);(?<identifierType>[isgb])=((?<identifier>.+))?");
private final OpcuaIdentifierType identifierType;
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
index 89146db..4166edf 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
@@ -29,6 +29,7 @@ import org.apache.plc4x.java.base.model.SubscriptionPlcField;
import org.apache.plc4x.java.opcua.connection.OpcuaTcpPlcConnection;
import org.apache.plc4x.java.opcua.protocol.OpcuaField;
import org.apache.plc4x.java.opcua.protocol.OpcuaPlcFieldHandler;
+import org.eclipse.milo.examples.server.ExampleServer;
import java.math.BigInteger;
import java.time.Duration;
@@ -45,35 +46,40 @@ import java.util.function.Consumer;
* The current version is tested against a public server, which is to be replaced later by a separate instance of the Milo framework.
* Afterwards the code represented here will be used as an example for the introduction page.
* <p>
- * TODO: replace current public server with local Milo instance
*
- * Created by Matthias Milan Strljic on 10.05.2019
*/
public class ManualPLC4XOpcua {
- private static final String BOOL_IDENTIFIER = "ns=2;i=10844";
- private static final String BYTE_STRING_IDENTIFIER = "ns=2;i=10858";
- private static final String BYTE_IDENTIFIER = "ns=2;i=10846";
- private static final String DOUBLE_IDENTIFIER = "ns=2;i=10854";
- private static final String FLOAT_IDENTIFIER = "ns=2;i=10853";
- private static final String INT16_IDENTIFIER = "ns=2;i=10847";
- private static final String INT32_IDENTIFIER = "ns=2;i=10849";
- private static final String INT64_IDENTIFIER = "ns=2;i=10851";
- private static final String INTEGER_IDENTIFIER = "ns=2;i=10869";
- private static final String SBYTE_IDENTIFIER = "ns=2;i=10845";
- private static final String STRING_IDENTIFIER = "ns=2;i=10855";
- private static final String UINT16_IDENTIFIER = "ns=2;i=10848";
- private static final String UINT32_IDENTIFIER = "ns=2;i=10850";
- private static final String UINT64_IDENTIFIER = "ns=2;i=10852";
- private static final String UINTEGER_IDENTIFIER = "ns=2;i=10870";
+ private static final String BOOL_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Boolean";
+ private static final String BYTE_STRING_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/ByteString";
+ private static final String BYTE_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Byte";
+ private static final String DOUBLE_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Double";
+ private static final String FLOAT_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Float";
+ private static final String INT16_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Int16";
+ private static final String INT32_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Int32";
+ private static final String INT64_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Int64";
+ private static final String INTEGER_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/Integer";
+ private static final String SBYTE_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/SByte";
+ private static final String STRING_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/String";
+ private static final String UINT16_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/UInt16";
+ private static final String UINT32_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/UInt32";
+ private static final String UINT64_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/UInt64";
+ private static final String UINTEGER_IDENTIFIER = "ns=2;s=HelloWorld/ScalarTypes/UInteger";
private static final String DOES_NOT_EXIST_IDENTIFIER = "ns=2;i=12512623";
public static void main(String args[]) {
+ try {
+ ExampleServer testServer = new ExampleServer();
+ testServer.startup().get();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
OpcuaTcpPlcConnection opcuaConnection = null;
OpcuaPlcFieldHandler fieldH = new OpcuaPlcFieldHandler();
- PlcField field = fieldH.createField("ns=2;i=10855");
+ PlcField field = fieldH.createField(BOOL_IDENTIFIER);
try {
opcuaConnection = (OpcuaTcpPlcConnection)
- new PlcDriverManager().getConnection("opcua:tcp://localhost:4843?discovery=true");
+ new PlcDriverManager().getConnection("opcua:tcp://127.0.0.1:12686/milo?discovery=false");
} catch (PlcConnectionException e) {
e.printStackTrace();
@@ -104,19 +110,20 @@ public class ManualPLC4XOpcua {
PlcReadRequest request = builder.build();
PlcReadResponse response = opcuaConnection.read(request).get();
- Collection coll = response.getAllStrings("String");
+
+ //Collection coll = response.getAllStrings("String");
PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
wBuilder.addItem("w-Bool", BOOL_IDENTIFIER, true);
- wBuilder.addItem("w-ByteString", BYTE_STRING_IDENTIFIER, "TEST".getBytes());
- wBuilder.addItem("w-Byte", BYTE_IDENTIFIER, (byte) 1);
+ //wBuilder.addItem("w-ByteString", BYTE_STRING_IDENTIFIER, "TEST".getBytes());
+ wBuilder.addItem("w-Byte", BYTE_IDENTIFIER, (byte) 0x00);
wBuilder.addItem("w-Double", DOUBLE_IDENTIFIER, (double) 0.25);
wBuilder.addItem("w-Float", FLOAT_IDENTIFIER, (float) 0.25);
wBuilder.addItem("w-INT16", INT16_IDENTIFIER, (short) 12);
wBuilder.addItem("w-Int32", INT32_IDENTIFIER, (int) 314);
wBuilder.addItem("w-Int64", INT64_IDENTIFIER, (long) 123125);
wBuilder.addItem("w-Integer", INTEGER_IDENTIFIER, (int) 314);
- wBuilder.addItem("w-SByte", SBYTE_IDENTIFIER, (short) 23);
+ wBuilder.addItem("w-SByte", SBYTE_IDENTIFIER, (byte) 23);
wBuilder.addItem("w-String", STRING_IDENTIFIER, "TEST");
wBuilder.addItem("w-UInt16", UINT16_IDENTIFIER, (int) 222);
wBuilder.addItem("w-UInt32", UINT32_IDENTIFIER, (long) 21412);
@@ -191,5 +198,3 @@ public class ManualPLC4XOpcua {
}
}
}
-
-