I am using a CMT-SVR-102 to read string data from an Omron CJ2M PLC, and then sending it out via the OUTPORT in a macro to a Free Protocol device. The issue is that the bytes in the string data appears to be swapped. So instead of “ABCD” I get “BADC”.
Is there a way to swap the bytes from within the macro?
There are functions within our API to swap the high or low byte / word. These functions and their usage is as follows:
SWAPW(): Swap the low word and high word of the specified value.
int source = 0x12345678, result
SWAPW(source, result) //result == 0x56781234
SWAPB(): Swap the low byte and high byte of the specified value.
short source = 0x1234, result
SWAPB(source, result) //result == 0x3412
SWAPB(0x12345678, result) //result == 0x34127856
Being that your question is related to the formation of STRING data, I believe that you are most likely working with a char array. In that case, you can reassign each element within that array to a new “temp” char used within the OUTPORT. Here is an example: