Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.
[SOLVED] Modbus TCP Master error
-
Hello everybody,
I want to use Modbus4J rather than Jamod. I use Modbus4J version 3.0.0.
I'm trying to test the smallest possible example :
package testModbus; import com.serotonin.modbus4j.ModbusFactory; import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.code.DataType; import com.serotonin.modbus4j.ip.IpParameters; import com.serotonin.modbus4j.locator.BaseLocator; public class Main { public static void main(String[] args) throws Exception { IpParameters params = new IpParameters(); params.setHost("localhost"); params.setPort(502); ModbusFactory masterF = new ModbusFactory(); ModbusMaster master = masterF.createTcpMaster(params, false); master.init(); System.out.println(master.testSlaveNode(5)); // Define the point locator. BaseLocator<Number> loc = BaseLocator.holdingRegister(1, 0, DataType.TWO_BYTE_INT_UNSIGNED); // Set the point value master.setValue(loc, 1800); // Get the point value System.out.println(master.getValue(loc)); } }
I have this error when I tryto execute the Java program :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at com.serotonin.modbus4j.ip.tcp.TcpMaster.<init>(TcpMaster.java:57) at com.serotonin.modbus4j.ModbusFactory.createTcpMaster(ModbusFactory.java:69) at testModbus.Main.main(Main.java:18) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more
With another bigger test, the error is the same.
I don't know where is the real problem with the code, or configuration, ... ?
Thanks you in advance for the help :-)
Aurélien, France -
Hi Aurelien,
That looks to me like you need a log4j.xml file somewhere on your classpath at runtime. You can just add the "-cp /path/to/log4j.xml" to the invocation of your program.
-
Thanks ! :-D
I have found the solution.
It's necessary to add commons logging library.
Download :
http://commons.apache.org/proper/commons-logging/download_logging.cgi -
Nice! Thanks for sharing the solution!