A practical use of SWPB and CPS instructions in logix 5000

showshocka

Member
Join Date
Mar 2011
Location
USA
Posts
510
I understand the stated meaning of both and I see them being used in the project... can't quite figure out why they're being used. Can anybody give me an example of why these would be used in an operation.
 
Last edited:
SWPB is typically used when communicating to a different type of device that uses different encoding - i.e. in a Siemens PLC, the Most Significant Byte (MSB) is the second one, whereas in an Allen-Bradley, the MSB is the first one (reading from left to right). If you're receiving a value from a PLC with different encoding, it will be interpreted incorrectly unless you swap the bytes into the correct order. Here's a thread on another forum which documented very well the need for it (note: that forum seems to have some serious issues at the moment, and all the posts are displaying as the same post, but if it gets fixed, it's worth a look).

CPS is much the same as COP, only it's more rigorous in that it stops the data being changed partway through. For example, if you have a CLX, the I/O data and produced/consumed tags are updated asynchronously to the code - so if you're copying data from a produced/consumed tag or a physical I/O table, it could potentially change partway through execution of your COP instruction. This may or may not be a problem; it depends on your application. In most cases it doesn't really matter, but if it does you can use CPS. CPS will not allow anything else to interrupt it until it's finished copying, so you can be sure that your data was not changed partway through. In most cases, COP is just fine; if you have an application where you're copying from a produced/consumed tag and need to be 100% sure that you're copying a complete, "single-updated" data image, then perhaps a CPS is necessary.

Personally, I haven't ever found an application where a COP didn't do the job nicely, and seeing as CPS is much more processor intensive, I tend not to use them. Others prefer to use CPS regardless just to be sure of what they're doing.
 
Looks like ASF responded faster while I was pouring a scotch!

SWPB - Swap byte.
I have used when communicating to a Siemens PLC from an AB plc. The order of the bytes in the word are different. Big endian vs. little endian.
CPS - Synchronous copy.
Used when buffering IO data, this instruction maintains the consistency or integrity of the data when buffering IO.The data transfer is not interrupted.
 
SWPB is typically used when communicating to a different type of device that uses different encoding

That would make Sense, the SWPB is being used as part of a Profibus Network, where this sensor is communicating back to a computer.
 
I all most forgot..what I really need help in understanding is the "Length". Couldn't grasp that as much as the beginning part of the meanings for them.
 
The help file for each instruction does a pretty good job of explaining the length, but long story short; it's the number of elements the instruction will act upon.

e.g. COP Array_1[0] to Array_2[10] length 10 will copy Array_1[0] to Array_2[10], Array_1[1] to Array_2[11], Array_1[2] to Array_2[12]...through to...Array_1[9] to Array_2[19]. You specified a length of 10, so it copies 10 contiguous elements.

The biggest thing to remember here is that the length is in terms of destination elements. So if you're copying 16-bit data types into 32-bit data types, and you have a length of 10, it will copy the first two 16-bit source elements into the first 32-bit destination element, and then repeat 10 times. So you'll actually copy 20 16-bit elements into 10 32-bit elements. There are any number of threads on this if you go searching, because it's a fairly common mistake.
 

Similar Topics

I know I have some 12kW immersion heaters coming up for a job. I don't deal with these often, and I'm just trying to find a practical service...
Replies
6
Views
1,836
Hello Guys; I am new here. Also, New to the PLC so I took some college courses and also learning by myself. I came across GSV/SSV instructions...
Replies
2
Views
1,612
Hello everyone. I'm starting a new thread on the recommendation of RheinhardtP. This is a lengthy post, so bear with me. It's about disruption...
Replies
80
Views
36,818
Hi, I've been looking all over the web for practical examples of the devices used for real in SCADA devices :( . Could some of you share what you...
Replies
1
Views
1,457
Back
Top Bottom