Float to Integer and Vice Versa

learner

Lifetime Supporting Member
Join Date
Apr 2007
Location
British Columbia
Posts
81
Hi Guys,

I'm starting up a system overseas. I was given a PLC program which I know has some bugs.
The program was written in RSLOGIX 5000. The PLC is a Compactlogix.
I am receiving float numbers from DCS into arrays of integers (INT) in my PLC. Basically two integers for each float value.
The communication is done using MVI69-MCM. Therefore I have to use arrays of INT.

Could you please tell me how I can arrange the order of the bytes comming from DCS so I can interpret the values properly?

Also I need to reverse this process for sending my data from PLC to DCS.

Regards

Learner
 
You can use a COP Instruction to move the Data into a Float and the SWPB Instruction to get the Data in the right order. We had to do this with a ProSoft MVI56 Profibus system. The people we talked to at the manufacturer of the device we were reading couldn't tell us the order of the data, so it was just trial and error until we got it right. Hopefully, you can find out the order the DCS System is sending the Data in, or at least the IEEE format it uses. Once you figure out how to get the information from the DCS right, sending Data back should be the reverse.

Hope that helps.

Stu.....
 
HI Thanks for the response. Now this question might look silly, but I am just a little bit paranoid about how I can do this just by COP instruction. Could you please tell me how to copy two consecutive integers to a Real data type?
 
COP does a bitwise copy between the source and destination, the length of which is determined by the destination data type.

If you have an INT[10] array, you can COPy that into reals, using two INT's per real:

To copy to a single real:
COP INT[2] MyReal 1

To copy the array to 5 floats:
COP INT[0] MyRealArray[0] 5

You will have to check the endianness of the source and target values, and may have to swap the bytes of the ints around if needed. The empirical way to tell would be to generate a defined real, and copy it into a BYTE_ARRAY[4], then compare that to the same number received from your device into ANOTHER_BYTE_ARRAY[4], and see if the representation is the same.
 
I would suggest you download the Logix Instruction Set Manual from AB.
http://literature.rockwellautomation.com/idc/groups/literature/documents/rm/1756-rm003_-en-p.pdf

The COP Instruction does not convert Data Types. The Length Paramater is based on the Target Data Type. So, to move 2 Integers to 1 Float, in the Source put the Tag of the first Integer, for the Destination put in the Tag of your Float, and for Length a value of 1. You can do an entire Array this way, but make sure that you have the right two to one ration between the Source Integers, and Destination Floats. Both the Source and Destination must be contiguous memory locations.

Hope that helps.

Stu.....
 

Similar Topics

Hi. I'm using a Modbus ProSoft where I basically map data to a big INT array. Example, where GX_I_63HPU is a REAL, MNETC.DATA.WriteData[200] an...
Replies
21
Views
419
How do I convert a float to an integer? I've got a floating-point number D606, value 3999.863. I need to convert it to an integer (4000), then I...
Replies
14
Views
4,113
I can't quite figure out what the issue is here. I read some things about floating point integers and rounding and I assume that's my issue but...
Replies
13
Views
3,892
I have a Float that is F45:10 and I need to convert it to an integer to display on an HMI that is in VB.net and we can't change. I look on the AB...
Replies
8
Views
9,394
Hi all Why would The instruction [MOV s:37 F8:18] = 2015.0 in an (SLC 1747-L552C) and [MOV s:37 F191:0] = 55331E-034 in an (SLC 1747-L553) I...
Replies
13
Views
2,281
Back
Top Bottom