Search in sources :

Example 1 with DigitalOut

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

Example 2 with DigitalOut

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

Example 3 with DigitalOut

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

Example 4 with DigitalOut

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);
    }
}
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

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