You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2018/06/28 12:02:30 UTC

[incubator-plc4x] branch feature/mobbus-support-with-lib updated (ae4e81b -> 6f222f0)

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

sruehl pushed a change to branch feature/mobbus-support-with-lib
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


    from ae4e81b  use combine children attribute to merge ignored dependencies
     new 3b5fd72  added some logging
     new 6f222f0  added possibility to supply port to modbus

The 2 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:
 .../apache/plc4x/java/modbus/ModbusPlcDriver.java  |  8 ++++--
 .../modbus/connection/ModbusTcpPlcConnection.java  |  5 ++++
 .../java/modbus/netty/Plc4XModbusProtocol.java     | 12 +++++++++
 .../plc4x/java/modbus/ManualPlc4XModbusTest.java   |  4 +--
 .../modbus/src/test/resources/logback.xml          | 30 +++++++++++-----------
 5 files changed, 40 insertions(+), 19 deletions(-)


[incubator-plc4x] 01/02: added some logging

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

sruehl pushed a commit to branch feature/mobbus-support-with-lib
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 3b5fd72187fb733c48744ed70ecefa1bd9f13fee
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 28 14:01:42 2018 +0200

    added some logging
---
 .../apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java  | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java b/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java
index db575da..5f77d92 100644
--- a/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java
+++ b/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/netty/Plc4XModbusProtocol.java
@@ -30,6 +30,8 @@ import org.apache.plc4x.java.api.messages.*;
 import org.apache.plc4x.java.api.messages.items.*;
 import org.apache.plc4x.java.api.types.ResponseCode;
 import org.apache.plc4x.java.modbus.model.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
@@ -38,6 +40,8 @@ import java.util.concurrent.atomic.AtomicInteger;
 
 public class Plc4XModbusProtocol extends MessageToMessageCodec<ModbusTcpPayload, PlcRequestContainer<PlcRequest, PlcResponse>> {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(Plc4XModbusProtocol.class);
+
     public final AtomicInteger transactionId = new AtomicInteger();
 
     private final ConcurrentMap<Short, PlcRequestContainer<PlcRequest, PlcResponse>> requestsMap = new ConcurrentHashMap<>();
@@ -47,6 +51,7 @@ public class Plc4XModbusProtocol extends MessageToMessageCodec<ModbusTcpPayload,
 
     @Override
     protected void encode(ChannelHandlerContext ctx, PlcRequestContainer<PlcRequest, PlcResponse> msg, List<Object> out) throws Exception {
+        LOGGER.trace("(<--OUT): {}, {}, {}", ctx, msg, out);
         // Reset tranactionId on overflow
         transactionId.compareAndSet(Short.MAX_VALUE + 1, 0);
         PlcRequest request = msg.getRequest();
@@ -124,6 +129,7 @@ public class Plc4XModbusProtocol extends MessageToMessageCodec<ModbusTcpPayload,
     @SuppressWarnings("unchecked")
     @Override
     protected void decode(ChannelHandlerContext ctx, ModbusTcpPayload msg, List<Object> out) throws Exception {
+        LOGGER.trace("(-->IN): {}, {}, {}", ctx, msg, out);
         // TODO: implement me
         short transactionId = msg.getTransactionId();
         PlcRequestContainer<PlcRequest, PlcResponse> plcRequestContainer = requestsMap.get(transactionId);
@@ -179,6 +185,12 @@ public class Plc4XModbusProtocol extends MessageToMessageCodec<ModbusTcpPayload,
         }
     }
 
+    @Override
+    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+        LOGGER.trace("(-->ERR): {}", ctx, cause);
+        super.exceptionCaught(ctx, cause);
+    }
+
     ////////////////////////////////////////////////////////////////////////////////
     // Encoding helpers.
     ////////////////////////////////////////////////////////////////////////////////


[incubator-plc4x] 02/02: added possibility to supply port to modbus

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

sruehl pushed a commit to branch feature/mobbus-support-with-lib
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 6f222f06539b842120022885f9fcc15b2a67b7f6
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 28 14:02:24 2018 +0200

    added possibility to supply port to modbus
