use of net.wimpi.modbus.procimg.DigitalIn in project openhab1-addons by openhab.
the class ReadInputDiscretesRequest method createResponse.
// constructor
/*
* public ModbusResponse getResponse() {
* ReadInputDiscretesResponse response =
* new ReadInputDiscretesResponse(getBitCount());
* response.setHeadless(isHeadless());
* return response;
* }//getResponse
*/
@Override
public ModbusResponse createResponse() {
ReadInputDiscretesResponse response = null;
DigitalIn[] dins = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get inputdiscretes range
try {
dins = procimg.getDigitalInRange(this.getReference(), this.getBitCount());
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new ReadInputDiscretesResponse(dins.length);
// transfer header data
if (!isHeadless()) {
response.setTransactionID(this.getTransactionID());
response.setProtocolID(this.getProtocolID());
} else {
response.setHeadless();
}
response.setUnitID(this.getUnitID());
response.setFunctionCode(this.getFunctionCode());
for (int i = 0; i < dins.length; i++) {
response.setDiscreteStatus(i, dins[i].isSet());
}
return response;
}
use of net.wimpi.modbus.procimg.DigitalIn 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);
}
}
Aggregations