use of net.wimpi.modbus.procimg.IllegalAddressException in project openhab1-addons by openhab.
the class ReadInputRegistersRequest method createResponse.
// constructor
@Override
public ModbusResponse createResponse() {
ReadInputRegistersResponse response = null;
InputRegister[] inpregs = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get input registers range
try {
inpregs = procimg.getInputRegisterRange(this.getReference(), this.getWordCount());
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new ReadInputRegistersResponse(inpregs);
// 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.IllegalAddressException in project openhab1-addons by openhab.
the class ReadMultipleRegistersRequest method createResponse.
// constructor
@Override
public ModbusResponse createResponse() {
ReadMultipleRegistersResponse response = null;
Register[] regs = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get input registers range
try {
regs = procimg.getRegisterRange(this.getReference(), this.getWordCount());
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new ReadMultipleRegistersResponse(regs);
// 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.IllegalAddressException in project openhab1-addons by openhab.
the class WriteMultipleRegistersRequest method createResponse.
// constructor
@Override
public ModbusResponse createResponse() {
WriteMultipleRegistersResponse response = null;
if (m_NonWordDataHandler == null) {
Register[] regs = null;
// 1. get process image
ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
// 2. get registers
try {
// TODO: realize a setRegisterRange()?
regs = procimg.getRegisterRange(this.getReference(), this.getWordCount());
// 3. set Register values
for (int i = 0; i < regs.length; i++) {
regs[i].setValue(this.getRegister(i).toBytes());
}
} catch (IllegalAddressException iaex) {
return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
}
response = new WriteMultipleRegistersResponse(this.getReference(), regs.length);
} else {
int result = m_NonWordDataHandler.commitUpdate();
if (result > 0) {
return createExceptionResponse(result);
}
response = new WriteMultipleRegistersResponse(this.getReference(), m_NonWordDataHandler.getWordCount());
}
// 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;
}
Aggregations