Balaji-Sundar opened a new issue, #1997:
URL: https://github.com/apache/plc4x/issues/1997
### What happened?
Modbus Over TCP Reading Float Value in Negative Issue. Actual value is
1.93e+07
public static void main(String[] args) {
try {
String ip = "10.7.10.1";
int port = 502;
int slaveId = 2;
int requestTimeOut = 10000;
String payLoadByteOrder = "LITTLE_ENDIAN_BYTE_SWAP";
String connectionUrl =
String.format("modbus-tcp:tcp://%s:%d?unit-identifier=%d&request-timeout=%d&default-payload-byte-order=%s",
ip, port, slaveId, requestTimeOut, payLoadByteOrder);
try (PlcConnection plcConnection = new
DefaultPlcDriverManager().getConnection(connectionUrl)) {
if (!plcConnection.getMetadata().isReadSupported()) {
System.out.println("This connection doesn't support reading.");
}
PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
builder.addTagAddress("value1", "holding-register:159:REAL[2]");
PlcReadRequest readRequest = builder.build();
PlcReadResponse response = readRequest.execute().get();
System.out.println("response = " + response.toString());
for (String tagName : response.getTagNames()) {
System.out.println("Tag: " + tagName);
System.out.println("Response code for " + tagName + ": " +
response.getResponseCode(tagName));
int numValues = response.getNumberOfValues(tagName);
System.out.println("numValues = " + numValues);
if (response.getResponseCode(tagName) == PlcResponseCode.OK) {
System.out.println("response = " + response.getTag(tagName));
System.out.println("response = " + response.getFloat(tagName));
//response.getAllBytes(tagName).stream().map(HexUtil::toHex).map(hex ->
"Register Value: " + hex).forEach(System.out::println);
} else {
System.out.println("Error[" + tagName + "]: " +
response.getResponseCode(tagName).name());
}
}
}
} catch (Exception e) {
System.out.println("e = " + e);
}
}
Output:
response = org.apache.plc4x.java.spi.messages.DefaultPlcReadResponse@6a47b187
Tag: value1
Response code for value1: OK
numValues = 2
response = ModbusTagHoldingRegister {address=158, quantity=2, dataType=REAL }
response = -7.128774E35
### Version
v0.12.0
### Programming Languages
- [x] plc4j
- [ ] plc4go
- [ ] plc4c
- [ ] plc4net
### Protocols
- [ ] AB-Ethernet
- [ ] ADS /AMS
- [ ] BACnet/IP
- [ ] CANopen
- [ ] DeltaV
- [ ] DF1
- [ ] EtherNet/IP
- [ ] Firmata
- [ ] KNXnet/IP
- [x] Modbus
- [ ] OPC-UA
- [ ] S7
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]