Manipulating a DINT

gas

Member
Join Date
Nov 2005
Location
Erie, Pa
Posts
531
Using a 1769-L16ER-BB1B
We are receiving a DINT from an external device.
Then changing the sign using a SWPB order mode REVERSE
dest Dint_2
same rung COP to REAL
Next rung CPS to another tag


[SWPB(TEST_DINT,REVERSE,TEST_DINT_2),COP(TEST_DINT_2,TEST_REAL_VALUE,4)]; CPS(TEST_DINT,TEST_2_REAL_VALUE,4);

Please everyone weigh in and tell us what is wrong.
Thanks
 
SWPB does not change the sign, it re-orders the bytes.


Please show an example of the received DINT value, in decimal or preferably HEX/BCD, and what you think the real value should be; the nearest power of 2 (..., 16, 8, 4, 2, 1 0.5, 0.25, 0.125,...) will be good enough.


Then, if possible, send another value that is twice the first, and show the same information.


That should be enough to decode the issue.


Also, what is the external device, what protocol is in use, and where is a programming manual or similar?
 
Last edited:
Are you receiving 1 DINT or 4 DINTs? Because those COP and CPS instructions are trying to copy four DINTs to four REALs.
 
This is a great opportunity to get familiar with 2's Complement signed integers and 32-bit single-precision IEEE Floating Point, as well as with the SWPB, COP, and CPS instructions in ControlLogix. I've done this many dozens of times in my career and always have to get down to looking at raw bytes, often relying on trial-and-error to verify my assumptions.

Why do you think you have to "change the sign" ?

What sort of device does the DINT tag come from ? What data type are those 32 bits supposed to represent ?

It is very common to have to change the "endian" sense or high/low byte order of a value coming from an external system before converting a block of bytes into a REAL data type.

We definitely can't tell you "what is wrong" without an example of the actual raw data and the value you think it should represent.
 
At this point I'm not 100% sure ANYTHING is wrong. You never said what are really trying to accomplish. There are definitely some things that seem kind of odd. But maybe odd is what you are shooting for.

But I think the big one is the "4" in the COP and CPS. As drbitboy alluded to, that value is in destination elements, not bytes. I suspect you are corrupting some data with what you are doing.

Keith
 
Last edited:
Thank you all. We are waiting for the input device to arrive so we can do some real testing. The guy that wrote this code is a competent engineer and I am slogging thru Studio 5000.
I'll report back when we get all the components wired up.
 

Similar Topics

I have a barcode scanner reading bin labels and handing a string to an Laser Guided vehicle to place the bin in its appropriate location based on...
Replies
1
Views
1,264
Hello, Have aoi written in Ladder to pass in and out string variables. String VAriables that interact with PLC program are declared as InOut...
Replies
5
Views
4,305
Hello everyone. I have a quick question regarding dates in Structured text. What I´m trying to do is to take the current date, add/subtract days...
Replies
3
Views
1,624
Hi, I was wondering if you could help. I am using a Micrologix 1400 where I have an 11 digit number loaded in a L# data type (doubleword). This...
Replies
5
Views
3,011
I'm looking for a decent way to set independent statusbits of the statusword in simatic Step7. (CC0 - CC1 - OV - BR - etc...) When I want to set...
Replies
17
Views
3,377
Back
Top Bottom