Send IEEE Float To device

Forum Home Forums Communicating with Devices Modbus Send IEEE Float To device

This topic contains 7 replies, has 3 voices, and was last updated by Avatar roska 2 years, 4 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2298
    Avatar
    roska
    Participant

    Im able to read all kinds of values from a Controller with Modbus RTU, and I’m also able to set single coils or registers. Everything easy and as usual. But I’m not able to send a IEEE float. (for excample to transmit the setpoint).
    In the command section, I select Multiple, to get modbus function 16, and I set element count to 2.
    But when I want to send the command, I can only select string or hexadecimal. If I select hexadecimal, and enter the float as hex value (for excample 77.88 = 0x429BC28F), only the first word (429B) is transmetted. The setpoint of the controller is then 77.5, which is 0x429B0000.

    So how to send a IEEE float?

    Thanks,

    Robert

    #2299
    Avatar
    roska
    Participant

    And I would like to enter the decimal number, not hex. 🙂

    #2300
    Avatar
    manjey73
    Participant

    Options for Standard commands to use formulas for IEEE (float)

    Add to base formula

    public double fRevers (int rev)
    {
    float q = Convert.ToSingle(CmdVal);
    byte[] f = new byte[4];
    byte[] o = new byte[4];
    f = BitConverter.GetBytes(q);
    Array.Copy(f,0,o,0,4);
    if (rev == 1)
    {
    Array.Copy(f, 0, o, 1, 1);
    Array.Copy(f, 1, o, 0, 1);
    Array.Copy(f, 2, o, 3, 1);
    Array.Copy(f, 3, o, 2, 1);
    }
    Array.Resize(ref o, 8);
    Double ou = BitConverter.ToDouble(o,0);
    return ou;
    }

    Use the formula in the control channel – fRevers(1) Command type Standard, suitable for some Modbus devices.
    Or try to use this formula
    LINK

    { buf[1], buf[0], 0, 0, 0, 0, 0, 0 }

    and change the variable type on input
    ushort val = (ushort)Cmd;

    • This reply was modified 2 years, 4 months ago by Avatar manjey73.
    • This reply was modified 2 years, 4 months ago by Avatar manjey73.
    • This reply was modified 2 years, 4 months ago by Avatar manjey73.
    • This reply was modified 2 years, 4 months ago by Avatar manjey73.
    #2305
    Avatar
    roska
    Participant

    This doesn’t work as well. Now at least I know that if I turn on formula, that I can enter a “Value”, and not only “String” or “Hex”.
    But the device receives only garbage. I also tried some other formulas I found in the forum, but as the description is often Russian, I don’t understand the explainations.

    Receiving floats works without any problems, why is sending that complicated and requires messing around with formulas? 🙂

    #2306
    Avatar
    manjey73
    Participant

    The features of the processors other devices (Little Endian o Big Endian)
    Features of the sequence of bytes in the organization of the data transfer

    Well, we don’t all speak the same English 🙂
    I use online translation to learn examples in English as well as writing in the English forum.

    #2308
    Mikhail
    Mikhail
    Moderator

    roska, I tried to reproduce the problem.
    1. I added command into Modbus template: Holding Registers, Multiple, 2 elements
    2. Using Communicator GUI I sent a binary command in hex format: 429BC28F
    3. Data were sent:
    Send (17): 00 00 00 00 00 0B 01 10 00 64 00 02 04 42 9B C2 8F

    Registers value are: 0x429B (17051), 0xC28F (49807) according to http://modbus.rapidscada.net/

    Do you get another results if repeat the above sequence?
    (I use Modbus TCP, it doesn’t matter)

    #2309
    Mikhail
    Mikhail
    Moderator

    To covert a value entered manually into a command value you definitely need a formula. Because command value is a double (8 bytes), but you need to send only a single (4 bytes).

    #2310
    Avatar
    roska
    Participant

    Ok, now I got it. I checked the register values with ModbusPoll software, and noticed there was a combination of 2 problems: first of all, the the adress was shifted by 1, and the word-order wrong. In combination, I didn’t notice the mistake while reading the floats, because the values seemed reasonable. I just noticed, that it was wrong while trying to send floats. With the word order exchanged and shifting the adress, everything works. For receiving, I use the fRevers formula.

    Thank you all!

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.