0
我正在使用Jamod從Modbus設備檢索值。它適用於正常值。當我嘗試從寄存器中檢索負值時,它會生成一些隨機值。如何使用JAMOD檢索負值
代碼:
private float getData (String address, int count) {
float sum = 0.0f;
request = new ReadMultipleRegistersRequest(Integer.parseInt(address), count);
response = new ReadMultipleRegistersResponse();
request.setUnitID(1);
response.setUnitID(1);
request.setHeadless();
try {
response = (ReadMultipleRegistersResponse) execute(connection, holdingRequest);
for (int i=0; i<registerCount; i++) {
sum = sum + response.getRegisterValue(i);
}
System.out.println("Sum: " + sum);
} catch (Exception e) {
e.printStackTrace();
}
return sum;
}
private ModbusResponse execute(SerialConnection connection, ModbusRequest request) {
try {
transaction = new ModbusSerialTransaction(connection);
transaction.setRequest(request);
transaction.execute();
return transaction.getResponse();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
請幫助。在此先感謝