Industry Automation and Control Forum
This forum is addressing industrial automation design & engineering, operations, asset performance, cyber security and digital transformation for Plants & Machines.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-07-29 02:29 AM
Hi,
I am looking for a Function can Swap Bytes of INT or DINT
AB => BA
or
ABCD => DCBA
Is there a function that can do this except for SWAP_ARINT, SWAP_ARWORD, as these are using Arrays
Thanks
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-07-29 06:58 AM
Here are some function from OSCAT libraries that you can adapt for what you need.
FUNCTION SWAP_BYTE : WORD
VAR_INPUT
IN : WORD;
END_VAR
SWAP_BYTE := ROL(in,8);
FUNCTION SWAP_BYTE2 : DWORD
VAR_INPUT
IN : DWORD;
END_VAR
SWAP_BYTE2 := (ROR(in,8) AND 16#FF00FF00) OR (ROL(in,8) AND 16#00FF00FF);
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-07-29 06:58 AM
Here are some function from OSCAT libraries that you can adapt for what you need.
FUNCTION SWAP_BYTE : WORD
VAR_INPUT
IN : WORD;
END_VAR
SWAP_BYTE := ROL(in,8);
FUNCTION SWAP_BYTE2 : DWORD
VAR_INPUT
IN : DWORD;
END_VAR
SWAP_BYTE2 := (ROR(in,8) AND 16#FF00FF00) OR (ROL(in,8) AND 16#00FF00FF);
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2024-07-29 10:15 AM
Which PLC did you use, if the PLC support ST the example from Adrian should work fine.
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.