COP SINT to INT

jrsnydley

Member
Join Date
Dec 2014
Location
Minnesota
Posts
155
Hey guys, I am working on a project where I need to copy a SINT into an INT. I have a String that the operator inputs from the HMI. We'll call this My_String. So I have My_String.LEN = 4 and I am using a COP instruction to move My_String.Data[0] into My_Ints[0] with a length of 2. It works but it is backwards. I understand that I can use the SWPB instruction and move it to another Int to rearrange it. What I am wondering is why it gets reversed in the first place. Are bits 0-7 in the INT the high word and 8-15 the low word?

My_String[0] = 'A' which is moved to bits 0 - 7
My_String[1] = 'B' which is moved to bits 8 - 15

So why does it show up BA?
 
W/O knowing some more details I'll throw this out there, primarily because we dealt with something similar when migrating a PLC5 to a ControlLogix processor. After the ControlLogix migration, string data on an older PanelView had characters which were swapped in much the same manner you are describing.

From Wikipeida

Endianness[edit]
An architecture may use "big" or "little" endianness, or both, or be configurable to use either. Little endian processors order bytes in memory with the least significant byte of a multi-byte value in the lowest-numbered memory location. Big endian architectures instead order them with the most significant byte at the lowest-numbered address. The x86 architecture as well as several 8-bit architectures are little endian. Most RISC architectures (SPARC, Power, PowerPC, MIPS, ARM) were originally big endian, but many (including ARM) are now configurable.


In my case, the PLC5 "Edian" was different than the ControlLogix "Edian". I can't recall if the PLC5 was "big"/"little" or if the ControlLogix was "big"/"little", either case they were opposite, which created the byte swap thus character swap on the PanelView.
 
Last edited:
Followup see Technote 34814 as a reference to my previous post.

PLC5 - "Big" Endian (motorola processor)
Logix - "Little" Endian (intel processor)
 
The operator inputs the values into My_string from the HMI. For example: AB12. I copy this into My_Int[0] with a length of 2. So My_Int[0] bits 0-7 = A, My_Int[0] bits 8-15 = B, My_Int[1] bits 0-7 = 1 and My_Ints[1] bits 8-15 = 2. However, if I change the tag from decimal to ASCII, it shows My_Ints[0] = BA and My_Ints[1]=21. So with My_Int[0] = BA, shouldn't the value of My_Int[0] bits 0-7 = B? But that is not what it shows if I monitor the tag
 

Similar Topics

I am trying to copy an array of real numbers into a UDT with a real data type element. I have attached a snip below showing my COP instruction...
Replies
4
Views
203
Hello all. I have a Danfoss VLT feeding an INT into my CpLX program. I need to concatenate the MSB and LSB for position. I used a COP, making sure...
Replies
10
Views
641
Hello, I have been looking for a reference for the order that a UDT is copied in the COP instruction. More specifically - I have a set of code...
Replies
5
Views
548
I'm having to make an AOI to use with a generic ethernet device because the manufacturer does not provide an AOP. I just want to do a sanity check...
Replies
13
Views
1,260
We're converting a machine's control from CompactLogix to Micro800. It was originally going to be on a Micro850. However, because we've ended up...
Replies
2
Views
1,589
Back
Top Bottom