Codesys v3.5 reading registers problem

mk21y
2023-03-24
2023-03-24
  • mk21y - 2023-03-24

    Hello
    I'm using codesys v3.3 to meassure the values of a SENECA (S604E-6-MOD) wattmeter, but while reading the values for the Phase 3 current, i'm getting wrong values, the reason being that when I input the holding register (HEX: 1012) it shows the wrong values (it reads 2 registers 1012 and 1013) and the when I input a value (HEX: 1013) it reads 2 registers 1013 and 1014 but the problem is that the 1014 register is the register for Neutral current. Is there any way to combine the register or switch the order of reading them ( ex. first read 1013 and then 1012)?
    (the value of the Phase 3 current should be ⁓1.250)

     

    Last edit: mk21y 2023-03-24
  • RasPi-User - 2023-03-24

    Hello
    you can use a union to swap the words

    code
    

    UNION
    RealValue : REAL;
    MbValue: ARRAY[0..1]OF WORD;
    END_UNION
    END_TYPE

    Here is a function to convert two Mb-Words in a Real-Value.

    code
    

    FUNCTION F_MbConvert : REAL

    VAR_INPUT
    MbWord0: WORD; // ModBus-Register 1
    MbWord1: WORD; // ModBus-Register 2
    SwapWord: BOOL; // true = swapping MbWord0 <-> MbWord1
    END_VAR

    VAR
    _uMbValue: uModBusValue; // Union
    END_VAR

    IF SwapWord THEN
    _uMbValue.MbValue[0] := MbWord1;
    _uMbValue.MbValue[1] := MbWord0;
    ELSE
    _uMbValue.MbValue[0] := MbWord0;
    _uMbValue.MbValue[1] := MbWord1;
    END_IF

    F_MbConvert := _uMbValue.RealValue;

    Reinhard

     

    Related

    Talk.ru: 1

    • mk21y - 2023-03-24

      Hello,
      Thank you for the help. I'm new to codesys so i'm a little confused when doing these programs. Can I ask you to send me a screenshot of the code and ladder connection? Thank you again for the help πŸ˜ƒ .

       
  • RasPi-User - 2023-03-24

    Hello,
    here is a small test project. The MB slave is just a dummy, you have to insert your slave. The main program is the PLC_PRG, it calls the Prg KOP.
    Greetings Reinhard

     

Log in to post a comment.