[Modbus] Specify SlaveID
Hi all, I have a general question regarding the Modbus driver. Is it possible to specify a specific SlaveID in the connection string (or elsewhere)? As far as I have experienced, the slave with ID 0 is always used for connection. Cheers, Tim
RE: [Modbus] Querying Values from Holding Register
Hi, This was a problem with my Maven configuration. I'm sorry, I'm very inexperienced with Maven. Anyway, reading values from the holding register now works fine with drivers of version 0.7.0. Best Tim -Original Message- From: Christofer Dutz Sent: Montag, 1. Juni 2020 23:27 To: udeho ; dev@plc4x.apache.org Subject: Re: [Modbus] Querying Values from Holding Register Hi, Are you perhaps mixing different versions? The api and driver versions should match. Chris Von: udeho Gesendet: Montag, 1. Juni 2020 14:58 An: dev@plc4x.apache.org Betreff: RE: [Modbus] Querying Values from Holding Register Hi, I've just tried to do the same as below with the newly released 0.7.0 version. Unfortunately, I get the following errors: [main] INFO org.apache.plc4x.java.PlcDriverManager - Instantiating new PLC Driver Manager with class loader jdk.internal.loader.ClassLoaders$AppClassLoader@129a8472 [main] INFO org.apache.plc4x.java.PlcDriverManager - Registering available drivers... Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/plc4x/java/spi/connection/GeneratedDriverBase at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(Unknown Source) at java.base/java.security.SecureClassLoader.defineClass(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Unknown Source) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(Unknown Source) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(Unknown Source) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(Unknown Source) at java.base/java.util.ServiceLoader$2.hasNext(Unknown Source) at java.base/java.util.ServiceLoader$3.hasNext(Unknown Source) at org.apache.plc4x.java.PlcDriverManager.(PlcDriverManager.java:53) at org.apache.plc4x.java.PlcDriverManager.(PlcDriverManager.java:44) at modbus.playground.main(playground.java:108) Caused by: java.lang.ClassNotFoundException: org.apache.plc4x.java.spi.connection.GeneratedDriverBase at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ... 19 more I added the new version as a dependency in Maven, but in the pom.xml is also stated "Missing artifact org.apache.plc4x:plc4j-driver-modbus:jar:0.7.0". Used dependency in maven: org.apache.plc4x plc4j-driver-modbus 0.7.0 Best Tim -Original Message- From: Christofer Dutz Sent: Mittwoch, 20. Mai 2020 11:28 To: dev@plc4x.apache.org Subject: Re: [Modbus] Querying Values from Holding Register Hi Tim, I guess you are using one of the "old generation" drivers (As you say it's working and the address seems to imply that). Perhaps you should either try the version 0.8.0-SNAPSHOT or wait for 2 more days till we release the 0.7.0 version. In the 0.7.0 version we have completely deleted all existing drivers and replaced them by new ones. While at it I took the liberty of making the Modbus a little more robust. So it would be great if you could give us feedback if your problem goes away magically when updating to these driver versions. Chris Am 20.05.20, 10:24 schrieb "udeho" : Hi all, I have tried to query values from the holding register of a simulated modbus device and process them as integer using the following code: // read integer / holding register PlcDriverManager driverManager = new PlcDriverManager(); String conString = "modbus:tcp://localhost"; PlcConnection plcCon = driverManager.getConnection(conString); PlcReadRequest.Builder builder = plcCon.readRequestBuilder(); builder.addItem("value", "readholdingregisters:1"); PlcReadRequest readRequest = builder.build(); PlcReadResponse resp = readRequest.execute().get(); Thi
RE: [Modbus] Querying Values from Holding Register
Hi, I've just tried to do the same as below with the newly released 0.7.0 version. Unfortunately, I get the following errors: [main] INFO org.apache.plc4x.java.PlcDriverManager - Instantiating new PLC Driver Manager with class loader jdk.internal.loader.ClassLoaders$AppClassLoader@129a8472 [main] INFO org.apache.plc4x.java.PlcDriverManager - Registering available drivers... Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/plc4x/java/spi/connection/GeneratedDriverBase at java.base/java.lang.ClassLoader.defineClass1(Native Method) at java.base/java.lang.ClassLoader.defineClass(Unknown Source) at java.base/java.security.SecureClassLoader.defineClass(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(Unknown Source) at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) at java.base/java.lang.Class.forName0(Native Method) at java.base/java.lang.Class.forName(Unknown Source) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.nextProviderClass(Unknown Source) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(Unknown Source) at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(Unknown Source) at java.base/java.util.ServiceLoader$2.hasNext(Unknown Source) at java.base/java.util.ServiceLoader$3.hasNext(Unknown Source) at org.apache.plc4x.java.PlcDriverManager.(PlcDriverManager.java:53) at org.apache.plc4x.java.PlcDriverManager.(PlcDriverManager.java:44) at modbus.playground.main(playground.java:108) Caused by: java.lang.ClassNotFoundException: org.apache.plc4x.java.spi.connection.GeneratedDriverBase at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ... 19 more I added the new version as a dependency in Maven, but in the pom.xml is also stated "Missing artifact org.apache.plc4x:plc4j-driver-modbus:jar:0.7.0". Used dependency in maven: org.apache.plc4x plc4j-driver-modbus 0.7.0 Best Tim -Original Message- From: Christofer Dutz Sent: Mittwoch, 20. Mai 2020 11:28 To: dev@plc4x.apache.org Subject: Re: [Modbus] Querying Values from Holding Register Hi Tim, I guess you are using one of the "old generation" drivers (As you say it's working and the address seems to imply that). Perhaps you should either try the version 0.8.0-SNAPSHOT or wait for 2 more days till we release the 0.7.0 version. In the 0.7.0 version we have completely deleted all existing drivers and replaced them by new ones. While at it I took the liberty of making the Modbus a little more robust. So it would be great if you could give us feedback if your problem goes away magically when updating to these driver versions. Chris Am 20.05.20, 10:24 schrieb "udeho" : Hi all, I have tried to query values from the holding register of a simulated modbus device and process them as integer using the following code: // read integer / holding register PlcDriverManager driverManager = new PlcDriverManager(); String conString = "modbus:tcp://localhost"; PlcConnection plcCon = driverManager.getConnection(conString); PlcReadRequest.Builder builder = plcCon.readRequestBuilder(); builder.addItem("value", "readholdingregisters:1"); PlcReadRequest readRequest = builder.build(); PlcReadResponse resp = readRequest.execute().get(); This runs well, but when I try to handle the result as integer (using resp.getInteger("value")) I always get null as result no matter what's in the register. For Boolean values in the coil this works without any problem (using getBoolean() of course). Another approach I tried is using the getAllByteArrays("value"); command, but I haven't found a way to get the returned collection of byte arrays into integers. Can you give me an indication of what my problem may be or what I'm doing wrong? Thank you very much in advance! Best Tim
RE: [Modbus] Querying Values from Holding Register
Hi Chris, yes, I use the 0.6.0 version. Great, I will try to do it again when the new version is available and let you know whether it works. Thank you very much! Best Tim -Original Message- From: Christofer Dutz Sent: Mittwoch, 20. Mai 2020 11:28 To: dev@plc4x.apache.org Subject: Re: [Modbus] Querying Values from Holding Register Hi Tim, I guess you are using one of the "old generation" drivers (As you say it's working and the address seems to imply that). Perhaps you should either try the version 0.8.0-SNAPSHOT or wait for 2 more days till we release the 0.7.0 version. In the 0.7.0 version we have completely deleted all existing drivers and replaced them by new ones. While at it I took the liberty of making the Modbus a little more robust. So it would be great if you could give us feedback if your problem goes away magically when updating to these driver versions. Chris Am 20.05.20, 10:24 schrieb "udeho" : Hi all, I have tried to query values from the holding register of a simulated modbus device and process them as integer using the following code: // read integer / holding register PlcDriverManager driverManager = new PlcDriverManager(); String conString = "modbus:tcp://localhost"; PlcConnection plcCon = driverManager.getConnection(conString); PlcReadRequest.Builder builder = plcCon.readRequestBuilder(); builder.addItem("value", "readholdingregisters:1"); PlcReadRequest readRequest = builder.build(); PlcReadResponse resp = readRequest.execute().get(); This runs well, but when I try to handle the result as integer (using resp.getInteger("value")) I always get null as result no matter what's in the register. For Boolean values in the coil this works without any problem (using getBoolean() of course). Another approach I tried is using the getAllByteArrays("value"); command, but I haven't found a way to get the returned collection of byte arrays into integers. Can you give me an indication of what my problem may be or what I'm doing wrong? Thank you very much in advance! Best Tim
[Modbus] Querying Values from Holding Register
Hi all, I have tried to query values from the holding register of a simulated modbus device and process them as integer using the following code: // read integer / holding register PlcDriverManager driverManager = new PlcDriverManager(); String conString = "modbus:tcp://localhost"; PlcConnection plcCon = driverManager.getConnection(conString); PlcReadRequest.Builder builder = plcCon.readRequestBuilder(); builder.addItem("value", "readholdingregisters:1"); PlcReadRequest readRequest = builder.build(); PlcReadResponse resp = readRequest.execute().get(); This runs well, but when I try to handle the result as integer (using resp.getInteger("value")) I always get null as result no matter what's in the register. For Boolean values in the coil this works without any problem (using getBoolean() of course). Another approach I tried is using the getAllByteArrays("value"); command, but I haven't found a way to get the returned collection of byte arrays into integers. Can you give me an indication of what my problem may be or what I'm doing wrong? Thank you very much in advance! Best Tim
PlcConnectionException
Dear PLC4X-Community, I tried to do my first steps with modbus in PLC4X using the modbus simulator referenced in your getting-started guide. Following your instructions, I executed the following code to establish a connection: public static void main(String [] args) { String conString = "modbus://localhost"; try(PlcConnection plcCon = new PlcDriverManager().getConnection(conString)){ System.out.println("Hello Modbus"); } catch (Exception e) { e.printStackTrace(); } } Unfortunately, I get the following error: org.apache.plc4x.java.api.exceptions.PlcConnectionException: Connection url doesn't match the format 'modbus:{type}//{port|host}' at org.apache.plc4x.java.modbus.ModbusPlcDriver.connect(ModbusPlcDriver.java:69) at org.apache.plc4x.java.PlcDriverManager.getConnection(PlcDriverManager.java:72) at plc4x.playground.main(playground.java:12) Could you please give me a hint what I'm doing wrong or what is missing? As far as I can see, I did it the same way you proposed in your virtual modbus section. Thanks a lot! Best regards Tim