• Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Byte Array to Real

    Mervis
    2
    4
    49
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      Neuron_Flo last edited by

      Dear Unipi Support Team,
      in a function block I want to assign a byte array (4Bytes) to a real? All variants I've tested ends in the normal int interpretation.

      Martin Kudláček 1 Reply Last reply Reply Quote 0
      • Martin Kudláček
        Martin Kudláček @Neuron_Flo last edited by

        Hello @Neuron_Flo,
        what is the source of these 4 bytes? Do you read them from some HW prototype?

        Martin

        1 Reply Last reply Reply Quote 0
        • N
          Neuron_Flo last edited by

          Hi Martin, from a tcp connection:
          received := io.readport(handle, adr(dataRecv[0]), 9);

          I have a real of 4bytes in the byte array.

          Martin Kudláček 1 Reply Last reply Reply Quote 0
          • Martin Kudláček
            Martin Kudláček @Neuron_Flo last edited by Martin Kudláček

            Hello @Neuron_Flo,
            we tried different approaches, but non of them gave the correct result. There doesn't seem to be a native way how to transform this data in ST code. It looks like you need to resort to the classic calculation according to: https://en.wikipedia.org/wiki/Single-precision_floating-point_format

            Martin

            1 Reply Last reply Reply Quote 0
            • First post
              Last post