Hello everyone!
I am working on the implementation of S7 protocol communication between plc and openems component. For that I added two dependencies into cnf/pom.xml:
<!-- S7 -->
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-api</artifactId>
<version>0.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-driver-s7</artifactId>
<version>0.10.0</version>
<scope>runtime</scope>
</dependency>
and added two bundles in my bnd.bnd file:
-buildpath: \
${buildpath},\
...
org.apache.plc4x.plc4j-api,\
org.apache.plc4x.plc4j-driver-s7
-testpath: \
${testpath}
Also after resolving EdgeApp.bndrun org.apache.plc4x.plc4j-api was added to EdgeApp.bndrun -runbundles: section automatically. But when I am trying to establish connection I receive “unable to find driver for protocol ‘s7’” error:
he.plc4x.java.PlcDriverManager] Instantiating new PLC Driver Manager with class loader jdk.internal.loader.ClassLoaders$AppClassLoader@42110406
2023-10-03T11:29:15,309 [32b46a2)] INFO [he.plc4x.java.PlcDriverManager] Registering available drivers...
org.apache.plc4x.java.api.exceptions.PlcConnectionException: Unable to find driver for protocol 's7'
at org.apache.plc4x.java.PlcDriverManager.getDriver(PlcDriverManager.java:124)
at org.apache.plc4x.java.PlcDriverManager.getDriverForUrl(PlcDriverManager.java:139)
at org.apache.plc4x.java.PlcDriverManager.getConnection(PlcDriverManager.java:76)
at io.openems.edge.ess.veloce.s7.S7ReadHelper.connect(S7ReadHelper.java:53)
at io.openems.edge.ess.veloce.s7.S7ReadHelper.<init>(S7ReadHelper.java:45)
at io.openems.edge.ess.veloce.s7.S7ReadWorker.<init>(S7ReadWorker.java:23)
at io.openems.edge.ess.veloce.core.CoreVeloceImpl.activate(CoreVeloceImpl.java:60)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
The problem is that Drivers were not activated. When I am adding org.apache.plc4x.plc4j-driver-s7 bundle manually to EdgeApp.bndrun (or just creating object using the second dependency:
import org.apache.plc4x.java.s7.readwrite.S7Driver;
S7Driver driver = new S7Driver();
in my component), and trying to resolve EdgeApp.bndrun, then I receive an error:
Resolution failed. Capabilities satisfying the following requirements could not be found:
[<<INITIAL>>]
⇒ osgi.identity: (osgi.identity=io.openems.edge.ess.veloce)
⇒ [io.openems.edge.ess.veloce version=1.0.0.202310030815]
⇒ osgi.wiring.package: (&(osgi.wiring.package=org.apache.plc4x.java.s7.readwrite)(version>=0.10.0)(!(version>=1.0.0)))
⇒ [org.apache.plc4x.plc4j-driver-s7 version=0.10.0]
⇒ osgi.wiring.package: (osgi.wiring.package=org.apache.plc4x.java.osgi)
[osgi.cmpn version=7.0.0.201802012110]
⇒ osgi.unresolvable: (&(must.not.resolve=*)(!(must.not.resolve=*)))
[ch.qos.logback.classic version=1.2.3]
⇒ osgi.wiring.package: (&(osgi.wiring.package=ch.qos.logback.core.util)(version>=1.2.0)(!(version>=2.0.0)))
[org.slf4j.api version=2.0.6]
⇒ osgi.extender: (&(osgi.extender=osgi.serviceloader.processor)(version>=1.0.0)(!(version>=2.0.0)))
[slf4j.api version=2.0.5]
⇒ osgi.extender: (&(osgi.extender=osgi.serviceloader.processor)(version>=1.0.0)(!(version>=2.0.0)))
It looks like there’s a conflict in slf4j version used by the plc4x libraries (MANIFEST.MF Import-Package: …,org.slf4j;version=“[2.0,3)”) and slf4j version used in openems project, so I tried to exclude this transitive dependency in the cnf/pom.xml
<dependency>
<groupId>org.apache.plc4x</groupId>
<artifactId>plc4j-driver-s7</artifactId>
<version>0.10.0</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
but it didn’t fix the issue.
Moreover, when I tried to downgrade versions of the plc4x libraries to those ones which use slf4j version (0.7.0 version, MANIFEST.MF Import-Packages: …org.slf4j;version=“[1.7,2)” in the rank from the error ( osgi.extender: (&(osgi.extender=osgi.serviceloader.processor)(version>=1.0.0)(!(version>=2.0.0)))), problem remains the same.
I’m not an OSGI expert, so any help in solving this problem would be greatly appreciated.
Thanks in advance!
Best regards,
Mykola Skydan