Modbus, send REAL data

  • 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 ?


  • I find it!

    Modbus data order: 1234.
    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 !