Announcement

Collapse
No announcement yet.

Float Conversion

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

  • g.mccormick
    replied
    Setup the array as 16bit word type. You are reading 16bit words. You can then combine two array elements into a 32 bit int, then do a copy bits to 32bit float for the floats.

    Leave a comment:


  • RBPLC
    replied
    I'm trying to read a number of Modbus registers from another device. I wanted to use one MRX command to read all of the holding registers that I needed out of the device. In the other device, all values are stored in 32-bit registers (two words). Every parameter has two Modbus words allocated for that parameter but not every parameter is 32-bit data type. Some values are IEEE float (taking the 32-bits) and others are 8-bit enumerated values. In trying to use the one MRX command, I wanted to set up an array to read in all of the registers I need with one command and then go back and pull out the data from the array (directly for float values and by unpacking for enumerated values). I was going to set the array as a floating point number type as the majority of the numbers read in will be floats and I can parse them directly without conversion out of the array. The issue is there doesn't seem to be a way to take that 32 bit number and pull out one of the bytes to get the enumerated value (as you stated, the three other bytes might be junk but that's o.k.). In the BRX platform this can be done by casting, like: Value0:UB0, Value0:UB1, Value0:UB2, Value0:UB3, where I would only need Value0:UB0 as this is the only part of the word that contains any useful information. The casting operation in the BRX does exactly what I need but it doesn't appear that I can do the same thing with the Productivity. There are several other ways to do what I want but they will require multiple MRX commands.

    Leave a comment:


  • kewakl
    replied
    What information would you like to keep?
    You could MATH * a factor of 10 to keep tenth/hund/thou.
    You could CPD if you dont need the dec part.
    Check for round ir truncate if you do CPD.
    What do you need to extract from your original value?
    Unpacking a float may not return 'meaningful' info.

    Leave a comment:


  • RBPLC
    started a topic Float Conversion

    Float Conversion

    Is there an easy/direct way to convert a float to a word or byte? What I would like to do is perform the UPKW function with a float instead of a DWord.
    Last edited by RBPLC; 03-07-2020, 03:15 AM.
Working...
X