Search in sources :

Example 1 with SimpleDigitalIn

use of net.wimpi.modbus.procimg.SimpleDigitalIn in project openhab1-addons by openhab.

the class ConfigUpdatedTestCase method testConfigUpdated.

@Test
public void testConfigUpdated() throws UnknownHostException, ConfigurationException, BindingConfigParseException {
    // Modbus server ("modbus slave") has two digital inputs
    spi.addDigitalIn(new SimpleDigitalIn(true));
    spi.addDigitalIn(new SimpleDigitalIn(false));
    binding = new ModbusBinding();
    // simulate configuration changes
    for (int i = 0; i < 2; i++) {
        binding.updated(addSlave(newLongPollBindingConfig(), SLAVE_NAME, ModbusBindingProvider.TYPE_DISCRETE, null, 0, 2));
    }
    configureSwitchItemBinding(2, SLAVE_NAME, 0);
    binding.execute();
    // Give the system some time to make the expected connections & requests
    waitForRequests(1);
    if (!serverType.equals(ServerType.UDP)) {
        waitForConnectionsReceived(1);
    }
    verify(eventPublisher, never()).postCommand(null, null);
    verify(eventPublisher, never()).sendCommand(null, null);
    try {
        verify(eventPublisher).postUpdate("Item1", OnOffType.ON);
        verify(eventPublisher).postUpdate("Item2", OnOffType.OFF);
    } catch (AssertionError e) {
        throw new ExpectedFailure();
    }
    verifyNoMoreInteractions(eventPublisher);
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) Test(org.junit.Test)

Example 2 with SimpleDigitalIn

use of net.wimpi.modbus.procimg.SimpleDigitalIn in project openhab1-addons by openhab.

the class SerialSlaveTest method main.

