Hi Etienne,

fort he sake of easiness... could you do a short test if it works, when you 
Replace the Content of PLC4XConsumer.java with the following:

```
/*
 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.camel;

import org.apache.camel.*;
import org.apache.camel.spi.ExceptionHandler;
import org.apache.camel.support.LoggingExceptionHandler;
import org.apache.camel.support.ServiceSupport;
import org.apache.camel.util.AsyncProcessorConverterHelper;
import org.apache.plc4x.java.api.PlcConnection;
import org.apache.plc4x.java.api.exceptions.PlcException;
import org.apache.plc4x.java.api.messages.PlcSubscriptionResponse;
import org.apache.plc4x.java.api.messages.PlcUnsubscriptionRequest;
import org.apache.plc4x.java.api.messages.PlcUnsubscriptionResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.concurrent.*;

public class Plc4XConsumer extends ServiceSupport implements Consumer {
    private static final Logger LOGGER = 
LoggerFactory.getLogger(Plc4XConsumer.class);

    private Plc4XEndpoint endpoint;
    private AsyncProcessor processor;
    private ExceptionHandler exceptionHandler;
    private PlcConnection plcConnection;
    private String fieldQuery;
    private Class<?> dataType;
    private PlcSubscriptionResponse subscriptionResponse;

    private ScheduledExecutorService executorService = 
Executors.newSingleThreadScheduledExecutor();
    private ScheduledFuture<?> future;

    public Plc4XConsumer(Plc4XEndpoint endpoint, Processor processor) throws 
PlcException {
        this.endpoint = endpoint;
        this.dataType = endpoint.getDataType();
        this.processor = AsyncProcessorConverterHelper.convert(processor);
        this.exceptionHandler = new 
LoggingExceptionHandler(endpoint.getCamelContext(), getClass());
        String plc4xURI = endpoint.getEndpointUri().replaceFirst("plc4x:/?/?", 
"");
        this.plcConnection = 
endpoint.getPlcDriverManager().getConnection(plc4xURI);
        this.fieldQuery = endpoint.getAddress();
    }

    @Override
    public String toString() {
        return "Plc4XConsumer[" + endpoint + "]";
    }

    @Override
    public Endpoint getEndpoint() {
        return endpoint;
    }

    public ExceptionHandler getExceptionHandler() {
        return exceptionHandler;
    }

    public void setExceptionHandler(ExceptionHandler exceptionHandler) {
        this.exceptionHandler = exceptionHandler;
    }

    @Override
    protected void doStart() throws InterruptedException, ExecutionException {
        // TODO: Is it correct to only support one field?
        future = executorService.schedule(() -> {
            plcConnection.readRequestBuilder()
                .addItem("default", fieldQuery)
                .build()
                .execute()
                .thenAccept(response -> {
                    LOGGER.debug("Received {}", response);
                    try {
                        Exchange exchange = endpoint.createExchange();
                        
exchange.getIn().setBody(unwrapIfSingle(response.getAllObjects("default")));
                        processor.process(exchange);
                    } catch (Exception e) {
                        exceptionHandler.handleException(e);
                    }
                });
        }, 3, TimeUnit.SECONDS);
    }

    @Override
    protected void doStop() throws InterruptedException, ExecutionException, 
TimeoutException {
        // First stop the polling process
        if (future != null) {
            future.cancel(true);
        }
        // TODO: Handle the response ...
        try {
            plcConnection.close();
        } catch (Exception e) {
            LOGGER.error("Error closing connection", e);
        }
    }

    private Object unwrapIfSingle(Collection collection) {
        if (collection.isEmpty()) {
            return null;
        }
        if (collection.size() == 1) {
            return collection.iterator().next();
        }
        return collection;
    }

}
```

Julian


Am 18.02.20, 13:22 schrieb "Julian Feinauer" <[email protected]>:

    Hi Etienne,
    
    oh, sorry, indeed. The Code in the Camel module is right, but does not work 
for Siemens S7.
    Let me try to write you an updated version in another branch ASAP then you 
can check it.
    
    Sorry!
    Julian
    
    Am 18.02.20, 12:56 schrieb "Etienne Robinet" <[email protected]>:
    
        I just cloned the rel/0.6 branch from git, until now I didn't change 
anything.
        Regards,,
        Etienne
        
        On 2020/02/18 11:10:39, Julian Feinauer <[email protected]> 
