Boolean To Integer

MarkNightingale

Lifetime Supporting Member + Moderator
Join Date
Sep 2010
Location
In The VAT Shed
Posts
739
Hi,

I am trying to convert an array of Booleans into an integer so that I can use it to display a message on a SCADA system.
I have looked on all the knowledge bases and can't seem to find anything.
I am using RS Logix 5000 Version 17.

Thanks in advance

Mark
 
What format is the boolean array in? Is it just a direct bit to bit INT conversion? The COPY instruction should be able to directly copy the Boolean data into an INT location.
 
I have attached a screen grab of the controller tags and have highlighted the tag I want to convert to an integer.

I have tried using the copy command but the data types need to both be integers.

Thanks

Screen.jpg
 
If I were at work I'd be able to look around a bit deeper and test a few things out. But being as it's a Holiday weekend here in the States...

I thought Copy and Move could exchange data between different file types, but maybe they have to be the same level. Boolean data is a single bit, INT isn't. Maybe you have to copy (or move) them at the bit level?

(Mostly guessing right now, sorry).
 
64 bits would not convert to any basic data type. Exactly what do you expect to end up with? Do you have 1 bit on per message? Tell us exactly what you are trying to solve.
 
Last edited:
In the function block programming language there is a selected summer function that will add up to 8 values based on the status of 8 bools. So:

In1 = 1, Select1 = Array[0]
In2 = 2, Select2 = Array[1]
In3 = 4, Select3 = Array[2]
In4 = 8, Select4 = Array[3]
In5 = 16, Select5 = Array[4]
In6 = 32, Select6 = Array[5]
In7 = 64, Select7 = Array[6]
In8 = 128, Select8 = Array[7]

...then continue doubling In with another block for the second octet...

In1 = 256, Select1 = Array[8]
In2 = 512, Select2 = Array[9]
In3 = 1024, Select3 = Array[10]
In4 = 2048, Select4 = Array[11]
In5 = 4096, Select5 = Array[12]
In6 = 8192, Select6 = Array[13]
In7 = 16384, Select7 = Array[14]
In8 = 32768, Select8 = Array[15]

....and so on as needed.

Once you got all you blocks add their outputs together.
 
Sounds like he has an array of boolean data types called Step Indication that he wants to convert to an Integer to display something like a multi-state text display that would show what step the sequence is on.

I didn't pay too closely attention until now, but it may be that he just wants to identify what bit is on in the array and convert it to an Integer that his SCADA/HMI can use. So the integer file would be 0-63 depending on what step in the sequence it is on.

Personally I would just go the long way and move a number into an integer file based on what bit is true. Probably not the most efficient way, but I would weigh the time it takes to find more efficient way and the ease of understanding that way by someone who didn't program it later in the machine's life. And the ease of modification later of the sequence display, what if you wanted to display two or more messages based on boolean number 10's state and the state of the machine.
 
Tharon,

Thats exactly what I want to do. When the program is in say step 7, bit number 7 is true and all the others are false. I then want to use this value in my SCADA to display what the current step is doing

I just thought there might be a quicker way of transferring those bits into an integer so it makes the code look tidier, because there are 12 different programs with varying numbers of steps.

Thanks for your advice.

Mark
 
OK, create a tag named Current_Stage.

Create a subroutine which is called every scan.
The subroutine contains the following logic:


  • If array[Current_Stage] is true then exit

  • Current_Stage = Current_Stage + 1

  • If Current_Stage > 63 then Current_Stage = 0

Have the display monitor Current_Stage
 
In my example, if the slight flickering of the display as a search progresses, especially if the current ON bit changes to a lower one, then:

Create a Display_Stage tag

Modify this step to read -

If array[Current_Stage] is true then Display_Stage = Current_Stage; exit

and have the display monitor Display_Stage.
 
Mark, just above your ringed BOOL array, there is an INT called Step_No.

Doesn't this contain what you need ?
 
Having taken another look at your screenshot - I notice that you have Forces enabled.

Admittedly you don't have any forces installed, but the "enabled" status means that any force you apply to a digital or analog I/O wil take effect immediately, and, without warning !.

The safest position to leave the controller in is with all forces removed, and disabled.

In RSLogix5000, manually removing the last force does not disable forces, like it does for RSLogix500 and RSLogix5. However, if you use the "Remove all forces" option from the drop-down menu, then they will be disabled as well.
 
Having taken another look at your screenshot - I notice that you have Forces enabled.

Admittedly you don't have any forces installed, but the "enabled" status means that any force you apply to a digital or analog I/O wil take effect immediately, and, without warning !.

The safest position to leave the controller in is with all forces removed, and disabled.

In RSLogix5000, manually removing the last force does not disable forces, like it does for RSLogix500 and RSLogix5. However, if you use the "Remove all forces" option from the drop-down menu, then they will be disabled as well.

Can you even disable forces? In the Micrologix processors I cannot disable forces globally (I can in the SLC500 series). I have never tried it in 5000, I only have one machine and never use forces on it.

Personally I don't see any issue with it being Enabled but none installed. Since the Micrologix processors have to stay that way.
 
I can't think of a better way than Tharon suggests, inspect each bit, and move the corresponding step value....

Why not make this an add-on instruction....?

I'll take a look at this, and try to optimise it for speed of execution....
 

Similar Topics

Have beginner knowledge of digital controls, and intermediate/advanced knowledge of socket clients and listeners (written logging proxies, socket...
Replies
9
Views
3,726
Hi, I need to decode the integer value to boolean and store the each bit of 16bits in different variable of boolean type and to be used in the...
Replies
7
Views
2,449
Hi, I need to decode to the integer value to boolean and store the each bit of 16bits in different variable of boolean type and to be used in the...
Replies
2
Views
3,417
Hi, Is there a boolean to integer conversion for the GE 90-30 PLCs? I want to determine how many fans are running, (%I1 - 20). I was going to...
Replies
2
Views
2,944
Hi. I haven't touched an Allen Bradley PLC for more than 10 years and I'm kind of rusty. I want to do something really simple in a FBD section...
Replies
5
Views
846
Back
Top Bottom