Package com.serotonin.modbus4j

Examples of com.serotonin.modbus4j.ModbusMaster


        config.setProperty("tcpport", String.valueOf(502));




        ModbusMaster master = ModbusMasterGateway.getInstance(config);
        try {
            master.init();
            NumericLocator bl = new NumericLocator(1, RegisterRange.HOLDING_REGISTER, 266, DataType.TWO_BYTE_INT_UNSIGNED);
            System.out.println("readed value: " + master.getValue(bl));
            master.setValue(bl, 1);

        } catch (ModbusTransportException ex) {
            System.out.println("error1: " + ex.toString());
        } catch (ErrorResponseException ex) {
            System.out.println("error2: " + ex.toString());
        } catch (ModbusInitException ex) {
            System.out.println("error3:" + ex.toString());
        } finally {
            master.destroy();
        }

    }
View Full Code Here


//        config.setProperty("port", "/dev/ttyUSB10");
//        config.setProperty("baudrate",String.valueOf(19200));
//        config.setProperty("data-bits",String.valueOf(SerialPort.DATABITS_8));
//        config.setProperty("parity", String.valueOf(SerialPort.PARITY_EVEN));
//        config.setProperty("stop-bits", String.valueOf(SerialPort.STOPBITS_1));
        ModbusMaster master = ModbusMasterGateway.getInstance();
        try {
            master.init();
            NumericLocator bl = new NumericLocator(1, RegisterRange.HOLDING_REGISTER, 266, DataType.TWO_BYTE_INT_UNSIGNED);
            System.out.println(master.getValue(bl));

        } catch (ModbusTransportException ex) {
            System.out.println(ex.toString());
        } catch (ErrorResponseException ex) {
            System.out.println(ex.toString());
        } catch (ModbusInitException ex) {
            System.out.println(ex.toString());
        } finally {
            master.destroy();
        }
        assertEquals(1, 1);
        // sudo socat pty,link=/dev/ttyUSB10,waitslave,ignoreeof tcp:192.168.1.5:54321 &
        // chown user /dev/ttyUSB10
        // sudo socat tcp-l:54321,reuseaddr,fork file:/dev/ttyUSB0,nonblock,waitlock=/var/run/ttyUSB0.lock
View Full Code Here

    /**
     * Test of write method.
     */
    @Test
    public void testWrite() {
        ModbusMaster master = ModbusMasterGateway.getInstance();
        int value1 = 235;
        int value = 0;
        try {
            master.init();
            //master.setValue(1,768,2,true);
            NumericLocator bl = new NumericLocator(1, RegisterRange.HOLDING_REGISTER, 771, DataType.TWO_BYTE_INT_UNSIGNED);
            master.setValue(bl, value1);
            value = (Integer) master.getValue(bl);

        } catch (ModbusTransportException ex) {
            System.out.println(ex.toString());
        } catch (ErrorResponseException ex) {
            System.out.println(ex.toString());
        } catch (ModbusInitException ex) {
            System.out.println(ex.toString());
        } finally {
            master.destroy();
        }
        assertEquals(value, value1);


    }
View Full Code Here

TOP

Related Classes of com.serotonin.modbus4j.ModbusMaster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.