Skip to content
Steve O'Hara edited this page Mar 28, 2016 · 3 revisions

Overview

These WIKI pages are provided as a way to back up the information available from the originating jamod library and as a quick start to using j2mod.

For the impatient

Here is a simple way to read a coil;

private static final ModbusLogger logger = ModbusLogger.getLogger(Test.class);

public static void main(String[] args) {
    protected static ModbusTCPMaster master;
    try {
        master = new ModbusTCPMaster("1.2.3.4");
        master.connect();
        logger.info("Read coil 1 status [1.2.3.4:502] - %b", master.readCoils(0, 1).getBit(0));
    }
    catch (Exception e) {
        logger.error("Cannot initialise tests - %s", e.getMessage());
    }
    finally {
        if (master != null) {
            master.disconnect();
        }
    }
}
Clone this wiki locally