- * 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=="); }