You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2019/05/19 19:38:59 UTC

[plc4x] branch develop updated (7f94d6c -> 3c00fa3)

This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a change to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


    from 7f94d6c  fixed typo in S7PlcConnection
     new 3d8a7e6  Add initial OPC UA project. This is a raw version of the project without any tests or refactoring in a first fully functional state.
     new 2801e63  Added NOTICE entry for the use of Milo
     new 98c62d0  Added Author field
     new b8c09b5  [Fixed] Failure while Timeout of write request [Added] requestTimeout field for variable timeouts
     new 2b98afa  Added test class bodies and renamed consistently
     new 21da7e6  [Fixed] JavaDoc formatting [Added] Warning messages at exception points with the consideration of adding later some run-time exceptions
     new 3c00fa3  [Added] descriptive class comments to ManualPLC4XOpcua

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 NOTICE                                             |   3 +
 plc4j/drivers/{simulated => opcua}/pom.xml         |  45 +-
 .../apache/plc4x/java/opcua/OpcuaPlcDriver.java}   |  57 +--
 .../opcua/connection/BaseOpcuaPlcConnection.java}  |  62 ++-
 .../opcua/connection/OpcuaConnectionFactory.java}  |  21 +-
 .../opcua/connection/OpcuaTcpPlcConnection.java    | 464 +++++++++++++++++++++
 .../plc4x/java/opcua/protocol/OpcuaField.java      | 118 ++++++
 .../java/opcua/protocol/OpcuaPlcFieldHandler.java  | 151 +++++++
 .../opcua/protocol/OpcuaSubsriptionHandle.java     |  81 ++++
 .../java/opcua/protocol/model/OpcuaDataTypes.java} |  34 +-
 .../opcua/protocol/model/OpcuaIdentifierType.java} |  41 +-
 .../services/org.apache.plc4x.java.spi.PlcDriver   |   2 +-
 .../apache/plc4x/java/opcua/ManualPLC4XOpcua.java  | 145 +++++++
 .../plc4x/java/opcua/OpcuaPlcDriverTest.java       |  67 +++
 .../org/apache/plc4x/java/opcua/UtilsTest.java}    |  29 +-
 .../connection/OpcuaTcpPlcConnectionTest.java}     |  25 +-
 .../plc4x/java/opcua/protocol/OpcuaFieldTest.java} |  43 +-
 .../opcua/protocol/OpcuaPlcFieldHandlerTest.java}  |  25 +-
 .../protocol/OpcuaSubscriptionHandleTest.java}     |  25 +-
 plc4j/drivers/pom.xml                              |   1 +
 20 files changed, 1256 insertions(+), 183 deletions(-)
 copy plc4j/drivers/{simulated => opcua}/pom.xml (63%)
 copy plc4j/drivers/{modbus/src/main/java/org/apache/plc4x/java/modbus/ModbusPlcDriver.java => opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java} (54%)
 copy plc4j/drivers/{modbus/src/main/java/org/apache/plc4x/java/modbus/connection/BaseModbusPlcConnection.java => opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java} (51%)
 copy plc4j/drivers/{modbus/src/main/java/org/apache/plc4x/java/modbus/connection/ModbusConnectionFactory.java => opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java} (63%)
 create mode 100644 plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
 create mode 100644 plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
 create mode 100644 plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
 create mode 100644 plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
 copy plc4j/{api/src/main/java/org/apache/plc4x/java/api/exceptions/PlcNotImplementedException.java => drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java} (64%)
 copy plc4j/drivers/{modbus/src/main/java/org/apache/plc4x/java/modbus/connection/ModbusConnectionFactory.java => opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java} (50%)
 copy plc4j/drivers/{ads => opcua}/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver (94%)
 create mode 100644 plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
 create mode 100644 plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
 copy plc4j/drivers/{simulated/src/main/java/org/apache/plc4x/java/simulated/connection/TestFieldItem.java => opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java} (56%)
 copy plc4j/{utils/opm/src/main/java/org/apache/plc4x/java/opm/OPMException.java => drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java} (69%)
 copy plc4j/{protocols/driver-bases/base/src/test/java/org/apache/plc4x/java/base/messages/DefaultPlcProprietaryRequestTest.java => drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java} (51%)
 copy plc4j/{utils/opm/src/main/java/org/apache/plc4x/java/opm/OPMException.java => drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java} (70%)
 copy plc4j/{utils/opm/src/main/java/org/apache/plc4x/java/opm/OPMException.java => drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java} (69%)


[plc4x] 01/07: Add initial OPC UA project. This is a raw version of the project without any tests or refactoring in a first fully functional state.

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 3d8a7e6f31b549ff5b4c85a28cbaff69eca281ef
Author: Matthias Milan Strljic <Ma...@gmail.com>
AuthorDate: Mon May 13 19:17:11 2019 +0200

    Add initial OPC UA project. This is a raw version of the project without any tests or refactoring in a first fully functional state.
---
 plc4j/drivers/opcua/pom.xml                        |  83 ++++
 .../apache/plc4x/java/opcua/OPCUAPlcDriver.java    |  99 +++++
 .../opcua/connection/BaseOPCUAPlcConnection.java   |  89 ++++
 .../opcua/connection/OPCUAConnectionFactory.java   |  36 ++
 .../opcua/connection/OPCUATcpPlcConnection.java    | 474 +++++++++++++++++++++
 .../plc4x/java/opcua/protocol/OpcuaField.java      | 115 +++++
 .../java/opcua/protocol/model/OpcuaDataTypes.java  |  43 ++
 .../opcua/protocol/model/OpcuaIdentifierType.java  |  26 ++
 .../opcua/protocol/model/OpcuaPlcFieldHandler.java | 146 +++++++
 .../protocol/model/OpcuaSubsriptionHandle.java     |  76 ++++
 .../services/org.apache.plc4x.java.spi.PlcDriver   |  19 +
 .../java/opcua/connection/ManualPLC4XOPCUA.java    | 125 ++++++
 plc4j/drivers/pom.xml                              |   1 +
 13 files changed, 1332 insertions(+)

