diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 734c5a81404..d7ed1132ce5 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -27,6 +27,7 @@ Bug Fixes - PLC4X-163 Fixed Netty ByteBuf Leaks for S7 Driver - PLC4X-158 Added Warning if no Pooled Driver is used for Scraper - Fixed wrong connection address parameter handling which connects to a wrong address if there is no sub-address to a given IP + PORT combination +- PLC4X-142 OPC-UA read variables -- corrected RegEx ============================================================== Apache PLC4X 0.5.0 diff --git a/plc4j/drivers/opcua/pom.xml b/plc4j/drivers/opcua/pom.xml index 77d0e5dc017..bcea3773560 100644 --- a/plc4j/drivers/opcua/pom.xml +++ b/plc4j/drivers/opcua/pom.xml @@ -60,6 +60,13 @@ 0.3.6 + + org.eclipse.milo + server-examples + 0.3.6 + test + + org.apache.commons commons-lang3 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 d304fd93d19..5f895161140 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 @@ Licensed to the Apache Software Foundation (ASF) under one */ public class OpcuaField implements PlcField { - public static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?\\d+);(?[isgb])=((?[\\w(.)-=]+))?"); + public static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?\\d+);(?[isgb])=((?.+))?"); 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 89146dbfa49..4166edf300c 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 @@ Licensed to the Apache Software Foundation (ASF) under one 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 @@ Licensed to the Apache Software Foundation (ASF) under one * 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. *

- * 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 static void main(String args[]) { 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 @@ private long GetConnectionTime() { } } } - - diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java index e853552bc33..358727b4cac 100644 --- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java +++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java @@ -42,9 +42,16 @@ public void after() { @Test public void testOpcuaAddressPattern() { + //standard integer based param assertMatching(ADDRESS_PATTERN, "ns=2;i=10846"); + //string based address values assertMatching(ADDRESS_PATTERN, "ns=2;s=test.variable.name.inspect"); + assertMatching(ADDRESS_PATTERN, "ns=2;s=key param with some spaces"); + assertMatching(ADDRESS_PATTERN, "ns=2;s=\"aweired\".\"siemens\".\"param\".\"submodule\".\"param"); + assertMatching(ADDRESS_PATTERN, "ns=2;s=Weee314Waannaaa\\somenice=ext=a234a*#+1455!ยง$%&/()tttraaaaSymbols-.,,"); + // GUID address tests assertMatching(ADDRESS_PATTERN, "ns=2;g=09087e75-8e5e-499b-954f-f2a8624db28a"); + // binary encoded addresses assertMatching(ADDRESS_PATTERN, "ns=2;b=asvaewavarahreb=="); }