0

Hi I am reading data from a multimeter and I have to store those values in float. I am using javax.comm jar file for it and Serial port. But after reading from it I am getting values like

[B@1592174 [B@a352a5 [B@86fe26 [B@97a560 ...

And when I am converting these values to string and the to double I am getting some huge number which is not same as the value in the multimeter. So what should I do??

I am doing the reading from the serial port via inputStream and converting them to a byte array.

JimiLoe
  • 950
  • 2
  • 14
  • 22
ajroxx27
  • 11
  • 3

1 Answers1

0

You're printing the actual byte[] object, whose toString shows you the class ([B for byte array) and the hash code (a352a5, for example). Instead, use Arrays.toString(byteArray).

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • I have used Arrays.toString(byteArray), but it is printing an array which consist of singned integers. And those values does'nt matches with my multimeter values. – ajroxx27 Mar 12 '14 at 05:24
  • the value for [B@86fe26 is [-16, 120, -16, -128, -128, 112, -128, -16, -128, -8, 112, 120, -16, -128, -8, 120, -8, -16, 0, 112, -128, 0, -8, 0, -8, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0....] as my byteArray size is 1024.... – ajroxx27 Mar 12 '14 at 05:25
  • @user3335924 Now you have to interpret those bytes according to your multimeter's protocol, which you haven't described at all. Using a `ByteBuffer` wrapped around your array and calling `getFloat` might work if it's IEEE 754. – chrylis -cautiouslyoptimistic- Mar 12 '14 at 05:44