Announcement

Collapse
No announcement yet.

BRX Do-More Modbus Float32 Conversion from two 16bit Words

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Ok I think I got it, man I wish I had some brain capacity left today, still don't fully grasp casting but its working.

    So the answer is SUBSCRIB to the 2 unsigned words (use 2 elements at the bottom), add the :R to the first EVEN Element (DLV1520:R), it turned mine into DLV1520:RD, pick an Rxxx Memory space to write to, and in my case if the answer is wrong try to swap words at the bottom, the worked for me(mine converted to float32 in modbus poll using big endian) . So...:
    DLV1520 = 16990
    DLV1521 = 26215

    These combined to give us: R1006 = 55.6

    (Ignore everthing but the SUBSCRIB, all things I tried to get here)

    Thanks for the Help BobO

    Screen shoot:

    Click image for larger version

Name:	Screenshot (162).png
Views:	97
Size:	796.9 KB
ID:	126841

    Comment


    • #17
      Casting is a way to coerce data of one datatype into data of another datatype.
      Casting may result in data loss.

      a simple way (and maybe not 100% accurate) of looking at casting:
      i have this data and i want it to look like another datatype.

      16 digital inputs can be 'cast' to look like a 16-bit word.

      Comment


      • #18
        Originally posted by kewakl View Post
        Casting is a way to coerce data of one datatype into data of another datatype.
        Casting may result in data loss.
        Not in this context. Do-more's casts are reinterpretations, not conversions.

        Comment


        • #19
          Originally posted by BobO View Post

          Not in this context. Do-more's casts are reinterpretations, not conversions.
          Thats why i also included the 'i want to look like...' phrasing
          but thanks for clarifying... as always

          Comment


          • #20
            Originally posted by Dirtybeef View Post
            Ok I think I got it, man I wish I had some brain capacity left today, still don't fully grasp casting but its working.

            So the answer is SUBSCRIB to the 2 unsigned words (use 2 elements at the bottom), add the :R to the first EVEN Element (DLV1520:R), it turned mine into DLV1520:RD, pick an Rxxx Memory space to write to, and in my case if the answer is wrong try to swap words at the bottom, the worked for me(mine converted to float32 in modbus poll using big endian) . So...:
            DLV1520 = 16990
            DLV1521 = 26215

            These combined to give us: R1006 = 55.6

            (Ignore everthing but the SUBSCRIB, all things I tried to get here)
            Do-more casts can do several things: 1) aggregation, 2) extraction, and 3) reinterpretation.

            Aggregation allows you to grab several contiguous smaller types and use them as one larger type. For instance, if you wanted to look at X16-31 as an unsigned word, you would add :UW to the first location...X16:UW. If you wanted it to be signed, it would be X16:SW. Any type of aggregation needs to be aligned to the size of the aggregate. In the case of bytes, X0, X8, X16, X24 are all valid. For words, X0, X16, X32, etc. For dwords, X0, X32, X64, etc.

            You can also aggregate bytes into words or dwords, or words into dwords. As with bits, they need to be aligned to the aggregate's size. You can view V0 and V1 as a signed dword with V0:SD, or as a float V0:RD.

            Extraction casts allow you to isolate parts of a larger element. If you wanted the first byte of D10 as an unsigned, it would be D10:SB0, the third byte as unsigned would be D10:UB2. You can grab a bit of any numeric element by specifying the bit number. Last bit of D1 is D1:31. First bit is D1:0.

            Reinterpretation allows you to override the default type. If you copied the raw bytes of a float into a D location and view it as the default, it'll be garbage. But if you use :R, like D3:R, it reinterprets those bytes as float.

            The best way to understand what you can and cannot do with casting is to open the Element Browser (F9 from the Dashboard) and show the Cast-Builder. Lower right corner of the Element Browser there is a button that says Show Cast-Builder. Click that. Then enter an element in the Source Element field and just start clicking buttons in the Cast-Builder. It'll start to make sense after a bit of playing.

            As for your app, you only needed the SUBSCRIBE. Casting is a quicker and easier way to aggregate two words and reinterpret them as a float...if the byte/word order is correct and the offset is even. SUBSCRIBE allows you to fix byte order and alignment though, and works for all cases. I honestly shouldn't have mentioned casting and just sent you to SUBSCRIBE, but I wanted to communicate that Do-more is chock full of ways to do the stuff you were trying to do.

            Comment


            • #21
              Thanks BobO, I hadn't looked at the SUBSCRIBE function this way until now.

              Comment

              Working...
              X