wrote: 
        > Did you post your code somewhere? I cant find it.. just post it 
somewhere and I will have a look!
        > 
        > Julian
        > 
        > Am 18.02.20, 11:28 schrieb "Etienne Robinet" <[email protected]>:
        > 
        >     Hi Julian,
        >     thanks for the advice, but where should I change the code to 
apply your modification? Is it in the doStart() methode of de PLC4XConsumer?
        >     Regards,
        >     
        >     Etienne
        >     
        >     On 2020/02/18 08:55:22, Julian Feinauer 
<[email protected]> wrote: 
        >     > Hi Etienne,
        >     > 
        >     > thank you for your investigation.
        >     > I just locked at your log and it seems that connection works 
fine and some messages are exchanged BUT you try to subscribe to a Value which 
is currently not supported.
        >     > Try to just use the "readRequestBuilder().addItem("", 
"").build().execute().get()" approach to send a single request, that should 
work.
        >     > 
        >     > Best
        >     > Julian
        >     > 
        >     > Am 18.02.20, 09:39 schrieb "Etienne Robinet" 
<[email protected]>:
        >     > 
        >     >     Hello,
        >     >     with the help of some colleague we managed to find how to 
fix the issue so that the DriverManager can find the actual s7 protocol.
        >     >     All I had to do is to create a maven project 
(karaf-blueprint) archetype and do as follow:
        >     >     
        >     >     1. Inside the pom, add the S7PlcDriver under "imports"
        >     >     2. create a service under 
main/java/resources/META-INF/services/xxx.xxx.PlcDriver containing the 
implementation (S7PlcDriver) and license
        >     >     3. Create a simple XML blueprint (with a real address this 
time connected to a real PLC)
        >     >     <blueprint 
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"; default-activation="lazy">
        >     >     
        >     >         <camelContext id="PLC-Context" 
xmlns="http://camel.apache.org/schema/blueprint"; streamCache="true">
        >     >     
        >     >     
        >     >             <route id="Route1">
        >     >     
        >     >                 <from uri="plc4x:s7://192.168.178.10/1/1"/>
        >     >                 <log message=" Sending ${body}" 
loggingLevel="INFO" />
        >     >                 <to uri="mock:test?retainLast=10" />
        >     >     
        >     >             </route>
        >     >     
        >     >         </camelContext>
        >     >     
        >     >     </blueprint>
        >     >     
        >     >     So now I have the next issue, I can see from the log that a 
connection is established but it tells me that the connection doesn't support 
connection. Am I missing a parameter or what could be the issue?
        >     >     
        >     >     Here the log:
        >     >     
        >     >     https://i.imgur.com/KgWz8DF.png
        >     >     
        >     >     On 2020/02/17 12:11:56, Christofer Dutz 
<[email protected]> wrote: 
        >     >     > Hi all,
        >     >     > 
        >     >     > having a more detailed look at the log-trace, it seems 
the DriverManager isn't able to find the S7 driver at all ...
        >     >     > But I guess if it even was available, as Cesar pointed 
out, the field address is that of the mock driver and not of the S7 so this 
will not work.
        >     >     > Also are you connecting to localhost, which is also 
probably not what you want. Unless you are running a S7 simulator on your 
machine.
        >     >     > 
        >     >     > Depending of if you're using a released version of the s7 
driver the connection URL is correct, however if you switch to the new S7 
driver it would look like this:  s7://{ip or host}
        >     >     > Not the "/1/1" are now missing.
        >     >     > 
        >     >     > Chris
        >     >     > 
        >     >     > 
        >     >     > 
        >     >     > 
        >     >     > Am 17.02.20, 13:04 schrieb "Cesar Garcia" 
<[email protected]>:
        >     >     > 
        >     >     >     Hi,
        >     >     >     
        >     >     >     The PLC address does not look correct, can you 
confirm that it really
        >     >     >     points to a real PLC or an S7 simulator?
        >     >     >     
        >     >     >     <from uri="plc4x:s7:localhost/1/1"/>
        >     >     >     
        >     >     >     Best regards,
        >     >     >     
        >     >     >     
        >     >     >     El vie., 14 feb. 2020 a las 18:34, Etienne Robinet 
(<[email protected]>)
        >     >     >     escribió:
        >     >     >     
        >     >     >     > Hello everyone,
        >     >     >     > I've spent some days trying to figure out how to 
