use of net.wimpi.modbus.procimg.DigitalOut in project openhab1-addons by openhab.
the class ReadCoilsRequest method createResponse.
// constructor
@Override
public ModbusResponse createResponse() {
ReadCoilsResponse response = null;
DigitalOut[] douts = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get coil range
try {
douts = procimg.getDigitalOutRange(this.getReference(), this.getBitCount());
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new ReadCoilsResponse(douts.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 < douts.length; i++) {
response.setCoilStatus(i, douts[i].isSet());
}
return response;
}
use of net.wimpi.modbus.procimg.DigitalOut in project openhab1-addons by openhab.
the class WriteCoilRequest method createResponse.
// constructor
@Override
public ModbusResponse createResponse() {
WriteCoilResponse response = null;
DigitalOut dout = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get coil
try {
dout = procimg.getDigitalOut(this.getReference());
// 3. set coil
dout.set(this.getCoil());
// if(Modbus.debug) System.out.println("set coil ref="+this.getReference()+" state=" + this.getCoil());
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new WriteCoilResponse(this.getReference(), dout.isSet());
// transfer header data
if (!isHeadless()) {
response.setTransactionID(this.getTransactionID());
response.setProtocolID(this.getProtocolID());
} else {
response.setHeadless();
}
response.setUnitID(this.getUnitID());
response.setFunctionCode(this.getFunctionCode());
return response;
}
use of net.wimpi.modbus.procimg.DigitalOut in project openhab1-addons by openhab.
the class WriteMultipleCoilsRequest method createResponse.
// constructor
@Override
public ModbusResponse createResponse() {
WriteMultipleCoilsResponse response = null;
DigitalOut[] douts = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get coil range
try {
douts = procimg.getDigitalOutRange(m_Reference, m_Coils.size());
// 3. set coils
for (int i = 0; i < douts.length; i++) {
douts[i].set(m_Coils.getBit(i));
}
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new WriteMultipleCoilsResponse(m_Reference, m_Coils.size());
// transfer header data
if (!isHeadless()) {
response.setTransactionID(this.getTransactionID());
response.setProtocolID(this.getProtocolID());
} else {
response.setHeadless();
}
response.setUnitID(this.getUnitID());
response.setFunctionCode(this.getFunctionCode());
return response;
}
use of net.wimpi.modbus.procimg.DigitalOut 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