Search in sources :

Example 1 with SimpleDigitalOut

use of net.wimpi.modbus.procimg.SimpleDigitalOut 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)

Example 2 with SimpleDigitalOut

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

the class ErroringQueriesTestCase method testReadingTooMuchTwoSlaves.

/**
     * Test case for situation where we try to poll too much data.
     *
     * In this test server has
     * - single coil
     * - two discrete inputs
     *
     * Binding is configured to read
     * - two coils
     * - two discrete inputs
     *
     * Items are follows
     * - first (index=0) coil (Item1) -> no output since coil query should fail
     * - index=1 discrete (Item2) should be OK
     * - index=2 discrete (Item3) no event transmitted, item readIndex out of bounds. WARN logged
     */
@Test
public void testReadingTooMuchTwoSlaves() throws UnknownHostException, ConfigurationException, BindingConfigParseException {
    spi.addDigitalOut(new SimpleDigitalOut(true));
    spi.addDigitalIn(new SimpleDigitalIn(true));
    spi.addDigitalIn(new SimpleDigitalIn(true));
    spi.addDigitalIn(new SimpleDigitalIn(true));
    binding = new ModbusBinding();
    Dictionary<String, Object> config = newLongPollBindingConfig();
    addSlave(config, SLAVE_NAME, ModbusBindingProvider.TYPE_COIL, null, 0, 2);
    addSlave(config, SLAVE2_NAME, ModbusBindingProvider.TYPE_DISCRETE, null, 0, 2);
    binding.updated(config);
    // Configure items
    final ModbusGenericBindingProvider provider = new ModbusGenericBindingProvider();
    provider.processBindingConfiguration("test.items", new SwitchItem("Item1"), String.format("%s:%d", SLAVE_NAME, 0));
    provider.processBindingConfiguration("test.items", new SwitchItem("Item2"), String.format("%s:%d", SLAVE2_NAME, 1));
    provider.processBindingConfiguration("test.items", new SwitchItem("Item3"), String.format("%s:%d", SLAVE2_NAME, 2));
    binding.setEventPublisher(eventPublisher);
    binding.addBindingProvider(provider);
    binding.execute();
    // Give the system some time to make the expected connections & requests
    waitForConnectionsReceived(2);
    waitForRequests(2);
    verify(eventPublisher, never()).postCommand(null, null);
    verify(eventPublisher, never()).sendCommand(null, null);
    verify(eventPublisher).postUpdate("Item2", OnOffType.ON);
    verifyNoMoreInteractions(eventPublisher);
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) SwitchItem(org.openhab.core.library.items.SwitchItem) Test(org.junit.Test)

Example 3 with SimpleDigitalOut

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

the class ErroringQueriesTestCase method testReadingTooMuch.

/**
     * Test case for situation where we try to poll too much data.
     *
     * In this test server has
     * - single discrete input
     * - single coil inputs
     *
     * Binding is configured to read
     * - two coils
     *
     * Items are follows
     * - first discrete input (Item1) -> no output since query
     * should fail
     */
@Test
public void testReadingTooMuch() throws UnknownHostException, ConfigurationException, BindingConfigParseException {
    spi.addDigitalIn(new SimpleDigitalIn(true));
    spi.addDigitalOut(new SimpleDigitalOut(true));
    spi.addDigitalOut(new SimpleDigitalOut(false));
    binding = new ModbusBinding();
    Dictionary<String, Object> config = newLongPollBindingConfig();
    addSlave(config, SLAVE_NAME, ModbusBindingProvider.TYPE_DISCRETE, null, 0, 2);
    binding.updated(config);
    // Configure items
    final ModbusGenericBindingProvider provider = new ModbusGenericBindingProvider();
    provider.processBindingConfiguration("test.items", new SwitchItem("Item1"), String.format("%s:%d", SLAVE_NAME, 0));
    binding.setEventPublisher(eventPublisher);
    binding.addBindingProvider(provider);
    binding.execute();
    waitForConnectionsReceived(1);
    waitForRequests(1);
    verifyNoMoreInteractions(eventPublisher);
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) SwitchItem(org.openhab.core.library.items.SwitchItem) Test(org.junit.Test)

Example 4 with SimpleDigitalOut

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

the class ErroringQueriesTestCase method testReadingTooMuchWithPostUndef.

@Test
public void testReadingTooMuchWithPostUndef() throws UnknownHostException, ConfigurationException, BindingConfigParseException {
    spi.addDigitalIn(new SimpleDigitalIn(true));
    spi.addDigitalOut(new SimpleDigitalOut(true));
    spi.addDigitalOut(new SimpleDigitalOut(false));
    binding = new ModbusBinding();
    Dictionary<String, Object> config = newLongPollBindingConfig();
    addSlave(config, SLAVE_NAME, ModbusBindingProvider.TYPE_DISCRETE, null, 0, 2);
    putSlaveConfigParameter(config, serverType, SLAVE_NAME, "postundefinedonreaderror", "true");
    binding.updated(config);
    // Configure items
    final ModbusGenericBindingProvider provider = new ModbusGenericBindingProvider();
    provider.processBindingConfiguration("test.items", new SwitchItem("Item1"), String.format("%s:%d", SLAVE_NAME, 0));
    binding.setEventPublisher(eventPublisher);
    binding.addBindingProvider(provider);
    binding.execute();
    waitForConnectionsReceived(1);
    waitForRequests(1);
    verify(eventPublisher).postUpdate("Item1", UnDefType.UNDEF);
    verifyNoMoreInteractions(eventPublisher);
}
Also used : SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) SwitchItem(org.openhab.core.library.items.SwitchItem) Test(org.junit.Test)

Example 5 with SimpleDigitalOut

use of net.wimpi.modbus.procimg.SimpleDigitalOut 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)

Aggregations

SimpleDigitalIn (net.wimpi.modbus.procimg.SimpleDigitalIn)7 SimpleDigitalOut (net.wimpi.modbus.procimg.SimpleDigitalOut)7 SimpleInputRegister (net.wimpi.modbus.procimg.SimpleInputRegister)3 SimpleProcessImage (net.wimpi.modbus.procimg.SimpleProcessImage)3 SimpleRegister (net.wimpi.modbus.procimg.SimpleRegister)3 Test (org.junit.Test)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