diff --git a/plc4j/drivers/opcua/pom.xml b/plc4j/drivers/opcua/pom.xml
new file mode 100644
index 0000000..69a36cd
--- /dev/null
+++ b/plc4j/drivers/opcua/pom.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.plc4x</groupId>
+    <artifactId>plc4j-drivers</artifactId>
+    <version>0.4.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>plc4j-driver-opcua</artifactId>
+  <name>PLC4J: Driver: OPC UA</name>
+  <description>Implementation of a PLC4X driver able to speak with devices using the OPC UA protocol.</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-api</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-protocol-driver-base</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.eclipse.milo</groupId>
+      <artifactId>sdk-client</artifactId>
+      <version>0.3.0-M1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.milo</groupId>
+      <artifactId>stack-core</artifactId>
+      <version>0.3.0-M1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.milo</groupId>
+      <artifactId>stack-client</artifactId>
+      <version>0.3.0-M1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+    </dependency>
+  </dependencies>
+  <!--
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <configuration>
+          <usedDependencies combine.children="append">
+            <usedDependency>org.eclipse.milo:sdk-client</usedDependency>
+          </usedDependencies>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  -->
+</project>
\ No newline at end of file
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
new file mode 100644
index 0000000..68f3886
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
@@ -0,0 +1,99 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.authentication.PlcAuthentication;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcReadResponse;
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.PlcWriteResponse;
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.opcua.connection.OPCUAConnectionFactory;
+import org.apache.plc4x.java.opcua.connection.OPCUATcpPlcConnection;
+import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
+import org.apache.plc4x.java.spi.PlcDriver;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implementation of the OPC UA protocol, based on:
+ * - Eclipse Milo (https://github.com/eclipse/milo)
+ */
+public class OPCUAPlcDriver implements PlcDriver {
+
+
+
+    public static final Pattern INET_ADDRESS_PATTERN = Pattern.compile("tcp://(?<host>[\\w.-]+)(:(?<port>\\d*))?");
+    public static final Pattern OPCUA_URI_PATTERN = Pattern.compile("^opcua:(" + INET_ADDRESS_PATTERN + ")?" + "(?<params>/[\\w/]+)?");
+
+    private OPCUAConnectionFactory opcuaConnectionFactory;
+
+    public OPCUAPlcDriver() {
+        this.opcuaConnectionFactory = new OPCUAConnectionFactory();
+    }
+
+    public OPCUAPlcDriver(OPCUAConnectionFactory opcuaConnectionFactory) {
+        this.opcuaConnectionFactory = opcuaConnectionFactory;
+    }
+
+    @Override
+    public String getProtocolCode() {
+        return "opcua";
+    }
+
+    @Override
+    public String getProtocolName() {
+        return "OPC UA (TCP)";
+    }
+
+    @Override
+    public PlcConnection connect(String url) throws PlcConnectionException {
+        Matcher matcher = OPCUA_URI_PATTERN.matcher(url);
+
+        if (!matcher.matches()) {
+            throw new PlcConnectionException(
+                "Connection url doesn't match the format 'opcua:{type}//{port|host}'");
+        }
+
+        String host = matcher.group("host");
+        String portString = matcher.group("port");
+        Integer port = StringUtils.isNotBlank(portString) ? Integer.parseInt(portString) : null;
+        String params = matcher.group("params") != null ? matcher.group("params").substring(1) : null;
+
+        try {
+            return opcuaConnectionFactory.opcuaTcpPlcConnectionOf(InetAddress.getByName(host), port, params);
+        } catch (UnknownHostException e) {
+            throw new PlcConnectionException(e);
+        }
+    }
+
+    @Override
+    public PlcConnection connect(String url, PlcAuthentication authentication) throws PlcConnectionException {
+        throw new PlcConnectionException("opcua does not support Auth at this state");
+    }
+
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
new file mode 100644
index 0000000..b7221e2
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
@@ -0,0 +1,89 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.connection;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.base.connection.AbstractPlcConnection;
+import org.apache.plc4x.java.base.messages.*;
+import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public abstract class BaseOPCUAPlcConnection extends AbstractPlcConnection implements PlcReader, PlcWriter, PlcSubscriber {
+
+    private static final Logger logger = LoggerFactory.getLogger(BaseOPCUAPlcConnection.class);
+
+    BaseOPCUAPlcConnection(String params) {
+
+        if (!StringUtils.isEmpty(params)) {
+            for (String param : params.split("&")) {
+                String[] paramElements = param.split("=");
+                String paramName = paramElements[0];
+                if (paramElements.length == 2) {
+                    String paramValue = paramElements[1];
+                    switch (paramName) {
+                        default:
+                            logger.debug("Unknown parameter {} with value {}", paramName, paramValue);
+                    }
+                } else {
+                    logger.debug("Unknown no-value parameter {}", paramName);
+                }
+            }
+        }
+    }
+
+    @Override
+    public boolean canRead() {
+        return true;
+    }
+
+    @Override
+    public boolean canWrite() {
+        return true;
+    }
+
+    @Override
+    public PlcReadRequest.Builder readRequestBuilder() {
+        return new DefaultPlcReadRequest.Builder(this, new OpcuaPlcFieldHandler());
+    }
+
+    @Override
+    public PlcWriteRequest.Builder writeRequestBuilder() {
+        return new DefaultPlcWriteRequest.Builder(this, new OpcuaPlcFieldHandler());
+    }
+
+    @Override
+    public boolean canSubscribe() {
+        return true;
+    }
+
+    @Override
+    public PlcSubscriptionRequest.Builder subscriptionRequestBuilder() {
+        return new DefaultPlcSubscriptionRequest.Builder(this, new OpcuaPlcFieldHandler());
+    }
+
+    @Override
+    public PlcUnsubscriptionRequest.Builder unsubscriptionRequestBuilder() {
+        return new DefaultPlcUnsubscriptionRequest.Builder(this);
+    }
+
+
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
new file mode 100644
index 0000000..1bf0e60
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
@@ -0,0 +1,36 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+   http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.connection;
+
+import java.net.InetAddress;
+import java.util.Objects;
+
+public class OPCUAConnectionFactory {
+
+    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params) {
+        Objects.requireNonNull(address);
+
+        if (port == null) {
+            return OPCUATcpPlcConnection.of(address, params);
+        } else {
+            return OPCUATcpPlcConnection.of(address, port, params);
+        }
+    }
+
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
new file mode 100644
index 0000000..7235226
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
@@ -0,0 +1,474 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.connection;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
+
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.base.messages.*;
+import org.apache.plc4x.java.base.messages.items.*;
+import org.apache.plc4x.java.base.model.SubscriptionPlcField;
+import org.apache.plc4x.java.opcua.protocol.OpcuaField;
+import org.apache.plc4x.java.opcua.protocol.model.OpcuaSubsriptionHandle;
+import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
+import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
+import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
+import org.eclipse.milo.opcua.sdk.client.api.identity.IdentityProvider;
+import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
+import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaSubscription;
+import org.eclipse.milo.opcua.stack.client.DiscoveryClient;
+import org.eclipse.milo.opcua.stack.core.AttributeId;
+import org.eclipse.milo.opcua.stack.core.Identifiers;
+import org.eclipse.milo.opcua.stack.core.UaException;
+import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
+import org.eclipse.milo.opcua.stack.core.types.builtin.*;
+import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
+import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UShort;
+import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
+import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
+import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;
+import org.eclipse.milo.opcua.stack.core.types.structured.MonitoredItemCreateRequest;
+import org.eclipse.milo.opcua.stack.core.types.structured.MonitoringParameters;
+import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.math.BigInteger;
+import java.net.InetAddress;
+import java.time.Duration;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
+
+public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
+
+    private static final int OPCUA_DEFAULT_TCP_PORT = 4840;
+
+    private static final Logger logger = LoggerFactory.getLogger(OPCUATcpPlcConnection.class);
+    private InetAddress address;
+    private int port;
+    private String params;
+    private OpcUaClient client;
+    private boolean isConnected = false;
+    private  final AtomicLong clientHandles = new AtomicLong(1L);
+    private OPCUATcpPlcConnection(InetAddress address, String params) {
+        this( address, OPCUA_DEFAULT_TCP_PORT,  params);
+        logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
+    }
+
+    public OPCUATcpPlcConnection(InetAddress address, int port, String params) {
+        this(params);
+        logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
+        this.address = address;
+        this.port = port;
+        this.params = params;
+    }
+
+    public OPCUATcpPlcConnection(String params) {
+        super(params);
+    }
+
+    public static OPCUATcpPlcConnection of(InetAddress address, String params) {
+        return new OPCUATcpPlcConnection(address, params);
+    }
+
+    public static OPCUATcpPlcConnection of(InetAddress address, int port, String params) {
+        return new OPCUATcpPlcConnection(address, port, params);
+    }
+
+
+
+    public InetAddress getRemoteAddress() {
+        return null;
+    }
+
+    @Override
+    public void connect() throws PlcConnectionException {
+        List<EndpointDescription> endpoints =  null;
+
+        try {
+            endpoints = DiscoveryClient.getEndpoints(getEndpointUrl(address, port, params)).get();
+        } catch (Throwable ex) {
+            // try the explicit discovery endpoint as well
+            String discoveryUrl = getEndpointUrl(address, port, params);
+
+            if (!discoveryUrl.endsWith("/")) {
+                discoveryUrl += "/";
+            }
+            discoveryUrl += "discovery";
+
+            logger.info("Trying explicit discovery URL: {}", discoveryUrl);
+            try {
+                endpoints = DiscoveryClient.getEndpoints(discoveryUrl).get();
+            } catch (InterruptedException | ExecutionException e) {
+                e.printStackTrace();
+            }
+        }
+
+        EndpointDescription endpoint = null;
+        try {
+            endpoint = endpoints.stream()
+                .filter(e -> e.getSecurityPolicyUri().equals(getSecurityPolicy().getUri()))
+                .filter(endpointFilter())
+                .findFirst()
+                .orElseThrow(() -> new Exception("no desired endpoints returned"));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        OpcUaClientConfig config = OpcUaClientConfig.builder()
+            .setApplicationName(LocalizedText.english("eclipse milo opc-ua client"))
+            .setApplicationUri("urn:eclipse:milo:examples:client")
+            .setEndpoint(endpoint)
+            .setIdentityProvider(getIdentityProvider())
+            .setRequestTimeout(UInteger.valueOf(5000))
+            .build();
+
+        try {
+            this.client =  OpcUaClient.create(config);
+            this.client.connect().get();
+            isConnected = true;
+        } catch (UaException e) {
+            e.printStackTrace();
+        } catch (InterruptedException e) {
+            isConnected = false;
+        } catch (ExecutionException e) {
+            isConnected = false;
+        }
+    }
+
+    @Override
+    public boolean isConnected() {
+        return client != null && isConnected;
+    }
+
+    @Override
+    public void close() throws Exception {
+        if(client != null){
+            client.disconnect().get();
+            isConnected = false;
+        }
+    }
+
+    @Override
+    public CompletableFuture<PlcSubscriptionResponse> subscribe(PlcSubscriptionRequest subscriptionRequest) {
+        InternalPlcSubscriptionRequest internalPlcSubscriptionRequest = checkInternal(subscriptionRequest, InternalPlcSubscriptionRequest.class);
+        CompletableFuture<PlcSubscriptionResponse> future = CompletableFuture.supplyAsync(() ->{
+            Map<String, Pair<PlcResponseCode, PlcSubscriptionHandle>> responseItems = internalPlcSubscriptionRequest.getSubscriptionPlcFieldMap().entrySet().stream()
+            .map(subscriptionPlcFieldEntry -> {
+                final String plcFieldName = subscriptionPlcFieldEntry.getKey();
+                final SubscriptionPlcField subscriptionPlcField = subscriptionPlcFieldEntry.getValue();
+                final OpcuaField field = (OpcuaField)Objects.requireNonNull(subscriptionPlcField.getPlcField());
+                long cycleTime = subscriptionPlcField.getDuration().orElse(Duration.ofSeconds(1)).toMillis();
+                NodeId idNode = generateNodeId(field);
+                ReadValueId readValueId = new ReadValueId(
+                    idNode,
+                    AttributeId.Value.uid(), null, QualifiedName.NULL_VALUE);
+                UInteger clientHandle = uint(clientHandles.getAndIncrement());
+
+                MonitoringParameters parameters = new MonitoringParameters(
+                    clientHandle,
+                    (double) cycleTime,     // sampling interval
+                    null,       // filter, null means use default
+                    uint(1),   // queue size
+                    true        // discard oldest
+                );
+                MonitoringMode monitoringMode;
+                switch (subscriptionPlcField.getPlcSubscriptionType()) {
+                    case CYCLIC:
+                        monitoringMode = MonitoringMode.Sampling;
+                        break;
+                    case CHANGE_OF_STATE:
+                        monitoringMode = MonitoringMode.Reporting;
+                        break;
+                    case EVENT:
+                        monitoringMode = MonitoringMode.Reporting;
+                        break;
+                    default: monitoringMode = MonitoringMode.Reporting;
+                }
+
+                PlcSubscriptionHandle subHandle = null;
+                PlcResponseCode responseCode = PlcResponseCode.ACCESS_DENIED;
+                try {
+                    UaSubscription subscription = client.getSubscriptionManager().createSubscription(1000.0).get();
+
+                    MonitoredItemCreateRequest request = new MonitoredItemCreateRequest(
+                        readValueId, monitoringMode, parameters);
+                    List<MonitoredItemCreateRequest> requestList = new LinkedList<>();
+                    requestList.add(request);
+                    OpcuaSubsriptionHandle subsriptionHandle = new OpcuaSubsriptionHandle(plcFieldName, clientHandle);
+                    BiConsumer<UaMonitoredItem, Integer> onItemCreated =
+                        (item, id) -> item.setValueConsumer(subsriptionHandle::onSubscriptionValue);
+
+                    List<UaMonitoredItem> items = subscription.createMonitoredItems(
+                        TimestampsToReturn.Both,
+                        requestList,
+                        onItemCreated
+                    ).get();
+
+                    subHandle = subsriptionHandle;
+                    responseCode = PlcResponseCode.OK;
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                } catch (ExecutionException e) {
+                    e.printStackTrace();
+                }
+
+
+                return Pair.of(plcFieldName, Pair.of(responseCode, subHandle));
+            })
+            .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
+            PlcSubscriptionResponse result = new DefaultPlcSubscriptionResponse(internalPlcSubscriptionRequest, responseItems);
+            return result;
+        });
+
+        return future;
+    }
+
+    @Override
+    public CompletableFuture<PlcUnsubscriptionResponse> unsubscribe(PlcUnsubscriptionRequest unsubscriptionRequest) {
+        InternalPlcUnsubscriptionRequest internalPlcUnsubscriptionRequest = checkInternal(unsubscriptionRequest, InternalPlcUnsubscriptionRequest.class);
+        internalPlcUnsubscriptionRequest.getInternalPlcSubscriptionHandles().forEach(o -> {
+            OpcuaSubsriptionHandle opcSubHandle = (OpcuaSubsriptionHandle) o;
+            try {
+                client.getSubscriptionManager().deleteSubscription(opcSubHandle.getClientHandle()).get();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            } catch (ExecutionException e) {
+                e.printStackTrace();
+            }
+        });
+
+        return null;
+    }
+
+    @Override
+    public PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer, Collection<PlcSubscriptionHandle> handles) {
+        List<PlcConsumerRegistration> unregisters = new LinkedList<>();
+        handles.forEach(plcSubscriptionHandle -> unregisters.add(plcSubscriptionHandle.register(consumer)));
+
+        return () -> unregisters.forEach(PlcConsumerRegistration::unregister);
+    }
+
+    @Override
+    public void unregister(PlcConsumerRegistration registration) {
+        registration.unregister();
+    }
+
+    @Override
+    public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
+        CompletableFuture<PlcReadResponse> future = CompletableFuture.supplyAsync(() -> {
+            readRequest.getFields();
+            Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> fields = new HashMap<>();
+            List<NodeId> readValueIds = new LinkedList<>();
+            List<PlcField> readPLCValues = readRequest.getFields();
+            for (PlcField field: readPLCValues) {
+                NodeId idNode = generateNodeId((OpcuaField) field);
+                readValueIds.add(idNode);
+            }
+
+            CompletableFuture<List<DataValue>> dataValueCompletableFuture = client.readValues(0.0, TimestampsToReturn.Both, readValueIds);
+            List<DataValue> readValues = null;
+            try {
+                readValues = dataValueCompletableFuture.get();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+                readValues = new LinkedList<>();
+            } catch (ExecutionException e) {
+                e.printStackTrace();
+                readValues = new LinkedList<>();
+            }
+            for(int counter = 0; counter < readValues.size(); counter++){
+                PlcResponseCode resultCode = PlcResponseCode.OK;
+                BaseDefaultFieldItem stringItem = null;
+                if(readValues.get(counter).getStatusCode() != StatusCode.GOOD){
+                    resultCode = PlcResponseCode.NOT_FOUND;
+                }else{
+                    stringItem = encodeFieldItem(readValues.get(counter));
+
+                }
+                Pair<PlcResponseCode, BaseDefaultFieldItem> newPair = new ImmutablePair<>(resultCode, stringItem);
+                fields.put((String) readRequest.getFieldNames().toArray()[counter], newPair);
+
+
+            }
+            InternalPlcReadRequest internalPlcReadRequest = checkInternal(readRequest, InternalPlcReadRequest.class);
+            PlcReadResponse response = new DefaultPlcReadResponse(internalPlcReadRequest, fields );
+            return response;
+        });
+
+
+        return future;
+    }
+
+    private NodeId generateNodeId(OpcuaField uaField){
+        NodeId idNode = null;
+        switch (uaField.getIdentifierType()) {
+            case s:
+                idNode = new NodeId(uaField.getNamespace(), uaField.getIdentifier());
+                break;
+            case i:
+                idNode = new NodeId(uaField.getNamespace(), UInteger.valueOf(uaField.getIdentifier()));
+                break;
+            case g:
+                idNode = new NodeId(uaField.getNamespace(), UUID.fromString(uaField.getIdentifier()));
+                break;
+            case b:
+                idNode = new NodeId(uaField.getNamespace(), new ByteString(uaField.getIdentifier().getBytes()));
+                break;
+
+            default: idNode = new NodeId(uaField.getNamespace(), uaField.getIdentifier());
+        }
+
+        return  idNode;
+    }
+
+    public static BaseDefaultFieldItem encodeFieldItem(DataValue value){
+        NodeId typeNode = value.getValue().getDataType().get();
+        Object objValue = value.getValue().getValue();
+
+        if(typeNode.equals(Identifiers.Boolean)){
+            return new DefaultBooleanFieldItem((Boolean)objValue);
+        }else if (typeNode.equals(Identifiers.ByteString)){
+            byte[] array = ((ByteString)objValue).bytes();
+            Byte[] byteArry = new Byte[array.length];
+            int counter = 0;
+            for (byte bytie: array
+                 ) {
+                byteArry[counter] = bytie;
+                counter++;
+            }
+            return new DefaultByteArrayFieldItem(byteArry);
+        }else if (typeNode.equals(Identifiers.Integer)){
+            return new DefaultIntegerFieldItem((Integer)objValue);
+        }else if (typeNode.equals(Identifiers.Int16)){
+            return new DefaultShortFieldItem((Short)objValue);
+        }else if (typeNode.equals(Identifiers.Int32)){
+            return new DefaultIntegerFieldItem((Integer)objValue);
+        }else if (typeNode.equals(Identifiers.Int64)){
+            return new DefaultLongFieldItem((Long)objValue);
+        }else if (typeNode.equals(Identifiers.UInteger)){
+            return new DefaultLongFieldItem((Long)objValue);
+        }else if (typeNode.equals(Identifiers.UInt16)){
+            return new DefaultIntegerFieldItem(((UShort)objValue).intValue());
+        }else if (typeNode.equals(Identifiers.UInt32)){
+            return new DefaultLongFieldItem(((UInteger)objValue).longValue());
+        }else if (typeNode.equals(Identifiers.UInt64)){
+            return new DefaultBigIntegerFieldItem(new BigInteger(objValue.toString()));
+        }else if (typeNode.equals(Identifiers.Byte)){
+            return new DefaultShortFieldItem(Short.valueOf(objValue.toString()));
+        }else if (typeNode.equals(Identifiers.Float)){
+            return new DefaultFloatFieldItem((Float)objValue);
+        }else if (typeNode.equals(Identifiers.Double)){
+            return new DefaultDoubleFieldItem((Double)objValue);
+        }else if (typeNode.equals(Identifiers.SByte)){
+            return new DefaultByteFieldItem((Byte)objValue);
+        }else {
+            return new DefaultStringFieldItem(objValue.toString());
+        }
+
+    }
+
+    @Override
+    public CompletableFuture<PlcWriteResponse> write(PlcWriteRequest writeRequest) {
+        CompletableFuture<PlcWriteResponse> future;
+        future = CompletableFuture.supplyAsync(() -> {
+
+            InternalPlcWriteRequest internalPlcWriteRequest = (InternalPlcWriteRequest) writeRequest;
+
+            List<PlcField> writePLCValues = writeRequest.getFields();
+            LinkedList<DataValue> values = new LinkedList<>();
+            LinkedList<NodeId> ids = new LinkedList<>();
+            LinkedList<String> names = new LinkedList<>();
+            Map<String, PlcResponseCode> fieldResponse = new HashMap<>();
+            for (String fieldName: writeRequest.getFieldNames()) {
+                OpcuaField uaField = (OpcuaField) writeRequest.getField(fieldName);
+                NodeId idNode = generateNodeId(uaField);
+                Variant var = new Variant(internalPlcWriteRequest.getFieldItem(fieldName).getObject(0));
+                DataValue value = new DataValue(var, null, null);
+                ids.add(idNode);
+                names.add(fieldName);
+                values.add(value);
+            }
+            CompletableFuture<List<StatusCode>> opcRequest =
+                client.writeValues(ids, values);
+            List<StatusCode> statusCodes = null;
+            try {
+                statusCodes = opcRequest.get();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            } catch (ExecutionException e) {
+                e.printStackTrace();
+            }
+
+            for(int counter = 0; counter < names.size(); counter++){
+                PlcResponseCode resultCode = PlcResponseCode.OK;
+                BaseDefaultFieldItem stringItem = null;
+                if(statusCodes != null && statusCodes.size() > counter){
+                    if(statusCodes.get(counter).isGood()){
+                        resultCode = PlcResponseCode.OK;
+                    }else if(statusCodes.get(counter).isUncertain()){
+                        resultCode = PlcResponseCode.NOT_FOUND;
+                    }else {
+                        resultCode = PlcResponseCode.ACCESS_DENIED;
+                    }
+                }else{
+                    resultCode = PlcResponseCode.ACCESS_DENIED;
+                }
+                fieldResponse.put(names.get(counter), resultCode);
+            }
+            InternalPlcWriteRequest internalPlcReadRequest = checkInternal(writeRequest, InternalPlcWriteRequest.class);
+            PlcWriteResponse response = new DefaultPlcWriteResponse(internalPlcReadRequest, fieldResponse);
+            return response;
+        });
+
+
+        return future;
+    }
+
+
+    private String getEndpointUrl(InetAddress address, Integer port, String params) {
+        return "opc.tcp://" + address.getHostAddress() +":" + port + "/" + params;
+    }
+
+    private Predicate<EndpointDescription> endpointFilter() {
+        return e -> true;
+    }
+
+    private SecurityPolicy getSecurityPolicy() {
+        return SecurityPolicy.None;
+    }
+
+    private IdentityProvider getIdentityProvider() {
+        return new AnonymousProvider();
+    }
+}
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
new file mode 100644
index 0000000..317d6ad
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaField.java
@@ -0,0 +1,115 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.plc4x.java.opcua.protocol;
+
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.opcua.protocol.model.OpcuaDataTypes;
+import org.apache.plc4x.java.opcua.protocol.model.OpcuaIdentifierType;
+
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class OpcuaField implements PlcField {
+
+    private static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?<namespace>\\d+);(?<identifierType>[isgb])=((?<identifier>\\w+))?");
+
+    private final OpcuaIdentifierType identifierType;
+
+    private final int namespace;
+
+    private final String identifier;
+
+    protected OpcuaField(int namespace, OpcuaIdentifierType identifierType, String identifier) {
+        this.namespace = namespace;
+        this.identifier = identifier;
+        this.identifierType = identifierType;
+        if (this.identifier == null || this.namespace < 0) {
+            throw new IllegalArgumentException("Identifier can not be null or Namespace can not be lower then 0.");
+        }
+    }
+
+    private OpcuaField(Integer namespace, String identifier, OpcuaIdentifierType identifierType) {
+        this.identifier = Objects.requireNonNull(identifier);
+        this.identifierType = Objects.requireNonNull(identifierType);
+        this.namespace = namespace != null ? namespace : 0;
+        if (this.namespace < 0) {
+            throw new IllegalArgumentException("namespace must be greater then zero. Was " + this.namespace);
+        }
+    }
+
+    public static OpcuaField of(String address) {
+        Matcher matcher = ADDRESS_PATTERN.matcher(address);
+        if (!matcher.matches()) {
+            throw new PlcInvalidFieldException(address, ADDRESS_PATTERN, "{address}");
+        }
+        String identifier = matcher.group("identifier");
+
+        String identifierTypeString = matcher.group("identifierType");
+        OpcuaIdentifierType identifierType = OpcuaIdentifierType.valueOf(identifierTypeString);
+
+        String namespaceString = matcher.group("namespace");
+        Integer namespace = namespaceString != null ? Integer.valueOf(namespaceString) : 0;
+
+        return new OpcuaField(namespace, identifier, identifierType);
+    }
+
+
+    public static boolean matches(String address) {
+        return ADDRESS_PATTERN.matcher(address).matches();
+    }
+
+    public int getNamespace() {
+        return namespace;
+    }
+
+    public String getIdentifier() {
+        return identifier;
+    }
+
+    public OpcuaIdentifierType getIdentifierType() {
+        return identifierType;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (!(o instanceof OpcuaField)) {
+            return false;
+        }
+        OpcuaField that = (OpcuaField) o;
+        return namespace == that.namespace && identifier.equals(that.identifier);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(namespace);
+    }
+
+    @Override
+    public String toString() {
+        return "OpcuaField{" +
+            "namespace=" + namespace +
+            "identifier=" + identifier +
+            '}';
+    }
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
new file mode 100644
index 0000000..e3f056e
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
@@ -0,0 +1,43 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.protocol.model;
+
+public enum OpcuaDataTypes {
+    BOOL,
+    SByte,
+    Byte,
+    Int16,
+    UInt16,
+    Int32,
+    UInt32,
+    Int64,
+    Uint64,
+    Float,
+    Double,
+    StatusCode,
+    String,
+    DateTime,
+    Guid,
+    ByteString,
+    XMLElement,
+    NodeId,
+    ExpandedNodeId,
+    QualifiedName
+
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
new file mode 100644
index 0000000..afcef2a
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
@@ -0,0 +1,26 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.protocol.model;
+
+public enum OpcuaIdentifierType {
+    s,
+    i,
+    g,
+    b
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
new file mode 100644
index 0000000..81fe4f2
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
@@ -0,0 +1,146 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.protocol.model;
+
+
+
+import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.base.connection.DefaultPlcFieldHandler;
+import org.apache.plc4x.java.base.messages.items.*;
+import org.apache.plc4x.java.opcua.protocol.OpcuaField;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+
+public class OpcuaPlcFieldHandler extends DefaultPlcFieldHandler {
+
+    @Override
+    public PlcField createField(String fieldQuery) throws PlcInvalidFieldException {
+        if (OpcuaField.matches(fieldQuery)) {
+            return OpcuaField.of(fieldQuery);
+        }
+        throw new PlcInvalidFieldException(fieldQuery);
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeString(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<String> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add(item.toString());
+        }
+        return new DefaultStringFieldItem(resultSet.toArray(new String[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeBoolean(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Boolean> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Boolean) item);
+        }
+        return new DefaultBooleanFieldItem(resultSet.toArray(new Boolean[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeByte(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Byte> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Byte) item);
+        }
+        return new DefaultByteFieldItem(resultSet.toArray(new Byte[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeShort(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Short> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Short) item);
+        }
+        return new DefaultShortFieldItem(resultSet.toArray(new Short[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeInteger(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Integer> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Integer) item);
+        }
+        return new DefaultIntegerFieldItem(resultSet.toArray(new Integer[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeBigInteger(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<BigInteger> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((BigInteger) item);
+        }
+        return new DefaultBigIntegerFieldItem(resultSet.toArray(new BigInteger[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeLong(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Long> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Long) item);
+        }
+        return new DefaultLongFieldItem(resultSet.toArray(new Long[0]));
+    }
+
+    @Override
+    public BaseDefaultFieldItem encodeFloat(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Float> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Float) item);
+        }
+        return new DefaultFloatFieldItem(resultSet.toArray(new Float[0]));
+    }
+
+
+
+    @Override
+    public BaseDefaultFieldItem encodeDouble(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Double> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Double) item);
+        }
+        return new DefaultDoubleFieldItem(resultSet.toArray(new Double[0]));
+    }
+
+
+    @Override
+    public BaseDefaultFieldItem encodeByteArray(PlcField field, Object[] values) {
+        OpcuaField adsField = (OpcuaField) field;
+        ArrayList<Byte[]> resultSet = new ArrayList<>();
+        for(Object item : values){
+            resultSet.add((Byte[]) item);
+        }
+        return new DefaultByteArrayFieldItem(resultSet.toArray(new Byte[0][0]));
+    }
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
new file mode 100644
index 0000000..4a03345
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
@@ -0,0 +1,76 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.protocol.model;
+
+import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent;
+import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
+import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
+import org.apache.plc4x.java.api.types.PlcResponseCode;
+import org.apache.plc4x.java.base.messages.DefaultPlcSubscriptionEvent;
+import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
+import org.apache.plc4x.java.opcua.connection.OPCUATcpPlcConnection;
+import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
+import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
+import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
+import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
+
+import java.awt.*;
+import java.time.Instant;
+import java.util.*;
+import java.util.function.Consumer;
+
+public class OpcuaSubsriptionHandle implements PlcSubscriptionHandle {
+    Set< Consumer<PlcSubscriptionEvent>> consumers = new HashSet<>();
+    String fieldName;
+    public UInteger getClientHandle() {
+        return clientHandle;
+    }
+
+    UInteger clientHandle;
+
+    public  OpcuaSubsriptionHandle(String fieldName, UInteger clientHandle){
+        this.clientHandle = clientHandle;
+    }
+    @Override
+    public PlcConsumerRegistration register(Consumer<PlcSubscriptionEvent> consumer) {
+        consumers.add(consumer);
+        return () -> {consumers.remove(consumer);};
+    }
+
+    public void onSubscriptionValue(UaMonitoredItem item, DataValue value) {
+        consumers.forEach(plcSubscriptionEventConsumer -> {
+            PlcResponseCode resultCode = PlcResponseCode.OK;
+            BaseDefaultFieldItem stringItem = null;
+            if(value.getStatusCode() != StatusCode.GOOD){
+                resultCode = PlcResponseCode.NOT_FOUND;
+            }else{
+                stringItem = OPCUATcpPlcConnection.encodeFieldItem(value);
+
+            }
+            Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> fields = new HashMap<>();
+            Pair<PlcResponseCode, BaseDefaultFieldItem> newPair = new ImmutablePair<>(resultCode, stringItem);
+            fields.put(fieldName, newPair);
+            PlcSubscriptionEvent event = new DefaultPlcSubscriptionEvent(Instant.now(), fields);
+            plcSubscriptionEventConsumer.accept(event);
+        });
+    }
+
+}
diff --git a/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver b/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
new file mode 100644
index 0000000..860acdc
--- /dev/null
+++ b/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.apache.plc4x.java.opcua.OPCUAPlcDriver
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
new file mode 100644
index 0000000..eb29494
--- /dev/null
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
@@ -0,0 +1,125 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.plc4x.java.opcua.connection;
+
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
+import org.apache.plc4x.java.api.model.PlcField;
+import org.apache.plc4x.java.api.types.PlcSubscriptionType;
+import org.apache.plc4x.java.base.messages.DefaultPlcSubscriptionRequest;
+import org.apache.plc4x.java.base.model.SubscriptionPlcField;
+import org.apache.plc4x.java.opcua.protocol.OpcuaField;
+import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
+
+import java.math.BigInteger;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Consumer;
+
+public class ManualPLC4XOPCUA {
+    public static void main(String args[]){
+
+
+
+
+        OPCUATcpPlcConnection adsConnection = null;
+        OpcuaPlcFieldHandler fieldH = new OpcuaPlcFieldHandler();
+        PlcField field = fieldH.createField("ns=2;i=10855");
+        try {
+            adsConnection = (OPCUATcpPlcConnection)
+                new PlcDriverManager().getConnection("opcua:tcp://opcua.demo-this.com:51210/UA/SampleServer");
+
+        } catch (PlcConnectionException e) {
+            e.printStackTrace();
+        }
+        try {
+            PlcReadRequest.Builder builder = adsConnection.readRequestBuilder();
+            //builder.addItem("String", "ns=2;i=10855");
+            builder.addItem("Bool", "ns=2;i=10844");
+            builder.addItem("ByteString", "ns=2;i=10858");
+            builder.addItem("Byte", "ns=2;i=10846");
+            builder.addItem("Double", "ns=2;i=10854");
+            builder.addItem("Float", "ns=2;i=10853");
+            builder.addItem("Int16", "ns=2;i=10847");
+            builder.addItem("Int32", "ns=2;i=10849");
+            builder.addItem("Int64", "ns=2;i=10851");
+            builder.addItem("Integer", "ns=2;i=10869");
+            builder.addItem("SByte", "ns=2;i=10845");
+            builder.addItem("String", "ns=2;i=10855");
+            builder.addItem("UInt16", "ns=2;i=10848");
+            builder.addItem("UInt32", "ns=2;i=10850");
+            builder.addItem("UInt64", "ns=2;i=10852");
+            builder.addItem("UInteger", "ns=2;i=10870");
+
+            builder.addItem("DoesNotExists", "ns=2;i=12512623");
+
+            PlcReadRequest request = builder.build();
+            PlcReadResponse response = adsConnection.read(request).get();
+            Collection coll = response.getAllStrings("String");
+
+            PlcWriteRequest.Builder wBuilder = adsConnection.writeRequestBuilder();
+            //wBuilder.addItem("w-Bool", "ns=2;i=10844", "TEST");
+            //wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
+            //--->> wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
+            wBuilder.addItem("w-String", "ns=2;i=10855", "TEST");
+
+            /*
+            wBuilder.addItem("w-Byte", "ns=2;i=10846", (byte)1);
+            wBuilder.addItem("w-Double", "ns=2;i=10854", (double)0.25);
+            wBuilder.addItem("w-Float", "ns=2;i=10853", (float)0.25);
+            wBuilder.addItem("w-Int16", "ns=2;i=10847", (short)12);
+            wBuilder.addItem("w-Int32", "ns=2;i=10849", (int)314);
+            wBuilder.addItem("w-Int64", "ns=2;i=10851", (long)123125);
+            wBuilder.addItem("w-Integer", "ns=2;i=10869", (int)314);
+            wBuilder.addItem("w-SByte", "ns=2;i=10845", (short)23);
+            wBuilder.addItem("w-String", "ns=2;i=10855", "TEST");
+            wBuilder.addItem("w-UInt16", "ns=2;i=10848", (int)222);
+            wBuilder.addItem("w-UInt32", "ns=2;i=10850", (long)21412);
+            wBuilder.addItem("w-UInt64", "ns=2;i=10852", new BigInteger("1245152"));
+            wBuilder.addItem("w-UInteger", "ns=2;i=10870", new BigInteger("1245152"));
+
+            */
+            PlcWriteRequest writeRequest = wBuilder.build();
+            PlcWriteResponse wResponse = adsConnection.write(writeRequest).get();
+
+            PlcSubscriptionResponse subResp = adsConnection.subscribe(new DefaultPlcSubscriptionRequest(
+                adsConnection,
+                new LinkedHashMap<>(
+                    Collections.singletonMap("field1",
+                        new SubscriptionPlcField(PlcSubscriptionType.CHANGE_OF_STATE, OpcuaField.of("ns=2;i=10855"), Duration.of(1, ChronoUnit.SECONDS)))
+                )
+            )).get();
+
+            Consumer<PlcSubscriptionEvent> consumer = plcSubscriptionEvent -> System.out.println(plcSubscriptionEvent.toString());
+            PlcConsumerRegistration registration = adsConnection.register(consumer, subResp.getSubscriptionHandles());
+            Thread.sleep(7000);
+            registration.unregister();
+            Thread.sleep(200000);
+            adsConnection.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/plc4j/drivers/pom.xml b/plc4j/drivers/pom.xml
index 34f60a2..cf47c07 100644
--- a/plc4j/drivers/pom.xml
+++ b/plc4j/drivers/pom.xml
@@ -39,6 +39,7 @@
     <module>modbus</module>
     <module>s7</module>
     <module>simulated</module>
+	<module>opcua</module>
   </modules>
 
 </project>


[plc4x] 03/07: Added Author field

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 98c62d048c327de3d057275583bed9eff235e78f
Author: Mathi <de...@googlemail.com>
AuthorDate: Mon May 13 19:45:03 2019 +0200

    Added Author field
---
 .../apache/plc4x/java/opcua/OPCUAPlcDriver.java    | 12 +++--------
 .../opcua/connection/BaseOPCUAPlcConnection.java   |  7 ++++++-
 .../opcua/connection/OPCUAConnectionFactory.java   |  2 ++
 .../opcua/connection/OPCUATcpPlcConnection.java    |  3 ++-
 .../plc4x/java/opcua/protocol/OpcuaField.java      |  5 +++--
 .../java/opcua/protocol/model/OpcuaDataTypes.java  |  2 ++
 .../opcua/protocol/model/OpcuaIdentifierType.java  |  2 ++
 .../opcua/protocol/model/OpcuaPlcFieldHandler.java |  5 ++---
 .../protocol/model/OpcuaSubsriptionHandle.java     |  8 ++++++--
 .../java/opcua/connection/ManualPLC4XOPCUA.java    | 24 +++++++++++-----------
 10 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
index 68f3886..4e20b8c 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
@@ -15,27 +15,21 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.PlcConnection;
 import org.apache.plc4x.java.api.authentication.PlcAuthentication;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.api.messages.PlcReadRequest;
-import org.apache.plc4x.java.api.messages.PlcReadResponse;
-import org.apache.plc4x.java.api.messages.PlcWriteRequest;
-import org.apache.plc4x.java.api.messages.PlcWriteResponse;
-import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.opcua.connection.OPCUAConnectionFactory;
-import org.apache.plc4x.java.opcua.connection.OPCUATcpPlcConnection;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
 import org.apache.plc4x.java.spi.PlcDriver;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.Collection;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
index b7221e2..26cbb09 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
@@ -15,11 +15,16 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.connection;
 
 import org.apache.commons.lang3.StringUtils;
-import org.apache.plc4x.java.api.messages.*;
+import org.apache.plc4x.java.api.messages.PlcReadRequest;
+import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest;
+import org.apache.plc4x.java.api.messages.PlcUnsubscriptionRequest;
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
 import org.apache.plc4x.java.base.connection.AbstractPlcConnection;
 import org.apache.plc4x.java.base.messages.*;
 import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
index 1bf0e60..b82b696 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
@@ -15,6 +15,8 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.connection;
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
index 7235226..4929bf8 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
@@ -15,6 +15,8 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.connection;
 
@@ -25,7 +27,6 @@ import org.apache.plc4x.java.api.messages.*;
 import org.apache.plc4x.java.api.model.PlcConsumerRegistration;
 import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
-
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.java.base.messages.*;
 import org.apache.plc4x.java.base.messages.items.*;
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 317d6ad..0ac3c9f 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
@@ -15,12 +15,13 @@ software distributed under the License is distributed on an
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-*/
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 package org.apache.plc4x.java.opcua.protocol;
 
 import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
 import org.apache.plc4x.java.api.model.PlcField;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaDataTypes;
 import org.apache.plc4x.java.opcua.protocol.model.OpcuaIdentifierType;
 
 import java.util.Objects;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
index e3f056e..c0bfe65 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
@@ -15,6 +15,8 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.protocol.model;
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
index afcef2a..599ad05 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
@@ -15,6 +15,8 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.protocol.model;
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
index 81fe4f2..0a3c5c6 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
@@ -15,13 +15,13 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.protocol.model;
 
 
-
 import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
-import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
 import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.base.connection.DefaultPlcFieldHandler;
 import org.apache.plc4x.java.base.messages.items.*;
@@ -29,7 +29,6 @@ import org.apache.plc4x.java.opcua.protocol.OpcuaField;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-import java.util.List;
 
 public class OpcuaPlcFieldHandler extends DefaultPlcFieldHandler {
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
index 4a03345..582993c 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
@@ -15,6 +15,8 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.protocol.model;
 
@@ -32,9 +34,11 @@ import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
 import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
 import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
 
-import java.awt.*;
 import java.time.Instant;
-import java.util.*;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
 import java.util.function.Consumer;
 
 public class OpcuaSubsriptionHandle implements PlcSubscriptionHandle {
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
index eb29494..462b58a 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
@@ -15,6 +15,8 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.connection;
 
@@ -29,13 +31,11 @@ import org.apache.plc4x.java.base.model.SubscriptionPlcField;
 import org.apache.plc4x.java.opcua.protocol.OpcuaField;
 import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
 
-import java.math.BigInteger;
 import java.time.Duration;
 import java.time.temporal.ChronoUnit;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
-import java.util.concurrent.CompletableFuture;
 import java.util.function.Consumer;
 
 public class ManualPLC4XOPCUA {
@@ -44,18 +44,18 @@ public class ManualPLC4XOPCUA {
 
 
 
-        OPCUATcpPlcConnection adsConnection = null;
+        OPCUATcpPlcConnection opcuaConnection = null;
         OpcuaPlcFieldHandler fieldH = new OpcuaPlcFieldHandler();
         PlcField field = fieldH.createField("ns=2;i=10855");
         try {
-            adsConnection = (OPCUATcpPlcConnection)
+            opcuaConnection = (OPCUATcpPlcConnection)
                 new PlcDriverManager().getConnection("opcua:tcp://opcua.demo-this.com:51210/UA/SampleServer");
 
         } catch (PlcConnectionException e) {
             e.printStackTrace();
         }
         try {
-            PlcReadRequest.Builder builder = adsConnection.readRequestBuilder();
+            PlcReadRequest.Builder builder = opcuaConnection.readRequestBuilder();
             //builder.addItem("String", "ns=2;i=10855");
             builder.addItem("Bool", "ns=2;i=10844");
             builder.addItem("ByteString", "ns=2;i=10858");
@@ -76,10 +76,10 @@ public class ManualPLC4XOPCUA {
             builder.addItem("DoesNotExists", "ns=2;i=12512623");
 
             PlcReadRequest request = builder.build();
-            PlcReadResponse response = adsConnection.read(request).get();
+            PlcReadResponse response = opcuaConnection.read(request).get();
             Collection coll = response.getAllStrings("String");
 
-            PlcWriteRequest.Builder wBuilder = adsConnection.writeRequestBuilder();
+            PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
             //wBuilder.addItem("w-Bool", "ns=2;i=10844", "TEST");
             //wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
             //--->> wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
@@ -102,10 +102,10 @@ public class ManualPLC4XOPCUA {
 
             */
             PlcWriteRequest writeRequest = wBuilder.build();
-            PlcWriteResponse wResponse = adsConnection.write(writeRequest).get();
+            PlcWriteResponse wResponse = opcuaConnection.write(writeRequest).get();
 
-            PlcSubscriptionResponse subResp = adsConnection.subscribe(new DefaultPlcSubscriptionRequest(
-                adsConnection,
+            PlcSubscriptionResponse subResp = opcuaConnection.subscribe(new DefaultPlcSubscriptionRequest(
+                opcuaConnection,
                 new LinkedHashMap<>(
                     Collections.singletonMap("field1",
                         new SubscriptionPlcField(PlcSubscriptionType.CHANGE_OF_STATE, OpcuaField.of("ns=2;i=10855"), Duration.of(1, ChronoUnit.SECONDS)))
@@ -113,11 +113,11 @@ public class ManualPLC4XOPCUA {
             )).get();
 
             Consumer<PlcSubscriptionEvent> consumer = plcSubscriptionEvent -> System.out.println(plcSubscriptionEvent.toString());
-            PlcConsumerRegistration registration = adsConnection.register(consumer, subResp.getSubscriptionHandles());
+            PlcConsumerRegistration registration = opcuaConnection.register(consumer, subResp.getSubscriptionHandles());
             Thread.sleep(7000);
             registration.unregister();
             Thread.sleep(200000);
-            adsConnection.close();
+            opcuaConnection.close();
         } catch (Exception e) {
             e.printStackTrace();
         }


[plc4x] 02/07: Added NOTICE entry for the use of Milo

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 2801e636904f61ada9ea93543dc16dac790ee42c
Author: Matthias Milan Strljic <Ma...@gmail.com>
AuthorDate: Mon May 13 19:24:28 2019 +0200

    Added NOTICE entry for the use of Milo
---
 NOTICE | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/NOTICE b/NOTICE
index 97048d6..6ff3737 100644
--- a/NOTICE
+++ b/NOTICE
@@ -8,3 +8,6 @@ The Apache Software Foundation (http://www.apache.org/).
 
 This product includes software developed at
 The Netty project (https://netty.io/).
+
+This product includes software developed at
+The Milo project (https://github.com/eclipse/milo).


[plc4x] 04/07: [Fixed] Failure while Timeout of write request [Added] requestTimeout field for variable timeouts

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit b8c09b507e0b4a1580acd3e138f19170871943af
Author: Matthias Milan Strljic <Ma...@gmail.com>
AuthorDate: Mon May 13 21:45:11 2019 +0200

    [Fixed] Failure while Timeout of write request
    [Added] requestTimeout field for variable timeouts
---
 plc4j/drivers/opcua/pom.xml                        |  3 ++
 .../apache/plc4x/java/opcua/OPCUAPlcDriver.java    |  4 +-
 .../opcua/connection/OPCUAConnectionFactory.java   |  6 +--
 .../opcua/connection/OPCUATcpPlcConnection.java    | 53 ++++++++++------------
 .../opcua/protocol/model/OpcuaPlcFieldHandler.java | 12 +++--
 .../java/opcua/connection/ManualPLC4XOPCUA.java    | 11 ++---
 6 files changed, 44 insertions(+), 45 deletions(-)

diff --git a/plc4j/drivers/opcua/pom.xml b/plc4j/drivers/opcua/pom.xml
index 69a36cd..f0f47df 100644
--- a/plc4j/drivers/opcua/pom.xml
+++ b/plc4j/drivers/opcua/pom.xml
@@ -64,7 +64,10 @@
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-lang3</artifactId>
     </dependency>
+
   </dependencies>
+
+
   <!--
   <build>
     <plugins>
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
index 4e20b8c..271365e 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
@@ -43,7 +43,7 @@ public class OPCUAPlcDriver implements PlcDriver {
 
     public static final Pattern INET_ADDRESS_PATTERN = Pattern.compile("tcp://(?<host>[\\w.-]+)(:(?<port>\\d*))?");
     public static final Pattern OPCUA_URI_PATTERN = Pattern.compile("^opcua:(" + INET_ADDRESS_PATTERN + ")?" + "(?<params>/[\\w/]+)?");
-
+    private static final int requestTimeout = 10000;
     private OPCUAConnectionFactory opcuaConnectionFactory;
 
     public OPCUAPlcDriver() {
@@ -79,7 +79,7 @@ public class OPCUAPlcDriver implements PlcDriver {
         String params = matcher.group("params") != null ? matcher.group("params").substring(1) : null;
 
         try {
-            return opcuaConnectionFactory.opcuaTcpPlcConnectionOf(InetAddress.getByName(host), port, params);
+            return opcuaConnectionFactory.opcuaTcpPlcConnectionOf(InetAddress.getByName(host), port, params, requestTimeout);
         } catch (UnknownHostException e) {
             throw new PlcConnectionException(e);
         }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
index b82b696..a49669c 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
@@ -25,13 +25,13 @@ import java.util.Objects;
 
 public class OPCUAConnectionFactory {
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params) {
+    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
         Objects.requireNonNull(address);
 
         if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params);
+            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
         } else {
-            return OPCUATcpPlcConnection.of(address, port, params);
+            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
         }
     }
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
index 4929bf8..afd89b5 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
@@ -76,17 +76,18 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
 
     private static final Logger logger = LoggerFactory.getLogger(OPCUATcpPlcConnection.class);
     private InetAddress address;
+    private int requestTimeout = 5000;
     private int port;
     private String params;
     private OpcUaClient client;
     private boolean isConnected = false;
     private  final AtomicLong clientHandles = new AtomicLong(1L);
-    private OPCUATcpPlcConnection(InetAddress address, String params) {
-        this( address, OPCUA_DEFAULT_TCP_PORT,  params);
+    private OPCUATcpPlcConnection(InetAddress address, String params, int requestTimeout) {
+        this( address, OPCUA_DEFAULT_TCP_PORT,  params, requestTimeout);
         logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
     }
 
-    public OPCUATcpPlcConnection(InetAddress address, int port, String params) {
+    public OPCUATcpPlcConnection(InetAddress address, int port, String params, int requestTimeout) {
         this(params);
         logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
         this.address = address;
@@ -98,18 +99,18 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
         super(params);
     }
 
-    public static OPCUATcpPlcConnection of(InetAddress address, String params) {
-        return new OPCUATcpPlcConnection(address, params);
+    public static OPCUATcpPlcConnection of(InetAddress address, String params, int requestTimeout) {
+        return new OPCUATcpPlcConnection(address, params, requestTimeout);
     }
 
-    public static OPCUATcpPlcConnection of(InetAddress address, int port, String params) {
-        return new OPCUATcpPlcConnection(address, port, params);
+    public static OPCUATcpPlcConnection of(InetAddress address, int port, String params, int requestTimeout) {
+        return new OPCUATcpPlcConnection(address, port, params, requestTimeout);
     }
 
 
 
     public InetAddress getRemoteAddress() {
-        return null;
+        return address;
     }
 
     @Override
@@ -118,7 +119,7 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
 
         try {
             endpoints = DiscoveryClient.getEndpoints(getEndpointUrl(address, port, params)).get();
-        } catch (Throwable ex) {
+        } catch (Exception ex) {
             // try the explicit discovery endpoint as well
             String discoveryUrl = getEndpointUrl(address, port, params);
 
@@ -131,39 +132,31 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
             try {
                 endpoints = DiscoveryClient.getEndpoints(discoveryUrl).get();
             } catch (InterruptedException | ExecutionException e) {
-                e.printStackTrace();
+                throw new PlcConnectionException("Unable to discover URL:" + discoveryUrl);
             }
         }
 
-        EndpointDescription endpoint = null;
-        try {
-            endpoint = endpoints.stream()
+        EndpointDescription endpoint = endpoints.stream()
                 .filter(e -> e.getSecurityPolicyUri().equals(getSecurityPolicy().getUri()))
                 .filter(endpointFilter())
                 .findFirst()
-                .orElseThrow(() -> new Exception("no desired endpoints returned"));
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+                .orElseThrow(() -> new PlcConnectionException("No desired endpoints from"));
 
         OpcUaClientConfig config = OpcUaClientConfig.builder()
             .setApplicationName(LocalizedText.english("eclipse milo opc-ua client"))
-            .setApplicationUri("urn:eclipse:milo:examples:client")
+            .setApplicationUri("urn:eclipse:milo:plc4x:client")
             .setEndpoint(endpoint)
             .setIdentityProvider(getIdentityProvider())
-            .setRequestTimeout(UInteger.valueOf(5000))
+            .setRequestTimeout(UInteger.valueOf(requestTimeout))
             .build();
 
         try {
             this.client =  OpcUaClient.create(config);
             this.client.connect().get();
             isConnected = true;
-        } catch (UaException e) {
-            e.printStackTrace();
-        } catch (InterruptedException e) {
-            isConnected = false;
-        } catch (ExecutionException e) {
+        } catch (UaException | InterruptedException | ExecutionException e) {
             isConnected = false;
+
         }
     }
 
@@ -425,15 +418,15 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
             List<StatusCode> statusCodes = null;
             try {
                 statusCodes = opcRequest.get();
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            } catch (ExecutionException e) {
-                e.printStackTrace();
+            } catch (InterruptedException | ExecutionException e) {
+                statusCodes = new LinkedList<>();
+                for(int counter = 0; counter < ids.size(); counter++){
+                    ((LinkedList<StatusCode>) statusCodes).push(StatusCode.BAD);
+                }
             }
 
             for(int counter = 0; counter < names.size(); counter++){
-                PlcResponseCode resultCode = PlcResponseCode.OK;
-                BaseDefaultFieldItem stringItem = null;
+                PlcResponseCode resultCode;
                 if(statusCodes != null && statusCodes.size() > counter){
                     if(statusCodes.get(counter).isGood()){
                         resultCode = PlcResponseCode.OK;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
index 0a3c5c6..f265e81 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
@@ -136,10 +136,16 @@ public class OpcuaPlcFieldHandler extends DefaultPlcFieldHandler {
     @Override
     public BaseDefaultFieldItem encodeByteArray(PlcField field, Object[] values) {
         OpcuaField adsField = (OpcuaField) field;
-        ArrayList<Byte[]> resultSet = new ArrayList<>();
+        Byte[][] byteArray = new Byte[values.length][];
+        int innerCounter = 0;
         for(Object item : values){
-            resultSet.add((Byte[]) item);
+            byte[] itemArray = (byte[]) item;
+            byteArray[innerCounter] = new Byte[((byte[]) item).length];
+            for(int counter = 0; counter < itemArray.length; counter++){
+                byteArray[innerCounter][counter] = itemArray[counter];
+            }
+            innerCounter++;
         }
-        return new DefaultByteArrayFieldItem(resultSet.toArray(new Byte[0][0]));
+        return new DefaultByteArrayFieldItem(byteArray);
     }
 }
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
index 462b58a..f6eb6d5 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
@@ -31,6 +31,7 @@ import org.apache.plc4x.java.base.model.SubscriptionPlcField;
 import org.apache.plc4x.java.opcua.protocol.OpcuaField;
 import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
 
+import java.math.BigInteger;
 import java.time.Duration;
 import java.time.temporal.ChronoUnit;
 import java.util.Collection;
@@ -80,12 +81,9 @@ public class ManualPLC4XOPCUA {
             Collection coll = response.getAllStrings("String");
 
             PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
-            //wBuilder.addItem("w-Bool", "ns=2;i=10844", "TEST");
-            //wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
-            //--->> wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
-            wBuilder.addItem("w-String", "ns=2;i=10855", "TEST");
-
+            wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
             /*
+            wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
             wBuilder.addItem("w-Byte", "ns=2;i=10846", (byte)1);
             wBuilder.addItem("w-Double", "ns=2;i=10854", (double)0.25);
             wBuilder.addItem("w-Float", "ns=2;i=10853", (float)0.25);
@@ -99,8 +97,7 @@ public class ManualPLC4XOPCUA {
             wBuilder.addItem("w-UInt32", "ns=2;i=10850", (long)21412);
             wBuilder.addItem("w-UInt64", "ns=2;i=10852", new BigInteger("1245152"));
             wBuilder.addItem("w-UInteger", "ns=2;i=10870", new BigInteger("1245152"));
-
-            */
+*/
             PlcWriteRequest writeRequest = wBuilder.build();
             PlcWriteResponse wResponse = opcuaConnection.write(writeRequest).get();
 


[plc4x] 05/07: Added test class bodies and renamed consistently

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 2b98afadd733c26b33998089e93b97c3a1bf8e9d
Author: Mathi <de...@googlemail.com>
AuthorDate: Tue May 14 00:17:38 2019 +0200

    Added test class bodies and renamed consistently
---
 .../{OPCUAPlcDriver.java => OpcuaPlcDriver.java}   | 12 ++--
 ...Connection.java => BaseOpcuaPlcConnection.java} |  8 +--
 ...ionFactory.java => OpcuaConnectionFactory.java} |  8 +--
 ...cConnection.java => OpcuaTcpPlcConnection.java} | 25 ++++----
 .../plc4x/java/opcua/protocol/OpcuaField.java      |  2 +-
 .../protocol/{model => }/OpcuaPlcFieldHandler.java |  3 +-
 .../{model => }/OpcuaSubsriptionHandle.java        |  6 +-
 .../services/org.apache.plc4x.java.spi.PlcDriver   |  2 +-
 ...ManualPLC4XOPCUA.java => ManualPLC4XOpcua.java} | 17 +++---
 .../plc4x/java/opcua/OpcuaPlcDriverTest.java       | 66 ++++++++++++++++++++++
 .../org/apache/plc4x/java/opcua/UtilsTest.java}    | 29 +++++-----
 .../connection/OpcuaTcpPlcConnectionTest.java}     | 23 ++++----
 .../plc4x/java/opcua/protocol/OpcuaFieldTest.java} | 38 ++++++++-----
 .../opcua/protocol/OpcuaPlcFieldHandlerTest.java}  | 25 ++++----
 .../protocol/OpcuaSubscriptionHandleTest.java}     | 25 ++++----
 15 files changed, 178 insertions(+), 111 deletions(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
similarity index 90%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
index 271365e..ef5f985 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OPCUAPlcDriver.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
@@ -25,7 +25,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.plc4x.java.api.PlcConnection;
 import org.apache.plc4x.java.api.authentication.PlcAuthentication;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
-import org.apache.plc4x.java.opcua.connection.OPCUAConnectionFactory;
+import org.apache.plc4x.java.opcua.connection.OpcuaConnectionFactory;
 import org.apache.plc4x.java.spi.PlcDriver;
 
 import java.net.InetAddress;
@@ -37,20 +37,20 @@ import java.util.regex.Pattern;
  * Implementation of the OPC UA protocol, based on:
  * - Eclipse Milo (https://github.com/eclipse/milo)
  */
-public class OPCUAPlcDriver implements PlcDriver {
+public class OpcuaPlcDriver implements PlcDriver {
 
 
 
     public static final Pattern INET_ADDRESS_PATTERN = Pattern.compile("tcp://(?<host>[\\w.-]+)(:(?<port>\\d*))?");
     public static final Pattern OPCUA_URI_PATTERN = Pattern.compile("^opcua:(" + INET_ADDRESS_PATTERN + ")?" + "(?<params>/[\\w/]+)?");
     private static final int requestTimeout = 10000;
-    private OPCUAConnectionFactory opcuaConnectionFactory;
+    private OpcuaConnectionFactory opcuaConnectionFactory;
 
-    public OPCUAPlcDriver() {
-        this.opcuaConnectionFactory = new OPCUAConnectionFactory();
+    public OpcuaPlcDriver() {
+        this.opcuaConnectionFactory = new OpcuaConnectionFactory();
     }
 
-    public OPCUAPlcDriver(OPCUAConnectionFactory opcuaConnectionFactory) {
+    public OpcuaPlcDriver(OpcuaConnectionFactory opcuaConnectionFactory) {
         this.opcuaConnectionFactory = opcuaConnectionFactory;
     }
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
similarity index 93%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
index 26cbb09..0585e82 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOPCUAPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
@@ -27,16 +27,16 @@ import org.apache.plc4x.java.api.messages.PlcUnsubscriptionRequest;
 import org.apache.plc4x.java.api.messages.PlcWriteRequest;
 import org.apache.plc4x.java.base.connection.AbstractPlcConnection;
 import org.apache.plc4x.java.base.messages.*;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaPlcFieldHandler;
+import org.apache.plc4x.java.opcua.protocol.OpcuaPlcFieldHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
-public abstract class BaseOPCUAPlcConnection extends AbstractPlcConnection implements PlcReader, PlcWriter, PlcSubscriber {
+public abstract class BaseOpcuaPlcConnection extends AbstractPlcConnection implements PlcReader, PlcWriter, PlcSubscriber {
 
-    private static final Logger logger = LoggerFactory.getLogger(BaseOPCUAPlcConnection.class);
+    private static final Logger logger = LoggerFactory.getLogger(BaseOpcuaPlcConnection.class);
 
-    BaseOPCUAPlcConnection(String params) {
+    BaseOpcuaPlcConnection(String params) {
 
         if (!StringUtils.isEmpty(params)) {
             for (String param : params.split("&")) {
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
similarity index 83%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
index a49669c..84046ad 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
@@ -23,15 +23,15 @@ package org.apache.plc4x.java.opcua.connection;
 import java.net.InetAddress;
 import java.util.Objects;
 
-public class OPCUAConnectionFactory {
+public class OpcuaConnectionFactory {
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
+    public OpcuaTcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
         Objects.requireNonNull(address);
 
         if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
+            return OpcuaTcpPlcConnection.of(address, params, requestTimeout);
         } else {
-            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
+            return OpcuaTcpPlcConnection.of(address, port, params, requestTimeout);
         }
     }
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
similarity index 96%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
index afd89b5..b7de4b6 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUATcpPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
@@ -32,7 +32,7 @@ import org.apache.plc4x.java.base.messages.*;
 import org.apache.plc4x.java.base.messages.items.*;
 import org.apache.plc4x.java.base.model.SubscriptionPlcField;
 import org.apache.plc4x.java.opcua.protocol.OpcuaField;
-import org.apache.plc4x.java.opcua.protocol.model.OpcuaSubsriptionHandle;
+import org.apache.plc4x.java.opcua.protocol.OpcuaSubsriptionHandle;
 import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
 import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
 import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
@@ -70,11 +70,11 @@ import java.util.stream.Collectors;
 
 import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
 
-public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
+public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
 
     private static final int OPCUA_DEFAULT_TCP_PORT = 4840;
 
-    private static final Logger logger = LoggerFactory.getLogger(OPCUATcpPlcConnection.class);
+    private static final Logger logger = LoggerFactory.getLogger(OpcuaTcpPlcConnection.class);
     private InetAddress address;
     private int requestTimeout = 5000;
     private int port;
@@ -82,29 +82,30 @@ public class OPCUATcpPlcConnection extends BaseOPCUAPlcConnection {
     private OpcUaClient client;
     private boolean isConnected = false;
     private  final AtomicLong clientHandles = new AtomicLong(1L);
-    private OPCUATcpPlcConnection(InetAddress address, String params, int requestTimeout) {
+
+    private OpcuaTcpPlcConnection(InetAddress address, String params, int requestTimeout) {
         this( address, OPCUA_DEFAULT_TCP_PORT,  params, requestTimeout);
-        logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
+        logger.info("Configured OpcuaTcpPlcConnection with: host-name {}", address.getHostAddress());
     }
 
-    public OPCUATcpPlcConnection(InetAddress address, int port, String params, int requestTimeout) {
+    public OpcuaTcpPlcConnection(InetAddress address, int port, String params, int requestTimeout) {
         this(params);
-        logger.info("Configured OPCUATcpPlcConnection with: host-name {}", address.getHostAddress());
+        logger.info("Configured OpcuaTcpPlcConnection with: host-name {}", address.getHostAddress());
         this.address = address;
         this.port = port;
         this.params = params;
     }
 
-    public OPCUATcpPlcConnection(String params) {
+    public OpcuaTcpPlcConnection(String params) {
         super(params);
     }
 
-    public static OPCUATcpPlcConnection of(InetAddress address, String params, int requestTimeout) {
-        return new OPCUATcpPlcConnection(address, params, requestTimeout);
+    public static OpcuaTcpPlcConnection of(InetAddress address, String params, int requestTimeout) {
+        return new OpcuaTcpPlcConnection(address, params, requestTimeout);
     }
 
-    public static OPCUATcpPlcConnection of(InetAddress address, int port, String params, int requestTimeout) {
-        return new OPCUATcpPlcConnection(address, port, params, requestTimeout);
+    public static OpcuaTcpPlcConnection of(InetAddress address, int port, String params, int requestTimeout) {
+        return new OpcuaTcpPlcConnection(address, port, params, requestTimeout);
     }
 
 
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 0ac3c9f..cd33c75 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
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
 
 public class OpcuaField implements PlcField {
 
-    private 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>\\w+))?");
 
     private final OpcuaIdentifierType identifierType;
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
similarity index 98%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
index f265e81..c39a352 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaPlcFieldHandler.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
@@ -18,14 +18,13 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.protocol.model;
+package org.apache.plc4x.java.opcua.protocol;
 
 
 import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
 import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.base.connection.DefaultPlcFieldHandler;
 import org.apache.plc4x.java.base.messages.items.*;
-import org.apache.plc4x.java.opcua.protocol.OpcuaField;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
similarity index 94%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
rename to plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
index 582993c..08da653 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaSubsriptionHandle.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
@@ -18,7 +18,7 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.protocol.model;
+package org.apache.plc4x.java.opcua.protocol;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
@@ -28,7 +28,7 @@ import org.apache.plc4x.java.api.model.PlcSubscriptionHandle;
 import org.apache.plc4x.java.api.types.PlcResponseCode;
 import org.apache.plc4x.java.base.messages.DefaultPlcSubscriptionEvent;
 import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
-import org.apache.plc4x.java.opcua.connection.OPCUATcpPlcConnection;
+import org.apache.plc4x.java.opcua.connection.OpcuaTcpPlcConnection;
 import org.eclipse.milo.opcua.sdk.client.api.subscriptions.UaMonitoredItem;
 import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
 import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
@@ -66,7 +66,7 @@ public class OpcuaSubsriptionHandle implements PlcSubscriptionHandle {
             if(value.getStatusCode() != StatusCode.GOOD){
                 resultCode = PlcResponseCode.NOT_FOUND;
             }else{
-                stringItem = OPCUATcpPlcConnection.encodeFieldItem(value);
+                stringItem = OpcuaTcpPlcConnection.encodeFieldItem(value);
 
             }
             Map<String, Pair<PlcResponseCode, BaseDefaultFieldItem>> fields = new HashMap<>();
diff --git a/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver b/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
index 860acdc..fe96e3a 100644
--- a/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
+++ b/plc4j/drivers/opcua/src/main/resources/META-INF/services/org.apache.plc4x.java.spi.PlcDriver
@@ -16,4 +16,4 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-org.apache.plc4x.java.opcua.OPCUAPlcDriver
+org.apache.plc4x.java.opcua.OpcuaPlcDriver
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
similarity index 94%
rename from plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
rename to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
index f6eb6d5..8d12925 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/ManualPLC4XOPCUA.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java
@@ -18,7 +18,7 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua;
 
 import org.apache.plc4x.java.PlcDriverManager;
 import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
@@ -28,8 +28,9 @@ import org.apache.plc4x.java.api.model.PlcField;
 import org.apache.plc4x.java.api.types.PlcSubscriptionType;
 import org.apache.plc4x.java.base.messages.DefaultPlcSubscriptionRequest;
 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.model.OpcuaPlcFieldHandler;
+import org.apache.plc4x.java.opcua.protocol.OpcuaPlcFieldHandler;
 
 import java.math.BigInteger;
 import java.time.Duration;
@@ -39,17 +40,15 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.function.Consumer;
 
-public class ManualPLC4XOPCUA {
+public class ManualPLC4XOpcua {
     public static void main(String args[]){
 
 
-
-
-        OPCUATcpPlcConnection opcuaConnection = null;
+        OpcuaTcpPlcConnection opcuaConnection = null;
         OpcuaPlcFieldHandler fieldH = new OpcuaPlcFieldHandler();
         PlcField field = fieldH.createField("ns=2;i=10855");
         try {
-            opcuaConnection = (OPCUATcpPlcConnection)
+            opcuaConnection = (OpcuaTcpPlcConnection)
                 new PlcDriverManager().getConnection("opcua:tcp://opcua.demo-this.com:51210/UA/SampleServer");
 
         } catch (PlcConnectionException e) {
@@ -82,7 +81,6 @@ public class ManualPLC4XOPCUA {
 
             PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
             wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
-            /*
             wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
             wBuilder.addItem("w-Byte", "ns=2;i=10846", (byte)1);
             wBuilder.addItem("w-Double", "ns=2;i=10854", (double)0.25);
@@ -97,7 +95,6 @@ public class ManualPLC4XOPCUA {
             wBuilder.addItem("w-UInt32", "ns=2;i=10850", (long)21412);
             wBuilder.addItem("w-UInt64", "ns=2;i=10852", new BigInteger("1245152"));
             wBuilder.addItem("w-UInteger", "ns=2;i=10870", new BigInteger("1245152"));
-*/
             PlcWriteRequest writeRequest = wBuilder.build();
             PlcWriteResponse wResponse = opcuaConnection.write(writeRequest).get();
 
@@ -113,7 +110,7 @@ public class ManualPLC4XOPCUA {
             PlcConsumerRegistration registration = opcuaConnection.register(consumer, subResp.getSubscriptionHandles());
             Thread.sleep(7000);
             registration.unregister();
-            Thread.sleep(200000);
+            Thread.sleep(20000);
             opcuaConnection.close();
         } catch (Exception e) {
             e.printStackTrace();
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
new file mode 100644
index 0000000..0e0dd01
--- /dev/null
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
@@ -0,0 +1,66 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
+package org.apache.plc4x.java.opcua;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.INET_ADDRESS_PATTERN;
+import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.OPCUA_URI_PATTERN;
+import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
+
+public class OpcuaPlcDriverTest {
+    @BeforeEach
+    public void before() {
+    }
+
+    @AfterEach
+    public void after() {
+
+    }
+
+    @Test
+    public void testOpcuaAddressPattern() {
+
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://localhost");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://localhost:3131");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://www.google.de");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://www.google.de:443");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://127.0.0.1");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://127.0.0.1:251");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://254.254.254.254:1337");
+        assertMatching(INET_ADDRESS_PATTERN, "tcp://254.254.254.254");
+
+
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://localhost");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://localhost:3131");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://www.google.de");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://www.google.de:443");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://127.0.0.1");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://127.0.0.1:251");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://254.254.254.254:1337");
+        assertMatching(OPCUA_URI_PATTERN, "opcua:tcp://254.254.254.254");
+
+
+    }
+
+}
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
similarity index 59%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
index a49669c..bb1851a 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
@@ -6,9 +6,9 @@
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
- 
-   http://www.apache.org/licenses/LICENSE-2.0
- 
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,21 +18,22 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.connection;
-
-import java.net.InetAddress;
-import java.util.Objects;
+package org.apache.plc4x.java.opcua;
 
-public class OPCUAConnectionFactory {
+import java.util.regex.Pattern;
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
-        Objects.requireNonNull(address);
+import static org.junit.Assert.fail;
 
-        if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
-        } else {
-            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
+public class UtilsTest {
+    public static void assertMatching(Pattern pattern, String match) {
+        if (!pattern.matcher(match).matches()) {
+            fail(pattern + "doesn't match " + match);
         }
     }
 
+    public static void assertNoMatching(Pattern pattern, String match) {
+        if (pattern.matcher(match).matches()) {
+            fail(pattern + "does match " + match + " but should not");
+        }
+    }
 }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
similarity index 65%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
index a49669c..0e31f61 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
@@ -6,9 +6,9 @@
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
- 
+
    http://www.apache.org/licenses/LICENSE-2.0
- 
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,19 +20,16 @@
  */
 package org.apache.plc4x.java.opcua.connection;
 
-import java.net.InetAddress;
-import java.util.Objects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class OPCUAConnectionFactory {
+public class OpcuaTcpPlcConnectionTest {
+    @BeforeEach
+    public void before() {
+    }
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
-        Objects.requireNonNull(address);
+    @AfterEach
+    public void after() {
 
-        if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
-        } else {
-            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
-        }
     }
-
 }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java
similarity index 52%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java
index a49669c..f838b45 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaFieldTest.java
@@ -6,9 +6,9 @@
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
- 
+
    http://www.apache.org/licenses/LICENSE-2.0
- 
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,21 +18,33 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua.protocol;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
+import static org.apache.plc4x.java.opcua.protocol.OpcuaField.ADDRESS_PATTERN;
 
-import java.net.InetAddress;
-import java.util.Objects;
+public class OpcuaFieldTest {
 
-public class OPCUAConnectionFactory {
+    @BeforeEach
+    public void before() {
+    }
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
-        Objects.requireNonNull(address);
+    @AfterEach
+    public void after() {
 
-        if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
-        } else {
-            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
-        }
     }
 
+    @Test
+    public void testOpcuaAddressPattern() {
+
+        assertMatching(ADDRESS_PATTERN, "ns=2;i=10846");
+        assertMatching(ADDRESS_PATTERN, "ns=2;s=test.variable.name.inspect");
+        assertMatching(ADDRESS_PATTERN, "ns=2;g=09087e75-8e5e-499b-954f-f2a8624db28a");
+        assertMatching(ADDRESS_PATTERN, "ns=2;b=asvaewavarahreb==");
+
+    }
 }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
similarity index 62%
copy from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
copy to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
index a49669c..3153582 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
@@ -6,9 +6,9 @@
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
- 
+
    http://www.apache.org/licenses/LICENSE-2.0
- 
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,21 +18,18 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua.protocol;
 
-import java.net.InetAddress;
-import java.util.Objects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class OPCUAConnectionFactory {
+public class OpcuaPlcFieldHandlerTest {
+    @BeforeEach
+    public void before() {
+    }
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
-        Objects.requireNonNull(address);
+    @AfterEach
+    public void after() {
 
-        if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
-        } else {
-            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
-        }
     }
-
 }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
similarity index 62%
rename from plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
rename to plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
index a49669c..bc75d14 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OPCUAConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
@@ -6,9 +6,9 @@
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
- 
+
    http://www.apache.org/licenses/LICENSE-2.0
- 
+
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -18,21 +18,18 @@
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.connection;
+package org.apache.plc4x.java.opcua.protocol;
 
-import java.net.InetAddress;
-import java.util.Objects;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
 
-public class OPCUAConnectionFactory {
+public class OpcuaSubscriptionHandleTest {
+    @BeforeEach
+    public void before() {
+    }
 
-    public OPCUATcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
-        Objects.requireNonNull(address);
+    @AfterEach
+    public void after() {
 
-        if (port == null) {
-            return OPCUATcpPlcConnection.of(address, params, requestTimeout);
-        } else {
-            return OPCUATcpPlcConnection.of(address, port, params, requestTimeout);
-        }
     }
-
 }


[plc4x] 06/07: [Fixed] JavaDoc formatting [Added] Warning messages at exception points with the consideration of adding later some run-time exceptions

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 21da7e6900be74f0eb0cfc12711713849a8e17cb
Author: Matthias Strljic <ma...@isw.uni-stuttgart.de>
AuthorDate: Tue May 14 14:33:58 2019 +0200

    [Fixed] JavaDoc formatting
    [Added] Warning messages at exception points with the consideration of adding later some run-time exceptions
---
 .../apache/plc4x/java/opcua/OpcuaPlcDriver.java    |   9 +-
 .../opcua/connection/BaseOpcuaPlcConnection.java   |   9 +-
 .../opcua/connection/OpcuaConnectionFactory.java   |   9 +-
 .../opcua/connection/OpcuaTcpPlcConnection.java    | 175 ++++++++++-----------
 .../plc4x/java/opcua/protocol/OpcuaField.java      |  14 +-
 .../java/opcua/protocol/OpcuaPlcFieldHandler.java  |   9 +-
 .../opcua/protocol/OpcuaSubsriptionHandle.java     |   9 +-
 .../java/opcua/protocol/model/OpcuaDataTypes.java  |  39 ++---
 .../opcua/protocol/model/OpcuaIdentifierType.java  |  33 +++-
 .../apache/plc4x/java/opcua/ManualPLC4XOpcua.java  |  92 ++++++-----
 .../plc4x/java/opcua/OpcuaPlcDriverTest.java       |   9 +-
 .../org/apache/plc4x/java/opcua/UtilsTest.java     |   9 +-
 .../connection/OpcuaTcpPlcConnectionTest.java      |   9 +-
 .../plc4x/java/opcua/protocol/OpcuaFieldTest.java  |   9 +-
 .../opcua/protocol/OpcuaPlcFieldHandlerTest.java   |   9 +-
 .../protocol/OpcuaSubscriptionHandleTest.java      |   9 +-
 16 files changed, 250 insertions(+), 202 deletions(-)

diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
index ef5f985..7fefae7 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcuaPlcDriver.java
@@ -15,10 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
-
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua;
 
 import org.apache.commons.lang3.StringUtils;
@@ -33,9 +30,13 @@ import java.net.UnknownHostException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+
 /**
  * Implementation of the OPC UA protocol, based on:
  * - Eclipse Milo (https://github.com/eclipse/milo)
+ *
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 public class OpcuaPlcDriver implements PlcDriver {
 
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
index 0585e82..50a5bd0 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/BaseOpcuaPlcConnection.java
@@ -15,9 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.connection;
 
 import org.apache.commons.lang3.StringUtils;
@@ -31,7 +29,10 @@ import org.apache.plc4x.java.opcua.protocol.OpcuaPlcFieldHandler;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public abstract class BaseOpcuaPlcConnection extends AbstractPlcConnection implements PlcReader, PlcWriter, PlcSubscriber {
 
     private static final Logger logger = LoggerFactory.getLogger(BaseOpcuaPlcConnection.class);
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
index 84046ad..5c399f3 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaConnectionFactory.java
@@ -15,14 +15,15 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.connection;
 
 import java.net.InetAddress;
 import java.util.Objects;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaConnectionFactory {
 
     public OpcuaTcpPlcConnection opcuaTcpPlcConnectionOf(InetAddress address, Integer port, String params, int requestTimeout) {
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
index b7de4b6..c59c36a 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnection.java
@@ -94,6 +94,7 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
         this.address = address;
         this.port = port;
         this.params = params;
+        this.requestTimeout = requestTimeout;
     }
 
     public OpcuaTcpPlcConnection(String params) {
@@ -108,7 +109,51 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
         return new OpcuaTcpPlcConnection(address, port, params, requestTimeout);
     }
 
+    public static BaseDefaultFieldItem encodeFieldItem(DataValue value){
+        NodeId typeNode = value.getValue().getDataType().get();
+        Object objValue = value.getValue().getValue();
+
+        if(typeNode.equals(Identifiers.Boolean)){
+            return new DefaultBooleanFieldItem((Boolean)objValue);
+        }else if (typeNode.equals(Identifiers.ByteString)){
+            byte[] array = ((ByteString)objValue).bytes();
+            Byte[] byteArry = new Byte[array.length];
+            int counter = 0;
+            for (byte bytie: array
+            ) {
+                byteArry[counter] = bytie;
+                counter++;
+            }
+            return new DefaultByteArrayFieldItem(byteArry);
+        }else if (typeNode.equals(Identifiers.Integer)){
+            return new DefaultIntegerFieldItem((Integer)objValue);
+        }else if (typeNode.equals(Identifiers.Int16)){
+            return new DefaultShortFieldItem((Short)objValue);
+        }else if (typeNode.equals(Identifiers.Int32)){
+            return new DefaultIntegerFieldItem((Integer)objValue);
+        }else if (typeNode.equals(Identifiers.Int64)){
+            return new DefaultLongFieldItem((Long)objValue);
+        }else if (typeNode.equals(Identifiers.UInteger)){
+            return new DefaultLongFieldItem((Long)objValue);
+        }else if (typeNode.equals(Identifiers.UInt16)){
+            return new DefaultIntegerFieldItem(((UShort)objValue).intValue());
+        }else if (typeNode.equals(Identifiers.UInt32)){
+            return new DefaultLongFieldItem(((UInteger)objValue).longValue());
+        }else if (typeNode.equals(Identifiers.UInt64)){
+            return new DefaultBigIntegerFieldItem(new BigInteger(objValue.toString()));
+        }else if (typeNode.equals(Identifiers.Byte)){
+            return new DefaultShortFieldItem(Short.valueOf(objValue.toString()));
+        }else if (typeNode.equals(Identifiers.Float)){
+            return new DefaultFloatFieldItem((Float)objValue);
+        }else if (typeNode.equals(Identifiers.Double)){
+            return new DefaultDoubleFieldItem((Double)objValue);
+        }else if (typeNode.equals(Identifiers.SByte)){
+            return new DefaultByteFieldItem((Byte)objValue);
+        }else {
+            return new DefaultStringFieldItem(objValue.toString());
+        }
 
+    }
 
     public InetAddress getRemoteAddress() {
         return address;
@@ -120,6 +165,7 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
 
         try {
             endpoints = DiscoveryClient.getEndpoints(getEndpointUrl(address, port, params)).get();
+        //TODO Exception should be handeled better when the Discovery-API of Milo is stable
         } catch (Exception ex) {
             // try the explicit discovery endpoint as well
             String discoveryUrl = getEndpointUrl(address, port, params);
@@ -144,7 +190,7 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
                 .orElseThrow(() -> new PlcConnectionException("No desired endpoints from"));
 
         OpcUaClientConfig config = OpcUaClientConfig.builder()
-            .setApplicationName(LocalizedText.english("eclipse milo opc-ua client"))
+            .setApplicationName(LocalizedText.english("eclipse milo opc-ua client of the apache PLC4X:PLC4J project"))
             .setApplicationUri("urn:eclipse:milo:plc4x:client")
             .setEndpoint(endpoint)
             .setIdentityProvider(getIdentityProvider())
@@ -155,9 +201,13 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
             this.client =  OpcUaClient.create(config);
             this.client.connect().get();
             isConnected = true;
-        } catch (UaException | InterruptedException | ExecutionException e) {
+        } catch (UaException e) {
             isConnected = false;
-
+            String message = (config == null) ? "NULL" : config.toString();
+            throw  new PlcConnectionException("The given input values are a not valid OPC UA connection configuration [CONFIG]: " + message);
+        } catch (InterruptedException | ExecutionException e) {
+            isConnected = false;
+            throw  new PlcConnectionException("Error while creation of the connection because of : " + e.getMessage());
         }
     }
 
@@ -232,18 +282,15 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
 
                     subHandle = subsriptionHandle;
                     responseCode = PlcResponseCode.OK;
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                } catch (ExecutionException e) {
-                    e.printStackTrace();
+                } catch (InterruptedException | ExecutionException e) {
+                    logger.warn("Unable to subscribe Elements because of: {}", e.getMessage());
                 }
 
 
                 return Pair.of(plcFieldName, Pair.of(responseCode, subHandle));
             })
             .collect(Collectors.toMap(Pair::getKey, Pair::getValue));
-            PlcSubscriptionResponse result = new DefaultPlcSubscriptionResponse(internalPlcSubscriptionRequest, responseItems);
-            return result;
+            return (PlcSubscriptionResponse) new DefaultPlcSubscriptionResponse(internalPlcSubscriptionRequest, responseItems);
         });
 
         return future;
@@ -256,10 +303,8 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
             OpcuaSubsriptionHandle opcSubHandle = (OpcuaSubsriptionHandle) o;
             try {
                 client.getSubscriptionManager().deleteSubscription(opcSubHandle.getClientHandle()).get();
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            } catch (ExecutionException e) {
-                e.printStackTrace();
+            } catch (InterruptedException | ExecutionException e) {
+                logger.warn("Unable to unsubscribe Elements because of: {}", e.getMessage());
             }
         });
 
@@ -295,17 +340,13 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
             List<DataValue> readValues = null;
             try {
                 readValues = dataValueCompletableFuture.get();
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-                readValues = new LinkedList<>();
-            } catch (ExecutionException e) {
-                e.printStackTrace();
-                readValues = new LinkedList<>();
+            } catch (InterruptedException | ExecutionException e) {
+                logger.warn("Unable to read Elements because of: {}", e.getMessage());
             }
-            for(int counter = 0; counter < readValues.size(); counter++){
+            for(int counter = 0; counter < readValueIds.size(); counter++){
                 PlcResponseCode resultCode = PlcResponseCode.OK;
                 BaseDefaultFieldItem stringItem = null;
-                if(readValues.get(counter).getStatusCode() != StatusCode.GOOD){
+                if(readValues == null || readValues.size() <= counter || readValues.get(counter).getStatusCode() != StatusCode.GOOD){
                     resultCode = PlcResponseCode.NOT_FOUND;
                 }else{
                     stringItem = encodeFieldItem(readValues.get(counter));
@@ -317,81 +358,13 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
 
             }
             InternalPlcReadRequest internalPlcReadRequest = checkInternal(readRequest, InternalPlcReadRequest.class);
-            PlcReadResponse response = new DefaultPlcReadResponse(internalPlcReadRequest, fields );
-            return response;
+            return (PlcReadResponse) new DefaultPlcReadResponse(internalPlcReadRequest, fields );
         });
 
 
         return future;
     }
 
-    private NodeId generateNodeId(OpcuaField uaField){
-        NodeId idNode = null;
-        switch (uaField.getIdentifierType()) {
-            case s:
-                idNode = new NodeId(uaField.getNamespace(), uaField.getIdentifier());
-                break;
-            case i:
-                idNode = new NodeId(uaField.getNamespace(), UInteger.valueOf(uaField.getIdentifier()));
-                break;
-            case g:
-                idNode = new NodeId(uaField.getNamespace(), UUID.fromString(uaField.getIdentifier()));
-                break;
-            case b:
-                idNode = new NodeId(uaField.getNamespace(), new ByteString(uaField.getIdentifier().getBytes()));
-                break;
-
-            default: idNode = new NodeId(uaField.getNamespace(), uaField.getIdentifier());
-        }
-
-        return  idNode;
-    }
-
-    public static BaseDefaultFieldItem encodeFieldItem(DataValue value){
-        NodeId typeNode = value.getValue().getDataType().get();
-        Object objValue = value.getValue().getValue();
-
-        if(typeNode.equals(Identifiers.Boolean)){
-            return new DefaultBooleanFieldItem((Boolean)objValue);
-        }else if (typeNode.equals(Identifiers.ByteString)){
-            byte[] array = ((ByteString)objValue).bytes();
-            Byte[] byteArry = new Byte[array.length];
-            int counter = 0;
-            for (byte bytie: array
-                 ) {
-                byteArry[counter] = bytie;
-                counter++;
-            }
-            return new DefaultByteArrayFieldItem(byteArry);
-        }else if (typeNode.equals(Identifiers.Integer)){
-            return new DefaultIntegerFieldItem((Integer)objValue);
-        }else if (typeNode.equals(Identifiers.Int16)){
-            return new DefaultShortFieldItem((Short)objValue);
-        }else if (typeNode.equals(Identifiers.Int32)){
-            return new DefaultIntegerFieldItem((Integer)objValue);
-        }else if (typeNode.equals(Identifiers.Int64)){
-            return new DefaultLongFieldItem((Long)objValue);
-        }else if (typeNode.equals(Identifiers.UInteger)){
-            return new DefaultLongFieldItem((Long)objValue);
-        }else if (typeNode.equals(Identifiers.UInt16)){
-            return new DefaultIntegerFieldItem(((UShort)objValue).intValue());
-        }else if (typeNode.equals(Identifiers.UInt32)){
-            return new DefaultLongFieldItem(((UInteger)objValue).longValue());
-        }else if (typeNode.equals(Identifiers.UInt64)){
-            return new DefaultBigIntegerFieldItem(new BigInteger(objValue.toString()));
-        }else if (typeNode.equals(Identifiers.Byte)){
-            return new DefaultShortFieldItem(Short.valueOf(objValue.toString()));
-        }else if (typeNode.equals(Identifiers.Float)){
-            return new DefaultFloatFieldItem((Float)objValue);
-        }else if (typeNode.equals(Identifiers.Double)){
-            return new DefaultDoubleFieldItem((Double)objValue);
-        }else if (typeNode.equals(Identifiers.SByte)){
-            return new DefaultByteFieldItem((Byte)objValue);
-        }else {
-            return new DefaultStringFieldItem(objValue.toString());
-        }
-
-    }
 
     @Override
     public CompletableFuture<PlcWriteResponse> write(PlcWriteRequest writeRequest) {
@@ -451,6 +424,28 @@ public class OpcuaTcpPlcConnection extends BaseOpcuaPlcConnection {
     }
 
 
+    private NodeId generateNodeId(OpcuaField uaField){
+        NodeId idNode = null;
+        switch (uaField.getIdentifierType()) {
+            case STRING_IDENTIFIER:
+                idNode = new NodeId(uaField.getNamespace(), uaField.getIdentifier());
+                break;
+            case NUMBER_IDENTIFIER:
+                idNode = new NodeId(uaField.getNamespace(), UInteger.valueOf(uaField.getIdentifier()));
+                break;
+            case GUID_IDENTIFIER:
+                idNode = new NodeId(uaField.getNamespace(), UUID.fromString(uaField.getIdentifier()));
+                break;
+            case BINARY_IDENTIFIER:
+                idNode = new NodeId(uaField.getNamespace(), new ByteString(uaField.getIdentifier().getBytes()));
+                break;
+
+            default: idNode = new NodeId(uaField.getNamespace(), uaField.getIdentifier());
+        }
+
+        return  idNode;
+    }
+
     private String getEndpointUrl(InetAddress address, Integer port, String params) {
         return "opc.tcp://" + address.getHostAddress() +":" + port + "/" + params;
     }
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 cd33c75..91ece25 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
@@ -15,9 +15,7 @@ software distributed under the License is distributed on an
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.protocol;
 
 import org.apache.plc4x.java.api.exceptions.PlcInvalidFieldException;
@@ -27,7 +25,10 @@ import org.apache.plc4x.java.opcua.protocol.model.OpcuaIdentifierType;
 import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaField implements PlcField {
 
     public static final Pattern ADDRESS_PATTERN = Pattern.compile("^ns=(?<namespace>\\d+);(?<identifierType>[isgb])=((?<identifier>\\w+))?");
@@ -64,7 +65,7 @@ public class OpcuaField implements PlcField {
         String identifier = matcher.group("identifier");
 
         String identifierTypeString = matcher.group("identifierType");
-        OpcuaIdentifierType identifierType = OpcuaIdentifierType.valueOf(identifierTypeString);
+        OpcuaIdentifierType identifierType = OpcuaIdentifierType.fromString(identifierTypeString);
 
         String namespaceString = matcher.group("namespace");
         Integer namespace = namespaceString != null ? Integer.valueOf(namespaceString) : 0;
@@ -98,7 +99,7 @@ public class OpcuaField implements PlcField {
             return false;
         }
         OpcuaField that = (OpcuaField) o;
-        return namespace == that.namespace && identifier.equals(that.identifier);
+        return namespace == that.namespace && identifier.equals(that.identifier) && identifierType == that.identifierType;
     }
 
     @Override
@@ -110,6 +111,7 @@ public class OpcuaField implements PlcField {
     public String toString() {
         return "OpcuaField{" +
             "namespace=" + namespace +
+            "identifierType=" + identifierType.getText() +
             "identifier=" + identifier +
             '}';
     }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
index c39a352..bb44a8e 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandler.java
@@ -15,9 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.protocol;
 
 
@@ -28,7 +26,10 @@ import org.apache.plc4x.java.base.messages.items.*;
 
 import java.math.BigInteger;
 import java.util.ArrayList;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaPlcFieldHandler extends DefaultPlcFieldHandler {
 
     @Override
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
index 08da653..8080d22 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubsriptionHandle.java
@@ -15,9 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.protocol;
 
 import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -40,7 +38,10 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.function.Consumer;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaSubsriptionHandle implements PlcSubscriptionHandle {
     Set< Consumer<PlcSubscriptionEvent>> consumers = new HashSet<>();
     String fieldName;
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
index c0bfe65..af95137 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaDataTypes.java
@@ -15,31 +15,32 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
+*/
+package org.apache.plc4x.java.opcua.protocol.model;
+/**
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */
-package org.apache.plc4x.java.opcua.protocol.model;
-
 public enum OpcuaDataTypes {
     BOOL,
     SByte,
     Byte,
-    Int16,
-    UInt16,
-    Int32,
-    UInt32,
-    Int64,
-    Uint64,
-    Float,
-    Double,
-    StatusCode,
-    String,
-    DateTime,
-    Guid,
-    ByteString,
-    XMLElement,
-    NodeId,
-    ExpandedNodeId,
-    QualifiedName
+    INT16,
+    UINT16,
+    INT32,
+    UINT32,
+    INT64,
+    UINT64,
+    FLOAT,
+    DOUBLE,
+    STATUS_CODE,
+    STRING,
+    DATE_TIME,
+    GUID,
+    BYTE_STRING,
+    XML_ELEMENT,
+    NODE_ID,
+    EXPANDABLE_NODE_ID,
+    QUALIFIED_NAME
 
 }
diff --git a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
index 599ad05..3122deb 100644
--- a/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
+++ b/plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/model/OpcuaIdentifierType.java
@@ -15,14 +15,35 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
  */
 package org.apache.plc4x.java.opcua.protocol.model;
 
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public enum OpcuaIdentifierType {
-    s,
-    i,
-    g,
-    b
+    STRING_IDENTIFIER("s"),
+    NUMBER_IDENTIFIER("i"),
+    GUID_IDENTIFIER("g"),
+    BINARY_IDENTIFIER("BINARY_IDENTIFIER");
+
+    private String text;
+
+    OpcuaIdentifierType(String text) {
+        this.text = text;
+    }
+
+    public String getText() {
+        return this.text;
+    }
+
+    public static OpcuaIdentifierType fromString(String text) {
+        for (OpcuaIdentifierType type : OpcuaIdentifierType.values()) {
+            if (type.text.equalsIgnoreCase(text)) {
+                return type;
+            }
+        }
+        throw new IllegalArgumentException("No constant with text " + text + " found");
+    }
 }
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 8d12925..57d1f79 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
@@ -15,9 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua;
 
 import org.apache.plc4x.java.PlcDriverManager;
@@ -39,8 +37,29 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.function.Consumer;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic 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 DOES_NOT_EXIST_IDENTIFIER = "ns=2;i=12512623";
+
+
     public static void main(String args[]){
 
 
@@ -56,45 +75,44 @@ public class ManualPLC4XOpcua {
         }
         try {
             PlcReadRequest.Builder builder = opcuaConnection.readRequestBuilder();
-            //builder.addItem("String", "ns=2;i=10855");
-            builder.addItem("Bool", "ns=2;i=10844");
-            builder.addItem("ByteString", "ns=2;i=10858");
-            builder.addItem("Byte", "ns=2;i=10846");
-            builder.addItem("Double", "ns=2;i=10854");
-            builder.addItem("Float", "ns=2;i=10853");
-            builder.addItem("Int16", "ns=2;i=10847");
-            builder.addItem("Int32", "ns=2;i=10849");
-            builder.addItem("Int64", "ns=2;i=10851");
-            builder.addItem("Integer", "ns=2;i=10869");
-            builder.addItem("SByte", "ns=2;i=10845");
-            builder.addItem("String", "ns=2;i=10855");
-            builder.addItem("UInt16", "ns=2;i=10848");
-            builder.addItem("UInt32", "ns=2;i=10850");
-            builder.addItem("UInt64", "ns=2;i=10852");
-            builder.addItem("UInteger", "ns=2;i=10870");
+            builder.addItem("Bool", BOOL_IDENTIFIER);
+            builder.addItem("ByteString", BYTE_STRING_IDENTIFIER);
+            builder.addItem("Byte", BYTE_IDENTIFIER);
+            builder.addItem("Double", DOUBLE_IDENTIFIER);
+            builder.addItem("Float", FLOAT_IDENTIFIER);
+            builder.addItem("Int16", INT16_IDENTIFIER);
+            builder.addItem("Int32", INT32_IDENTIFIER);
+            builder.addItem("Int64", INT64_IDENTIFIER);
+            builder.addItem("Integer", INTEGER_IDENTIFIER);
+            builder.addItem("SByte", SBYTE_IDENTIFIER);
+            builder.addItem("String", STRING_IDENTIFIER);
+            builder.addItem("UInt16", UINT16_IDENTIFIER);
+            builder.addItem("UInt32", UINT32_IDENTIFIER);
+            builder.addItem("UInt64", UINT64_IDENTIFIER);
+            builder.addItem("UInteger", UINTEGER_IDENTIFIER);
 
-            builder.addItem("DoesNotExists", "ns=2;i=12512623");
+            builder.addItem("DoesNotExists", DOES_NOT_EXIST_IDENTIFIER);
 
             PlcReadRequest request = builder.build();
             PlcReadResponse response = opcuaConnection.read(request).get();
             Collection coll = response.getAllStrings("String");
 
             PlcWriteRequest.Builder wBuilder = opcuaConnection.writeRequestBuilder();
-            wBuilder.addItem("w-Bool", "ns=2;i=11012", true);
-            wBuilder.addItem("w-ByteString", "ns=2;i=10858", "TEST".getBytes());
-            wBuilder.addItem("w-Byte", "ns=2;i=10846", (byte)1);
-            wBuilder.addItem("w-Double", "ns=2;i=10854", (double)0.25);
-            wBuilder.addItem("w-Float", "ns=2;i=10853", (float)0.25);
-            wBuilder.addItem("w-Int16", "ns=2;i=10847", (short)12);
-            wBuilder.addItem("w-Int32", "ns=2;i=10849", (int)314);
-            wBuilder.addItem("w-Int64", "ns=2;i=10851", (long)123125);
-            wBuilder.addItem("w-Integer", "ns=2;i=10869", (int)314);
-            wBuilder.addItem("w-SByte", "ns=2;i=10845", (short)23);
-            wBuilder.addItem("w-String", "ns=2;i=10855", "TEST");
-            wBuilder.addItem("w-UInt16", "ns=2;i=10848", (int)222);
-            wBuilder.addItem("w-UInt32", "ns=2;i=10850", (long)21412);
-            wBuilder.addItem("w-UInt64", "ns=2;i=10852", new BigInteger("1245152"));
-            wBuilder.addItem("w-UInteger", "ns=2;i=10870", new BigInteger("1245152"));
+            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-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-String", STRING_IDENTIFIER, "TEST");
+            wBuilder.addItem("w-UInt16", UINT16_IDENTIFIER, (int)222);
+            wBuilder.addItem("w-UInt32", UINT32_IDENTIFIER, (long)21412);
+            wBuilder.addItem("w-UInt64", UINT64_IDENTIFIER, new BigInteger("1245152"));
+            wBuilder.addItem("w-UInteger", UINTEGER_IDENTIFIER, new BigInteger("1245152"));
             PlcWriteRequest writeRequest = wBuilder.build();
             PlcWriteResponse wResponse = opcuaConnection.write(writeRequest).get();
 
@@ -102,7 +120,7 @@ public class ManualPLC4XOpcua {
                 opcuaConnection,
                 new LinkedHashMap<>(
                     Collections.singletonMap("field1",
-                        new SubscriptionPlcField(PlcSubscriptionType.CHANGE_OF_STATE, OpcuaField.of("ns=2;i=10855"), Duration.of(1, ChronoUnit.SECONDS)))
+                        new SubscriptionPlcField(PlcSubscriptionType.CHANGE_OF_STATE, OpcuaField.of(STRING_IDENTIFIER), Duration.of(1, ChronoUnit.SECONDS)))
                 )
             )).get();
 
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
index 0e0dd01..8c502ed 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/OpcuaPlcDriverTest.java
@@ -15,9 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua;
 
 import org.junit.jupiter.api.AfterEach;
@@ -27,7 +25,10 @@ import org.junit.jupiter.api.Test;
 import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.INET_ADDRESS_PATTERN;
 import static org.apache.plc4x.java.opcua.OpcuaPlcDriver.OPCUA_URI_PATTERN;
 import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaPlcDriverTest {
     @BeforeEach
     public void before() {
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
index bb1851a..2e84a0b 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/UtilsTest.java
@@ -15,15 +15,16 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua;
 
 import java.util.regex.Pattern;
 
 import static org.junit.Assert.fail;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class UtilsTest {
     public static void assertMatching(Pattern pattern, String match) {
         if (!pattern.matcher(match).matches()) {
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
index 0e31f61..5a42c5e 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/connection/OpcuaTcpPlcConnectionTest.java
@@ -15,14 +15,15 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.connection;
 
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaTcpPlcConnectionTest {
     @BeforeEach
     public void before() {
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 f838b45..828a0e6 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
@@ -15,9 +15,7 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.protocol;
 
 import org.junit.jupiter.api.AfterEach;
@@ -26,7 +24,10 @@ import org.junit.jupiter.api.Test;
 
 import static org.apache.plc4x.java.opcua.UtilsTest.assertMatching;
 import static org.apache.plc4x.java.opcua.protocol.OpcuaField.ADDRESS_PATTERN;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaFieldTest {
 
     @BeforeEach
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
index 3153582..044de34 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaPlcFieldHandlerTest.java
@@ -15,14 +15,15 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.protocol;
 
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaPlcFieldHandlerTest {
     @BeforeEach
     public void before() {
diff --git a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
index bc75d14..153d4ca 100644
--- a/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
+++ b/plc4j/drivers/opcua/src/test/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandleTest.java
@@ -15,14 +15,15 @@
  KIND, either express or implied.  See the License for the
  specific language governing permissions and limitations
  under the License.
- * @author Matthias Milan Stlrljic
- * Created by Matthias Milan Stlrljic on 10.05.2019
- */
+*/
 package org.apache.plc4x.java.opcua.protocol;
 
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
-
+/**
+ * @author Matthias Milan Stlrljic
+ * Created by Matthias Milan Stlrljic on 10.05.2019
+ */
 public class OpcuaSubscriptionHandleTest {
     @BeforeEach
     public void before() {


[plc4x] 07/07: [Added] descriptive class comments to ManualPLC4XOpcua

Posted by jf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jfeinauer pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit 3c00fa3548e782d00dd15303ca10c4b5263f3f08
Author: Matthias Strljic <ma...@isw.uni-stuttgart.de>
AuthorDate: Tue May 14 14:41:03 2019 +0200

    [Added] descriptive class comments to ManualPLC4XOpcua
---
 .../test/java/org/apache/plc4x/java/opcua/ManualPLC4XOpcua.java   | 8 ++++++++
 1 file changed, 8 insertions(+)

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 57d1f79..7708a89 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
@@ -38,6 +38,14 @@ import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.function.Consumer;
 /**
+ * This class serves only as a manual entry point for ad-hoc tests of the OPC UA PLC4J driver.
+ *
+ *
+ * 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
+ *
  * @author Matthias Milan Stlrljic
  * Created by Matthias Milan Stlrljic on 10.05.2019
  */