I'm using jamod library and trying to convert data read from Input Registers to float. Here is my code:
inputRegisterRequest=newReadInputRegistersRequest(30512,2);inputRegisterResponse=newReadInputRegistersResponse();try{inputRegisterResponse=(ReadInputRegistersResponse)execute(connection,inputRegisterRequest);inttempData=0;for(inti=0;i<inputRegisterResponse.getWordCount();i++){tempData=tempData+inputRegisterResponse.getRegisterValue(i);}//Method1:floatf=Float.intBitsToFloat(tempData);System.out.println("The new float value: "+f);//Method2:floatf=ModbusUtil.registersToFloat(inputRegisterToByteArray(inputRegisterResponse.getRegisters()));//Method3:DataInputStreamdis=newDataInputStream(newByteArrayinputStream(inputRegisterResponse.getRegisters()));floatf=dis.readFloat();}
Everytime I get some incorrect answer. Any help would be appreciated.
Last edit: Vaishnavi 2016-08-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm using jamod library and trying to convert data read from Input Registers to float. Here is my code:
Everytime I get some incorrect answer. Any help would be appreciated.
Last edit: Vaishnavi 2016-08-13