Search in sources :

Example 1 with IllegalAddressException

use of net.wimpi.modbus.procimg.IllegalAddressException in project openhab1-addons by openhab.

the class WriteSingleRegisterRequest method createResponse.

// constructor
@Override
public ModbusResponse createResponse() {
    WriteSingleRegisterResponse response = null;
    Register reg = null;
    // 1. get process image
    ProcessImage procimg = ModbusCoupler.getReference().getProcessImage();
    // 2. get register
    try {
        reg = procimg.getRegister(m_Reference);
        // 3. set Register
        reg.setValue(m_Register.toBytes());
    } catch (IllegalAddressException iaex) {
        return createExceptionResponse(Modbus.ILLEGAL_ADDRESS_EXCEPTION);
    }
    response = new WriteSingleRegisterResponse(this.getReference(), reg.getValue());
    // 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 2 with IllegalAddressException

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

Example 3 with IllegalAddressException

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

Example 4 with IllegalAddressException

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

Example 5 with IllegalAddressException

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