use of com.ghgande.j2mod.modbus.msg.WriteCoilRequest in project openems by OpenEMS.
the class ModbusBridge method writeSingleCoil.
private ModbusResponse writeSingleCoil(int modbusUnitId, int address, boolean b) throws OpenemsModbusException, ModbusException {
ModbusTransaction trans = getTransaction();
WriteCoilRequest req = new WriteCoilRequest(address, b);
req.setUnitID(modbusUnitId);
trans.setRequest(req);
try {
trans.execute();
} catch (ModbusException e) {
// try again with new connection
closeModbusConnection();
trans = getTransaction();
req = new WriteCoilRequest(address, b);
req.setUnitID(modbusUnitId);
trans.setRequest(req);
trans.execute();
}
return trans.getResponse();
}
use of com.ghgande.j2mod.modbus.msg.WriteCoilRequest 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);
}
}
use of com.ghgande.j2mod.modbus.msg.WriteCoilRequest 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());
}
}
Aggregations