Unity Pro array bit level

ddear

Member
Join Date
Aug 2013
Location
York, Pa
Posts
4
I created an DINT array in Unity Pro. How do I get to the bit level?
DINT_rcv expands to DINT_rcv[0] & DINT_rcv[1] but I want to address a bit at DINT_rcv[0].0
 
i don't think you can with any 32-bit types. dword doesn't work either. you would have to use 16 bit INT or WORD in your array.

the WORD_AS_DINT and DINT_AS_WORD blocks might help if you want to make a function block that takes a DINT as an INOUT, bit index as input, and true false value to set at the index as input, and then sets the bit within the DINT by converting it to two words, setting the bit in the word, and then re-builds the DINT from the two words.
 
You can do it as VON_Hydro explains.
Another way is to make DINT variable as located

ex. DINT_rcv = %MW0 DINT (uses %MW0 and %MW1 addresses)

Then make
Dint_Rcv_LSB %MW0 int
Dint_Rcv_MSB %MW1 int

Now you can use LSB and MSB integer variables with bit commands. All variables have same %MW addresses, so they get copied directly to your dint-variable "on backside" without need of any conversion blocks.


3rd method maybe could be to make DFB block, make inout variable for DINT, also make 32 in/out variables of (e)bool to block.
Inside block separate dint to bool ariables and concentrate back?
 
Last edited:
Working DFB could be without any %MW addresses.

MD_M_MD -conversion

Make first dint variable as pin1 (Dint_var)
To second pin make array of ebools variable (array [0..31] of ebools as in/out pin (arr_of_bools)

Inside of block make code

First count bit sum of ebools. Simplest for this is conversion move_arebools_to_dint

As output you have counted bit sum of 32bools now. (bool_sum-variable)

Then make couple compares

if bool_sum <> sum_old then
Dint_var := move_arebools_to_dint(arr_of_bools);
sum_old:=bool_sum;
END_IF;

if dint_var <> sum_old then
arr_of_bools=move_dint_to_arebools(Dint_var);
sum_old:=dint_var;
END_IF;


That is all. If you now make and connect Dint and array of bools -variables to DFB-pins, you can change bit values of bools and Dint is updated or if you change dint_value, bool variables are updated.
This don't need to be necessary IL or ST , writed only with ST- because it was easier to write here than function blocks. It works with all program languages.
From project settings you need to select directly present arrays, disable array compatibility check and other array settings. I assume that you have selected them allready.
 
Last edited:

Similar Topics

Hi, Unity has the option to index its arrays between any two numbers; e.g. "ARRAY[13..27] OF INT". I am writing a DFB which needs to take in a...
Replies
3
Views
2,336
I am trying to make a function that count the number of True BOOL inn a specific Array and return the count to an INT AlarmArrayActiveAlarms. I...
Replies
8
Views
4,344
I am using Unity Pro XL 4.1 and have a question. I am used to programming on Allen Bradley and this was possible in ControlLogix. I have 16...
Replies
2
Views
5,032
in unity ,every time when i call a fb,it makes a instance of this fb,i want to define an array instance of a fb,but i don't know if it's permitted ?
Replies
9
Views
4,364
Hello, I am using Unity pro V15. I have Quantum CPU 671 and Ethernet NOE 77101 configured. I have configured IO scanning on NOE. I have attached...
Replies
5
Views
136
Back
Top Bottom