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

    Modbus, send REAL data

    Scheduled Pinned Locked Moved General Discussion
    2 Posts 1 Posters 2.3k 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.
    • 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

        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