---
 .../apache/plc4x/java/modbus/ModbusPlcDriver.java  |  8 ++++--
 .../modbus/connection/ModbusTcpPlcConnection.java  |  5 ++++
 .../plc4x/java/modbus/ManualPlc4XModbusTest.java   |  4 +--
 .../modbus/src/test/resources/logback.xml          | 30 +++++++++++-----------
 4 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/ModbusPlcDriver.java b/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/ModbusPlcDriver.java
index 2f13b91..0ceaf4d 100644
--- a/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/ModbusPlcDriver.java
+++ b/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/ModbusPlcDriver.java
@@ -66,12 +66,16 @@ public class ModbusPlcDriver implements PlcDriver {
             String hostName = matcher.group("host");
             try {
                 InetAddress inetAddress = InetAddress.getByName(host);
-                return new ModbusTcpPlcConnection(inetAddress, params);
+                if (port == null) {
+                    return new ModbusTcpPlcConnection(inetAddress, params);
+                } else {
+                    return new ModbusTcpPlcConnection(inetAddress, Integer.valueOf(port), params);
+                }
             } catch (UnknownHostException e) {
                 throw new PlcConnectionException("Unknown host" + hostName, e);
             }
         } else {
-            return new ModbusSerialPlcConnection(port, params);
+            return new ModbusSerialPlcConnection(serialDefinition, params);
         }
     }
 
diff --git a/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/connection/ModbusTcpPlcConnection.java b/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/connection/ModbusTcpPlcConnection.java
index 38ca1e2..d5c912d 100644
--- a/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/connection/ModbusTcpPlcConnection.java
+++ b/plc4j/protocols/modbus/src/main/java/org/apache/plc4x/java/modbus/connection/ModbusTcpPlcConnection.java
@@ -44,6 +44,11 @@ public class ModbusTcpPlcConnection extends BaseModbusPlcConnection {
         logger.info("Configured ModbusTcpPlcConnection with: host-name {}", address.getHostAddress());
     }
 
+    public ModbusTcpPlcConnection(InetAddress address, int port, String params) {
+        this(new TcpSocketChannelFactory(address, port), params);
+        logger.info("Configured ModbusTcpPlcConnection with: host-name {}", address.getHostAddress());
+    }
+
     public ModbusTcpPlcConnection(ChannelFactory channelFactory, String params) {
         super(channelFactory, params);
     }
diff --git a/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java b/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java
index 5e89dcf..e320b1f 100644
--- a/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java
+++ b/plc4j/protocols/modbus/src/test/java/org/apache/plc4x/java/modbus/ManualPlc4XModbusTest.java
@@ -37,14 +37,14 @@ public class ManualPlc4XModbusTest {
             connectionUrl = "modbus:serial:///dev/ttys003";
         } else {
             System.out.println("Using tcp");
-            connectionUrl = "modbus:tcp://10.10.64.40";
+            connectionUrl = "modbus:tcp://10.10.64.10";
         }
         try (PlcConnection plcConnection = new PlcDriverManager().getConnection(connectionUrl)) {
             System.out.println("PlcConnection " + plcConnection);
 
             PlcReader reader = plcConnection.getReader().orElseThrow(() -> new RuntimeException("No Reader found"));
 
-            Address address = plcConnection.parseAddress("0/0");
+            Address address = plcConnection.parseAddress("readcoils:1/0");
             CompletableFuture<TypeSafePlcReadResponse<Integer>> response = reader
                 .read(new TypeSafePlcReadRequest<>(Integer.class, address));
             TypeSafePlcReadResponse<Integer> readResponse = response.get();
diff --git a/plc4j/protocols/modbus/src/test/resources/logback.xml b/plc4j/protocols/modbus/src/test/resources/logback.xml
index dd243bd..9f49628 100644
--- a/plc4j/protocols/modbus/src/test/resources/logback.xml
+++ b/plc4j/protocols/modbus/src/test/resources/logback.xml
@@ -1,22 +1,22 @@
 <?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
 
-  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
 
-      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.
-
--->
+  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.
+  -->
 <configuration xmlns="http://ch.qos.logback/xml/ns/logback"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="