public static void main(String[] args) {
    ModbusSerialListener listener = null;
    SimpleProcessImage spi = new SimpleProcessImage();
    String portname = args[0];
    if (Modbus.debug) {
        System.out.println("jModbus ModbusSerial Slave");
    }
    try {
        // 1. Prepare a process image
        spi = new SimpleProcessImage();
        spi.addDigitalOut(new SimpleDigitalOut(true));
        spi.addDigitalOut(new SimpleDigitalOut(false));
        spi.addDigitalIn(new SimpleDigitalIn(false));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addDigitalIn(new SimpleDigitalIn(false));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addRegister(new SimpleRegister(251));
        spi.addInputRegister(new SimpleInputRegister(45));
        // 2. Create the coupler and set the slave identity
        ModbusCoupler.getReference().setProcessImage(spi);
        ModbusCoupler.getReference().setMaster(false);
        ModbusCoupler.getReference().setUnitID(2);
        // 3. Set up serial parameters
        SerialParameters params = new SerialParameters();
        params.setPortName(portname);
        params.setBaudRate(115200);
        params.setDatabits(8);
        params.setParity("None");
        params.setStopbits(1);
        params.setEncoding("ascii");
        params.setEcho(false);
        params.setReceiveTimeoutMillis(100);
        if (Modbus.debug) {
            System.out.println("Encoding [" + params.getEncoding() + "]");
        }
        // 4. Set up serial listener
        listener = new ModbusSerialListener(params);
        listener.setListening(true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) SimpleInputRegister(net.wimpi.modbus.procimg.SimpleInputRegister) SimpleProcessImage(net.wimpi.modbus.procimg.SimpleProcessImage) SimpleRegister(net.wimpi.modbus.procimg.SimpleRegister) ModbusSerialListener(net.wimpi.modbus.net.ModbusSerialListener) SerialParameters(net.wimpi.modbus.util.SerialParameters)

Example 3 with SimpleDigitalIn

use of net.wimpi.modbus.procimg.SimpleDigitalIn in project openhab1-addons by openhab.

the class TCPSlaveTest method main.

public static void main(String[] args) {
    ModbusTCPListener listener = null;
    SimpleProcessImage spi = null;
    int port = Modbus.DEFAULT_PORT;
    try {
        if (args != null && args.length == 1) {
            port = Integer.parseInt(args[0]);
        }
        System.out.println("jModbus Modbus Slave (Server)");
        // 1. prepare a process image
        spi = new SimpleProcessImage();
        spi.addDigitalOut(new SimpleDigitalOut(true));
        spi.addDigitalOut(new SimpleDigitalOut(true));
        spi.addDigitalIn(new SimpleDigitalIn(false));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addDigitalIn(new SimpleDigitalIn(false));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        // allow checking LSB/MSB order
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addRegister(new SimpleRegister(251));
        spi.addInputRegister(new SimpleInputRegister(45));
        // 2. create the coupler holding the image
        ModbusCoupler.getReference().setProcessImage(spi);
        ModbusCoupler.getReference().setMaster(false);
        ModbusCoupler.getReference().setUnitID(15);
        // 3. create a listener with 3 threads in pool
        if (Modbus.debug) {
            System.out.println("Listening...");
        }
        listener = new ModbusTCPListener(3);
        listener.setPort(port);
        listener.start();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) ModbusTCPListener(net.wimpi.modbus.net.ModbusTCPListener) SimpleInputRegister(net.wimpi.modbus.procimg.SimpleInputRegister) SimpleProcessImage(net.wimpi.modbus.procimg.SimpleProcessImage) SimpleRegister(net.wimpi.modbus.procimg.SimpleRegister)

Example 4 with SimpleDigitalIn

use of net.wimpi.modbus.procimg.SimpleDigitalIn in project openhab1-addons by openhab.

the class UDPSlaveTest method main.

public static void main(String[] args) {
    ModbusUDPListener listener = null;
    SimpleProcessImage spi = null;
    int port = Modbus.DEFAULT_PORT;
    try {
        if (args != null && args.length == 1) {
            port = Integer.parseInt(args[0]);
        }
        System.out.println("jModbus Modbus/UDP Slave v0.1");
        // 1. Prepare a process image
        spi = new SimpleProcessImage();
        spi.addDigitalOut(new SimpleDigitalOut(true));
        spi.addDigitalIn(new SimpleDigitalIn(false));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addDigitalIn(new SimpleDigitalIn(false));
        spi.addDigitalIn(new SimpleDigitalIn(true));
        spi.addRegister(new SimpleRegister(251));
        spi.addInputRegister(new SimpleInputRegister(45));
        ModbusCoupler.getReference().setProcessImage(spi);
        ModbusCoupler.getReference().setMaster(false);
        ModbusCoupler.getReference().setUnitID(15);
        // 2. Setup and start listener
        listener = new ModbusUDPListener();
        listener.setPort(port);
        listener.start();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) SimpleInputRegister(net.wimpi.modbus.procimg.SimpleInputRegister) ModbusUDPListener(net.wimpi.modbus.net.ModbusUDPListener) SimpleProcessImage(net.wimpi.modbus.procimg.SimpleProcessImage) SimpleRegister(net.wimpi.modbus.procimg.SimpleRegister)

Example 5 with SimpleDigitalIn

use of net.wimpi.modbus.procimg.SimpleDigitalIn in project openhab1-addons by openhab.

the class WriteCoilsAndDiscreteTestCase method initSpi.

private void initSpi() {
    dins = new DigitalIn[] { new SimpleDigitalIn(discreteInitialValue), new SimpleDigitalIn(discreteInitialValue), new SimpleDigitalIn(discreteInitialValue), new SimpleDigitalIn(discreteInitialValue) };
    for (DigitalIn din : dins) {
        spi.addDigitalIn(din);
    }
    douts = new DigitalOut[] { new SimpleDigitalOut(coilInitialValue), new SimpleDigitalOut(coilInitialValue), new SimpleDigitalOut(coilInitialValue), new SimpleDigitalOut(coilInitialValue) };
    for (DigitalOut dout : douts) {
        spi.addDigitalOut(dout);
    }
}
Also used : SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) DigitalOut(net.wimpi.modbus.procimg.DigitalOut) SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) DigitalIn(net.wimpi.modbus.procimg.DigitalIn) SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn)

Aggregations

SimpleDigitalIn (net.wimpi.modbus.procimg.SimpleDigitalIn)8 SimpleDigitalOut (net.wimpi.modbus.procimg.SimpleDigitalOut)7 Test (org.junit.Test)4 SimpleInputRegister (net.wimpi.modbus.procimg.SimpleInputRegister)3 SimpleProcessImage (net.wimpi.modbus.procimg.SimpleProcessImage)3 SimpleRegister (net.wimpi.modbus.procimg.SimpleRegister)3 SwitchItem (org.openhab.core.library.items.SwitchItem)3 ModbusSerialListener (net.wimpi.modbus.net.ModbusSerialListener)1 ModbusTCPListener (net.wimpi.modbus.net.ModbusTCPListener)1 ModbusUDPListener (net.wimpi.modbus.net.ModbusUDPListener)1 DigitalIn (net.wimpi.modbus.procimg.DigitalIn)1 DigitalOut (net.wimpi.modbus.procimg.DigitalOut)1 SerialParameters (net.wimpi.modbus.util.SerialParameters)1