Sign in to follow this  
Followers 0
banker

Swap bytes

9 posts in this topic

Hi Can somebody help me, I have to swap some bytes. I have made commonication with a weighing transmitter via profibus. The weight signal is a 32 bit Dint signal. But i have to swap the bytes (4) as followring: SWAP DINT Byte O MSB Byte 3 Byte 1 ---------------> Byte 2 Byte 2 Byte 1 Byte 3 LSB Byte 0 I'am using a CJ CPU. Regards, Banker

Share this post


Link to post
Share on other sites
Use the SWAP function. You can specify the starting word and how many words and the function will swap the bytes for you. The last time I used it I specified quite a large block of words and it worked fine. Now if there was a similar swap word function zzzzzzzzzzz. Yes I can use transfer but it is messy and swap word would be much much easier!!!!!

Share this post


Link to post
Share on other sites
?ou have right is much easier using swap function but CPM1A-CPM2A do not supprort this function!

Share this post


Link to post
Share on other sites
Correct, only CJ1 and CS1 - latest processors - maybe CP1 - have not used one yet.

Share this post


Link to post
Share on other sites
Bobb.... seen the XCHG and the XCGL functions Bob fro the CJ's .. ?

Share this post


Link to post
Share on other sites
Been there done that Sleepy. Not smart enough - SWAP allows start word and how many words in the one instruction. XCHG only allows 2 words and XCGL only allows 2 long words. Pain in the "A" if you have to swap 40-50 words. Come on Omron - a smarter XCHG would be most welcome!!!!

Share this post


Link to post
Share on other sites
... Bob, You could use a for - next loop with XCHG, IR registers (ir+ etc), would do 40 - 50 words easy, with a few rungs of code ... ?? The Code below swaps 40 words ... (Do admit that XCHG would probably be handier if it operated more like SWAP) Nibroc Edited by Nibroc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0