use of com.ghgande.j2mod.modbus.io.ModbusTCPTransaction in project SmartApplianceEnabler by camueller.
the class ReadInputRegisterExecutor method execute.
@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
ReadInputRegistersRequest req = new ReadInputRegistersRequest(Integer.parseInt(registerAddress, 16), 2);
req.setUnitID(slaveAddress);
ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
trans.setRequest(req);
trans.execute();
ReadInputRegistersResponse res = (ReadInputRegistersResponse) trans.getResponse();
if (res != null) {
registerValue = Float.intBitsToFloat(res.getRegisterValue(0) << 16 | res.getRegisterValue(1));
logger.debug("{}: Input register={} value={}", applianceId, registerAddress, registerValue);
} else {
logger.error("{}: No response received.", applianceId);
}
}
use of com.ghgande.j2mod.modbus.io.ModbusTCPTransaction in project SmartApplianceEnabler by camueller.
the class ReadCoilExecutor method execute.
@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
ReadCoilsRequest req = new ReadCoilsRequest(Integer.parseInt(registerAddress, 16), 1);
req.setUnitID(slaveAddress);
ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
trans.setRequest(req);
trans.execute();
ReadCoilsResponse res = (ReadCoilsResponse) trans.getResponse();
if (res != null) {
coil = res.getCoils().getBit(0);
logger.debug("{}: Read coil register={} coil={}", applianceId, registerAddress, coil);
} else {
logger.error("{}: No response received.", applianceId);
}
}
use of com.ghgande.j2mod.modbus.io.ModbusTCPTransaction in project SmartApplianceEnabler by camueller.
the class ReadInputRegisterExecutor method execute.
@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
logger.trace("{}: Reading input register={} requestWords={}", getApplianceId(), getAddress(), getRequestWords());
ReadInputRegistersRequest req = new ReadInputRegistersRequest(getAddress(), getRequestWords());
req.setUnitID(slaveAddress);
ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
trans.setRequest(req);
trans.execute();
ReadInputRegistersResponse res = (ReadInputRegistersResponse) trans.getResponse();
if (res != null) {
Integer[] byteValues = new Integer[res.getWordCount()];
for (int i = 0; i < res.getWordCount(); i++) {
byteValues[i] = res.getRegisterValue(i);
}
logger.debug("{}: Input register={} value={}", getApplianceId(), getAddress(), byteValues);
getValueTransformer().setByteValues(byteValues);
} else {
logger.error("{}: No response received.", getApplianceId());
}
}
use of com.ghgande.j2mod.modbus.io.ModbusTCPTransaction in project SmartApplianceEnabler by camueller.
the class ReadCoilExecutorImpl method execute.
@Override
public void execute(TCPMasterConnection con, int slaveAddress) throws ModbusException {
logger.trace("{}: Reading coil register={}", getApplianceId(), getAddress());
ReadCoilsRequest req = new ReadCoilsRequest(getAddress(), 1);
req.setUnitID(slaveAddress);
ModbusTCPTransaction trans = new ModbusTCPTransaction(con);
trans.setRequest(req);
trans.execute();
ReadCoilsResponse res = (ReadCoilsResponse) trans.getResponse();
if (res != null) {
coil = res.getCoils().getBit(0);
logger.debug("{}: Coil register={} value={}", getApplianceId(), getAddress(), coil);
} else {
logger.error("{}: No response received.", getApplianceId());
}
}
use of com.ghgande.j2mod.modbus.io.ModbusTCPTransaction 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());
}
}
Aggregations