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

    Modbus, send REAL data

    General Discussion
    1
    2
    1498
    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.
    • G
      Giamba last edited by

      Hi,
      I have some real values to send via modbus from Mervis.
      Since REAL take 4 bytes, REAL should take two registers.
      How can I combine the two registers values to make one real value in C program ?

      regards.

      1 Reply Last reply Reply Quote 0
      • G
        Giamba last edited by

        I find it!

        Modbus data order: 1234.
        Example:
        In C program header:

        typedef unsigned long DWORD;
        typedef unsigned short WORD;
        union u_DWORD_TO_FLOAT{
            DWORD i;
            float f;
        };
        

        and in the code:

        union u_DWORD_TO_FLOAT AI01;
        ...
        AI01.i = (mb_mapping->tab_registers[20] << 16) + mb_mapping->tab_registers[21];
        float value = AI01.f;
        

        Hope this help someone !

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