How to Swap two Bytes in a word ?

2010-07-16
2023-06-21
  • thetripathi - 2010-07-16

    Hello All,
    I have just joined this forum and I would to say hello to all the members. I hope I will get lot of information here.
    I am using ABB AC500 PLC and Vekio Citec 7.1 for my application. The software platform is obviously CodeSys 2.3. Whenever I am transferring a word to the HMI,it is swapped i.e. Hi word comes as Lo word and vice versa. I guess I need to write a code into CodeSys to swap the word before sending it to the HMI. Can anyone help me out as to how to write the swapping code in codesys ?

    Thanks in advance

     
  • shooter - 2010-07-16

    got it from oscat.de

    swap_byte :=ROL(inword,8);
    it is rolling over 8 bits just what you want.

     
  • Anonymous - 2010-08-09

    Originally created by: Mikhail Shvetsov

    shooter hat geschrieben:
    got it from oscat.de
    swap_byte :=ROL(inword,8);
    it is rolling over 8 bits just what you want.

    it'snot necessary to use oscat for this function. it's usual function from CoDeSys

     
  • shooter - 2010-08-09

    yes i do know but i like to advertise with oscat.
    just because i like it.

     
  • Anonymous - 2010-08-10

    Originally created by: Mikhail Shvetsov

    shooter hat geschrieben:
    yes i do know but i like to advertise with oscat.
    just because i like it.

    Otherwise it seems like CoDeSys can nothing without Oscat )

     
  • DreamWorks - 2023-06-21

    VAR
    Test1:WORD;
    Test2:Word;
    END_VAR

    Test2:=MEM.ReverseBYTEsInWORD(Test1);

     
  • DreamWorks - 2023-06-21

    VAR
    Test1:WORD;
    Test2:Word;
    END_VAR

    Test2:=MEM.ReverseBYTEsInWORD(Test1);

     
  • DreamWorks - 2023-06-21
     

    Last edit: DreamWorks 2023-06-21

Log in to post a comment.