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);
}
}
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);
}
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);
}
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);
}
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();
}
}
Aggregations