Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Real to Dword

niangoto
2015-03-28
2015-03-30
  • niangoto - 2015-03-28

    Hello. I must represent real value as 4 bytes. I am doing this as follows:

    Real_var   AT  %MD0: REAL;
    Word_var  AT  %MD0: DWORD;
    

    For instance if Real_var=5, then Word_var =16#40A00000.
    Does someone know more elegant way to doing this?

     
  • shooter - 2015-03-29

    it depends on what is next step. and yes it works

     
  • niangoto - 2015-03-30

    shooter hat geschrieben:
    it depends on what is next step. and yes it works

    next step is:

    Array_of_byte[1]:= WORD_TO_BYTE(Word_var);
        Array_of_byte[2]:= WORD_TO_BYTE(SHR(Word_var,8));
        Array_of_byte[3]:= WORD_TO_BYTE(SHR(Word_var,16));
        Array_of_byte[4]:= WORD_TO_BYTE(SHR(Word_var,24));
    
    CANOPEN_SDOWRITE_real(
    EXECUTE:= execute,
    CHANNEL:= 1,
    NODE:= slave_node,
    IDX:= index,
    SUBIDX:= subindex,
    LEN:= 4,
    DATA:= Array_of_byte,
    Timeout:= t#200ms,
    RESULT=> );
    
     
  • shooter - 2015-03-30

    check oscat.de he made special communication functions.
    also for canopen

     

Log in to post a comment.