Search in sources :

Example 1 with DigitalIn

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

Example 2 with DigitalIn

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);
    }
}
Also used : SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) DigitalOut(net.wimpi.modbus.procimg.DigitalOut) SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn) SimpleDigitalOut(net.wimpi.modbus.procimg.SimpleDigitalOut) DigitalIn(net.wimpi.modbus.procimg.DigitalIn) SimpleDigitalIn(net.wimpi.modbus.procimg.SimpleDigitalIn)

Aggregations

DigitalIn (net.wimpi.modbus.procimg.DigitalIn)2 DigitalOut (net.wimpi.modbus.procimg.DigitalOut)1 IllegalAddressException (net.wimpi.modbus.procimg.IllegalAddressException)1 ProcessImage (net.wimpi.modbus.procimg.ProcessImage)1 SimpleDigitalIn (net.wimpi.modbus.procimg.SimpleDigitalIn)1 SimpleDigitalOut (net.wimpi.modbus.procimg.SimpleDigitalOut)1