0

I am developing a windows form application that interacts with a Siemens PLC S7 cpu. When I get a parameter from the CPU I get an Object that I convert in double using the Convert.ToDouble method.

Doing this I get extremely huge numbers e. g. I get 1162660659 when the property should be 28. I talket to the guy that developed the PLC software and he told me that the variables are stored in IEEE 754 format.

Is it possible the PLC presents the bytes of the floating point value in a different order--that is, with different endianness--than the PC running my .net software?

Do you have any suggestion on how to convert them?

Thank you in advance, best regards.

JJJ
  • 32,902
  • 20
  • 89
  • 102
user449689
  • 3,142
  • 4
  • 19
  • 37
  • 3
    Is the Siemens PLC big-endian or little-endian? If it's big-endian you'll probably have to reverse the order of the byte array before calling 'ToDouble()`. – D Stanley Jul 01 '14 at 13:15
  • 1
    Intel processors also use this floating point format. You didn't say whether the PLC returns 32-, 64-, or 80- bit floating point. You should try looking at the bit pattern in the value 28 generated on your PC, and that same bit pattern as presented by the PLC. It's possible you have to reverse the order of the bytes in the data presented by the PLC. Also. You said it is presented as a .net Object. There must be some PLC-to-.net host adapter driver software doing that. Look for documentation for that driver software. – O. Jones Jul 01 '14 at 13:19
  • @user449689, the answer erroneously tagged as a dup here probably won't help you, because it doesn't take the byte-order question (aka endianness) into account. – O. Jones Jul 01 '14 at 13:26
  • It is most definitely *not* a endian-ness problem, that produces a drastically outlandish value. The value 1162660659 has 3 bytes that match an ASCII code, odd coincidence. – Hans Passant Jul 01 '14 at 15:26
  • @OllieJones, I tried reversing the order of the byte array, but it did not work. – user449689 Jul 05 '14 at 20:39
  • @HansPassant, can you please explain me more about the 3 bytes that match the ASCII code? Thanks! – user449689 Jul 05 '14 at 20:40

0 Answers0