Hey Palaniswamy,
Welcome on mailing lists.

For OSGi to get whole thing working there are few things necessary.
Problem which you face is related to visibility of resources between
isolated class-loaders. Normally with "flat classpath" you get in
regular web or standalone applications scanning of classpath can
enumerate all resources. That's not a case with OSGi.
Driver manager in current form can't work without further enhancements
which will expose META-INF/services entries. There were some high level
attempts to solve that using Aries Spifly, yet I never really got it
working.

A proper way for most of situations within OSGi is to rely on services.
This is reason why we have activators (called only under OSGi) which can
replace META-INF/services lookups and work dynamically. Just like whole
environment does.
You can use OSGi services registered by driver itself. It will let you
calling getConnection method directly. Syntax for URI is the same as for
driver manager.

You might need some further adjustments in order to get transport stuff
which does another META-INF lookup for Transport SPI.

Best,
Łukasz


On 09.06.2021 21:33, Palaniswamy, Lakshimi Narayanan (ETI) wrote:
> Hello Community,
> 
> I am currently working with an OSGi framework based Open-Source Energy 
> Management System OpenEMS (https://openems.io/). As a part of the development 
> we wanted to integrate a Beckhoff PLC, which offers a ADS bridge-Modbus TCP 
> Protocol for communication. Although I found a DLL offered by Beckhoff 
> (https://infosys.beckhoff.com/index.php?content=../content/1031/tcadscommon/html/note.htm&id=),
>  it did not fit perfectly for the case of OpenEMS due to its OSGi Framework. 
> Thankfully I found the PLC4x adaptor. It really solves half the problem for 
> me. I would also like to mention I am quiet new to OSGi as well as JAVA to 
> begin with and am trying to figure things out on the go.
> 
> Now to my question. I wanted to use the PLC4j/ADS drivers and functionalities 
> in my code. I started with the basic setup mentioned in the "JAVA Getting 
> Started" page of the PLC4x. When I used the following code: 
> PLCDriverManager().getConnection("ads:tcp://xxx.xx.x.xx:502") to establish 
> the connection. I get an error saying "Unable to find driver for protocol 
> 'ads'". It was weird because if had added all (I hope so) the dependencies 
> required as follows:
> 
> <dependency>
>         <groupId>org.apache.plc4x</groupId>
>         <artifactId>plc4j-api</artifactId>
>         <version>0.8.0</version>
> </dependency>
> 
> <dependency>
> 
>         <groupId>org.apache.plc4x</groupId>
> 
>         <artifactId>plc4j-driver-ads</artifactId>
> 
>         <version>0.8.0</version>
> 
>         <scope>runtime</scope>
> 
> </dependency>
> 
> Later I found out that, for OSGi framework, the Drivers are required to be 
> activated 
> (https://github.com/apache/plc4x/blob/develop/plc4j/osgi/src/main/java/org/apache/plc4x/java/osgi/DriverActivator.java
>  ), so that it creates a bundle. But now I am really not sure how this is 
> done. Could someone please help me out with this. If there are any tutorials 
> or examples for such a case, please share it.
> 
> As I said before, we intend in integrating a Beckhoff PLC running TwinCAT 
> ADS, into a JAVA OSGi based framework, which would be communicating with each 
> other over Modbus TCP protocol.
> 
> Viele Grüße
> Laksh
> 
> 

Reply via email to