Convert ints to a dint – Rockwell Automation Logix5000 Controllers Controller Information and Status Programming Manual User Manual

Page 22

Advertising
background image

Chapter 2 Determine controller memory information

Convert INTs to a DINT

The MSG instruction returns each memory value as two separate INTs.

The first INT represents the lower 16 bits of the value.

The second INT represents the upper 16 bits of the value.

To convert the separate INTs into one usable value, use a

Copy (COP) instruction.

In this operand

Specify

Which means

Source

First INT of the 2 element pair
(lower 16 bits)

Start with the lower 16 bits.

Destination

DINT tag in which to store the 32-
bit value

Copy the value to the DINT tag.

Length

1

Copy 1 times the number of bytes in the Destination data

type. In this case, the instruction copies 4 bytes (32 bits),
which combines the lower and upper 16 bits into one 32-
bit value.

In the following example, the COP instruction produces the 32-bit value that

represents the amount of free I/O memory, in 32-bit words.

Example:

Convert INTs to a DINT.

Elements 3 of INT_array is the lower 16 bits of the amount of free I/O memory. Element 4 is the

upper 16 bits.

Memory_IO_Free is a DINT tag (32 bits) in which to store the value for the amount of free I/O

memory.

To copy all 32 bits, specify a Length of 1. This tells the instruction to copy 1 times the size of the

Destination (32 bits). This copies both element 3 (16 bits) and element 4 (16 bits) and places the 32-
bit result in Memory_IO_Free.

22

Rockwell Automation Publication 1756-PM015F-EN-P – October 2014

Advertising