Search in sources :

Example 6 with IllegalAddressException

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;
}
Also used : InputRegister(net.wimpi.modbus.procimg.InputRegister) IllegalAddressException(net.wimpi.modbus.procimg.IllegalAddressException) ProcessImage(net.wimpi.modbus.procimg.ProcessImage)

Example 7 with IllegalAddressException

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;
}
Also used : Register(net.wimpi.modbus.procimg.Register) IllegalAddressException(net.wimpi.modbus.procimg.IllegalAddressException) ProcessImage(net.wimpi.modbus.procimg.ProcessImage)

Example 8 with IllegalAddressException

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;
}
Also used : Register(net.wimpi.modbus.procimg.Register) IllegalAddressException(net.wimpi.modbus.procimg.IllegalAddressException) ProcessImage(net.wimpi.modbus.procimg.ProcessImage)

Aggregations

IllegalAddressException (net.wimpi.modbus.procimg.IllegalAddressException)8 ProcessImage (net.wimpi.modbus.procimg.ProcessImage)8 DigitalOut (net.wimpi.modbus.procimg.DigitalOut)3 Register (net.wimpi.modbus.procimg.Register)3 DigitalIn (net.wimpi.modbus.procimg.DigitalIn)1 InputRegister (net.wimpi.modbus.procimg.InputRegister)1