• A
    Aurelien

    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

    posted in Modbus4J general discussion read more
  • A
    Aurelien

    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

    posted in Modbus4J general discussion read more