UnityPro Bits of an array

PLCinfo

Member
Join Date
Oct 2005
Location
Melbourne
Posts
3
Hi all,

Probably a basic question to all, though one I'm struggling with myself.

Can someone please advise me of a simple way to write the code to set all the bits of an array in one step?? ie when an input is toggled the whole array "example[0..20]" is set to 1
Rather than having to set each bit seperately.

Hope thats understandable :-/
Thank you
 
Hello,

Anyone?

Is it possible to do what I'm hoping for?
I'd have thought so but I don't know the correct way to express it.

If someone has an idea on how I should be doing this, can they please point me in the right direction?

I'll try to rephrase what I'm asking:
Rather than having 21 lines of code using the same contact to set 21 outputs, is there a way to use the array expression in the output line of, say a 'set' block, to bring all the bits of the array on?
I don't know how to express the array variable for this purpose, in order to make it happen.

Hoping someone can be of assistance.

Thank you for any help you can offer.
Kind Regards.
 
Last edited:
Without looking into the Unity Help for the available functions, a FOR loop in structured test would do what you want in a couple of lines of code.

Do you need an array of bits? For 21 bits, how about use a DWORD, bit-packed. Now, you represent your digital state with example, but with a bit-packed word, you would use example.i to access an individual bit in the word (or double word).

In this case, to set all bits, just MOVe 16#FFFFFFFF into the DWORD. To reset, MOVe 16#0 into the DWORD.

Another way to have 'cleaner' code is your original method but do the 21 lines of set and/or reset in a subroutine. Just call this routine and it hides the ugliness of the 21 contacts.
 
Just checked Unity help - this should do what you need. From Help:


Function description
One of the actions of the MOVE_***_*** function is the assignment of an identical value to each element of an array.
The additional parameters EN and ENO can be configured.
Available functions
The available functions are as follows:
MOVE_BOOL_AREBOOL
...
 
If I understanded it right, this does the trick on Unity


First you have to configure bits to array and also you have to configure outputs to array variables.

so on variable editor create two array variables (addresses are examples)

bit0 array[0..21] of Ebool %M0
output0 array[0..21] of Ebool %Q0.2.0

Then you have to use copy_arebool_ardint block, if count is bigger than zero program sets all outputs to on state.


If you only want copy individual bits to outputs you can use copy_arebool_arebool block for this...


Check also from Tools->Project settings -> Variables that Allow dynamic Arrays and Directly represented array variales settings are in use.
 

Similar Topics

is it possible to external read the Forced_value list from a PLC using UnityPRO? I need to get this data. It could be via modbus, ops... or even...
Replies
5
Views
2,447
Hi, I'm wanting to write a rung that clears a whole output card (64 bits 4 words). I can do it in structured text for each individual bit but...
Replies
0
Views
1,315
Hi All, I'm new in UnityPro. Can you all guys help me on the UnityPro Programming? I need to create a Sequential Table (Recipe type format)...
Replies
7
Views
1,842
Can someone please help me to overcome the version issue of unitypro software. I was trying to transfer the program in to PLC and it throws this...
Replies
13
Views
3,676
Hi Everyone, Is there an RTO (Retentive Timer) function in UnityPro, or do I need to create the block on my own? Any tips would be appreciated...
Replies
1
Views
1,651
Back
Top Bottom