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

    Byte Array to Real

    Scheduled Pinned Locked Moved Mervis
    4 Posts 2 Posters 832 Views
    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áčekM 1 Reply Last reply
      Reply Quote 0
      • Martin KudláčekM
        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áčekM 1 Reply Last reply
          Reply Quote 0
          • Martin KudláčekM
            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

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post