Combining Consecutive Modbus Registers to read FLOAT

jbordelon
2012-12-12
2012-12-27
  • jbordelon - 2012-12-12

    Hi,

    I am using a 750-842 FBC to communicate with several other devices on a Modbus TCP network setup. I have a 352 Remote I/O, 2 Power Monitors through a Gateway, and a Generator controller.

    For some registers within the Power Monitors, The floating point value occupies 2 consecutive registers (i.e. 4002, 4003).

    How can I combine these two so that I can read the value? Im using the Ethernet_Modbusmaster_TCP function block to retrieve data from each of these devices.

    Thanks in advance,

    Jason

     
  • Strucc - 2012-12-13

    You can try something like:

    VAR
    Β  awWordsΒ  Β Β  Β : ARRAY[1..2] OF WORD;
    Β  pReal : POINTER TO REAL;
    Β  rReal : REAL;
    END_VAR
    awWords[1] := (* whatever code is needed to read the register *);
    awWords[2] := (* whatever code is needed to read the register *);
    pReal := ADR(awWords);
    rReal := pReal^;
    
     

    Related

    Talk.ru: 1
    Talk.ru: 2

  • jzhvymetal - 2012-12-27

    AT. Below are examples where the head address of the array is mapped to individual address for float variables.

    HOLD_REG AT %MW0: ARRAY[0..20] OF WORD;

    POS_X AT %ML0 : LREAL;
    POS_Y AT %ML1 : LREAL;
    POS_Z AT %ML2 : LREAL;
    POS_S AT %ML3 : LREAL;

    http://forum.codesys.com/viewtopic.php?f=2&t=5045

     
  • shooter - 2012-12-27

    %ML0 does not exist.
    if the float is same as real in definition you only have to do a dword_to_real

     

Log in to post a comment.