Search in sources :

Example 1 with WriteCoilResponse

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

the class WriteCoilExecutor method execute.

@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
    WriteCoilRequest req = new WriteCoilRequest(Integer.parseInt(registerAddress, 16), coil);
    req.setUnitID(slaveAddress);
    ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
    trans.setRequest(req);
    trans.execute();
    WriteCoilResponse res = (WriteCoilResponse) trans.getResponse();
    if (res != null) {
        result = res.getCoil();
        logger.debug("{}: Write coil register={} coil={} result={}", applianceId, registerAddress, coil, result);
    } else {
        logger.error("{}: No response received.", applianceId);
    }
}
Also used : ModbusTCPTransaction(com.ghgande.j2mod.modbus.io.ModbusTCPTransaction) WriteCoilResponse(com.ghgande.j2mod.modbus.msg.WriteCoilResponse) WriteCoilRequest(com.ghgande.j2mod.modbus.msg.WriteCoilRequest)

Example 2 with WriteCoilResponse

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

the class WriteCoilExecutorImpl method execute.

@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
    WriteCoilRequest req = new WriteCoilRequest(getAddress(), value);
    req.setUnitID(slaveAddress);
    ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
    trans.setRequest(req);
    trans.execute();
    WriteCoilResponse res = (WriteCoilResponse) trans.getResponse();
    if (res != null) {
        result = res.getCoil();
        logger.debug("{}: Write coil register={} coil={} confirmedValue={}", getApplianceId(), getAddress(), value, result);
    } else {
        logger.error("{}: No response received.", getApplianceId());
    }
}
Also used : ModbusTCPTransaction(com.ghgande.j2mod.modbus.io.ModbusTCPTransaction) WriteCoilResponse(com.ghgande.j2mod.modbus.msg.WriteCoilResponse) WriteCoilRequest(com.ghgande.j2mod.modbus.msg.WriteCoilRequest)

Aggregations

ModbusTCPTransaction (com.ghgande.j2mod.modbus.io.ModbusTCPTransaction)2 WriteCoilRequest (com.ghgande.j2mod.modbus.msg.WriteCoilRequest)2 WriteCoilResponse (com.ghgande.j2mod.modbus.msg.WriteCoilResponse)2