make PLC4X work inside a
        >     >     >     > karaf container in combination with camel 
blueprints for routing.
        >     >     >     > I've downloaded the latest release (0.5.0) and 
built it with maven. I then
        >     >     >     > installed the driver-s7-feature and 
plc4j-apache-camel bundle into my
        >     >     >     > container and got following bundles running:
        >     >     >     >
        >     >     >     > >PLC4J: API
        >     >     >     > >PLC4J: Driver: S7
        >     >     >     > >PLC4J: Protocol: Driver-Base: Base
        >     >     >     > >PLC4J: Protocol: Driver-Base: TCP
        >     >     >     > >PLC4J: Protocol: ISO on TCP
        >     >     >     > >PLC4J: Protocol: ISO TP
        >     >     >     > >PLC4J: Protocol: S7
        >     >     >     > >PLC4j: Utils: Driver Base: Java
        >     >     >     > >PLC4J: Integrations: Apache Camel
        >     >     >     >
        >     >     >     > After trying a simple route with this consumer 
component:
        >     >     >     > <from uri="plc4x:s7:localhost/1/1"/> (the address 
is for testing purpose)
        >     >     >     > I get the following error:
        >     >     >     > Error occurred during starting CamelContext: 
PLC-Context
        >     >     >     > org.apache.camel.FailedToCreateRouteException: 
Failed to create route
        >     >     >     > Route1: 
