Search in sources :

Example 1 with ReadInputDiscretesRequest

use of com.ghgande.j2mod.modbus.msg.ReadInputDiscretesRequest in project SmartApplianceEnabler by camueller.

the class ReadDiscreteInputExecutorImpl method execute.

@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
    logger.trace("{}: Reading discrete input register={}", getApplianceId(), getAddress());
    ReadInputDiscretesRequest req = new ReadInputDiscretesRequest(getAddress(), 1);
    req.setUnitID(slaveAddress);
    ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
    trans.setRequest(req);
    trans.execute();
    ReadInputDiscretesResponse res = (ReadInputDiscretesResponse) trans.getResponse();
    if (res != null) {
        discrete = res.getDiscreteStatus(0);
        logger.debug("{}: Discrete input register={} value={}", getApplianceId(), getAddress(), discrete);
    } else {
        logger.error("{}: No response received.", getApplianceId());
    }
}
Also used : ModbusTCPTransaction(com.ghgande.j2mod.modbus.io.ModbusTCPTransaction) ReadInputDiscretesResponse(com.ghgande.j2mod.modbus.msg.ReadInputDiscretesResponse) ReadInputDiscretesRequest(com.ghgande.j2mod.modbus.msg.ReadInputDiscretesRequest)

Aggregations

ModbusTCPTransaction (com.ghgande.j2mod.modbus.io.ModbusTCPTransaction)1 ReadInputDiscretesRequest (com.ghgande.j2mod.modbus.msg.ReadInputDiscretesRequest)1 ReadInputDiscretesResponse (com.ghgande.j2mod.modbus.msg.ReadInputDiscretesResponse)1