Route(Route1)[[From[plc4x:s7:localhost/1/1]] -> [To[mock:tes...
        >     >     >     > because of Unable to find driver for protocol 's7'
        >     >     >     >
        >     >     >     > I've tested numerous version of PLC4X and got the 
same results, so I think
        >     >     >     > I might be close to fix it!
        >     >     >     > Any help would be appreciated!
        >     >     >     >
        >     >     >     > Here the full log
        >     >     >     >
        >     >     >     > 16:30:45.578 INFO [Blueprint Event Dispatcher: 1] 
Attempting to start
        >     >     >     > CamelContext: PLC-Context
        >     >     >     > 16:30:45.579 INFO [Blueprint Event Dispatcher: 1] 
Apache Camel 2.24.2
        >     >     >     > (CamelContext: PLC-Context) is starting
        >     >     >     > 16:30:45.580 INFO [Blueprint Event Dispatcher: 1] 
StreamCaching is enabled
        >     >     >     > on CamelContext: PLC-Context
        >     >     >     > 16:30:45.580 INFO [Blueprint Event Dispatcher: 1] 
JMX is enabled
        >     >     >     > 16:30:45.600 INFO [Blueprint Event Dispatcher: 1] 
Instantiating new PLC
        >     >     >     > Driver Manager with class loader
        >     >     >     > BundleDelegatingClassLoader(plc4j-route.xml [67])
        >     >     >     > 16:30:45.600 INFO [Blueprint Event Dispatcher: 1] 
Registering available
        >     >     >     > drivers...
        >     >     >     > 16:30:45.601 TRACE [Blueprint Event Dispatcher: 1] 
FindResource:
        >     >     >     > 
META-INF/services/org.apache.plc4x.java.spi.PlcDriver
        >     >     >     > 16:30:45.627 INFO [Blueprint Event Dispatcher: 1] 
StreamCaching in use
        >     >     >     > with spool directory:
        >     >     >     > 
C:\karaf\bin\..\data\tmp\camel\camel-tmp-00f849ac-0ccf-4b12-822d-dda62267eb6c
        >     >     >     > and rules: [Spool > 128K body size]
        >     >     >     > 16:30:45.629 INFO [Blueprint Event Dispatcher: 1] 
Apache Camel 2.24.2
        >     >     >     > (CamelContext: PLC-Context) is shutting down
        >     >     >     > 16:30:45.639 INFO [Blueprint Event Dispatcher: 1] 
Apache Camel 2.24.2
        >     >     >     > (CamelContext: PLC-Context) uptime 0.060 seconds
        >     >     >     > 16:30:45.640 INFO [Blueprint Event Dispatcher: 1] 
Apache Camel 2.24.2
        >     >     >     > (CamelContext: PLC-Context) is shutdown in 0.011 
seconds
        >     >     >     > 16:30:45.640 WARN [Blueprint Event Dispatcher: 1] 
Changing Camel state for
        >     >     >     > bundle 67 to Failure
        >     >     >     > 16:30:45.641 ERROR [Blueprint Event Dispatcher: 1] 
Error occurred during
        >     >     >     > starting CamelContext: PLC-Context
        >     >     >     > org.apache.camel.FailedToCreateRouteException: 
Failed to create route
        >     >     >     > Route1: 
Route(Route1)[[From[plc4x:s7:localhost/1/1]] -> [To[mock:tes...
        >     >     >     > because of Unable to find driver for protocol 's7'
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.RouteService.warmUp(RouteService.java:147)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3954)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3861)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3647)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3488)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext$4.call(DefaultCamelContext.java:3247)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext$4.call(DefaultCamelContext.java:3243)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3266)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3243)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:72)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3159)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.blueprint.BlueprintCamelContext.start(BlueprintCamelContext.java:255)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.blueprint.BlueprintCamelContext.maybeStart(BlueprintCamelContext.java:297)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.blueprint.BlueprintCamelContext.blueprintEvent(BlueprintCamelContext.java:188)
        >     >     >     > [!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:190)
        >     >     >     > [!/:1.10.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.aries.blueprint.container.BlueprintEventDispatcher$3.call(BlueprintEventDispatcher.java:188)
        >     >     >     > [!/:1.10.2]
        >     >     >     >         at 
java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        >     >     >     >         at
        >     >     >     > 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        >     >     >     > [?:?]
        >     >     >     >         at 
java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        >     >     >     >         at
        >     >     >     > 
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
        >     >     >     > [?:?]
        >     >     >     >         at 
java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        >     >     >     >         at
        >     >     >     > 
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        >     >     >     > [?:?]
        >     >     >     >         at
        >     >     >     > 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        >     >     >     > [?:?]
        >     >     >     >         at
        >     >     >     > 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        >     >     >     > [?:?]
        >     >     >     >         at java.lang.Thread.run(Thread.java:834) 
[?:?]
        >     >     >     > Caused by: 
org.apache.plc4x.java.api.exceptions.PlcConnectionException:
        >     >     >     > Unable to find driver for protocol 's7'
        >     >     >     >         at
        >     >     >     > 
org.apache.plc4x.java.PlcDriverManager.getDriver(PlcDriverManager.java:98)
        >     >     >     > ~[?:?]
        >     >     >     >         at
        >     >     >     > 
org.apache.plc4x.java.PlcDriverManager.getConnection(PlcDriverManager.java:71)
        >     >     >     > ~[?:?]
        >     >     >     >         at
        >     >     >     > 
org.apache.plc4x.camel.Plc4XConsumer.<init>(Plc4XConsumer.java:57) ~[?:?]
        >     >     >     >         at
        >     >     >     > 
org.apache.plc4x.camel.Plc4XEndpoint.createConsumer(Plc4XEndpoint.java:72)
        >     >     >     > ~[?:?]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:69)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:107)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.RouteService.doWarmUp(RouteService.java:172)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         at
        >     >     >     > 
org.apache.camel.impl.RouteService.warmUp(RouteService.java:145)
        >     >     >     > ~[!/:2.24.2]
        >     >     >     >         ... 24 more
        >     >     >     >
        >     >     >     >
        >     >     >     >
        >     >     >     
        >     >     >     -- 
        >     >     >     *CEOS Automatización, C.A.*
        >     >     >     *GALPON SERVICIO INDUSTRIALES Y NAVALES FA, C.A.,*
        >     >     >     *PISO 1, OFICINA 2, AV. RAUL LEONI, SECTOR 
GUAMACHITO,*
        >     >     >     
        >     >     >     *FRENTE A LA ASOCIACION DE GANADEROS,BARCELONA,EDO. 
ANZOATEGUI*
        >     >     >     *Ing. César García*
        >     >     >     *Cel: 0416-681.03.99*
        >     >     >     
        >     >     >     *Cel: 0414-760.98.95*
        >     >     >     
        >     >     >     *Hotline Técnica SIEMENS: 0800 1005080*
        >     >     >     
        >     >     >     *Email: [email protected]
        >     >     >     <[email protected]>*
        >     >     >     
        >     >     > 
        >     >     > 
        >     >     
        >     > 
        >     > 
        >     
        > 
        > 
        
    
    

Reply via email to