BOOL ARRAY TO WORD ARRAY Schneider

Ranjith

Member
Join Date
May 2007
Location
Melbourne
Posts
316
I need to move a large Bool array to Word array in Schneider Control Expert.
Is there an easier way to do this?
For example: Bool[128] array to Word[8] array
My actual Bool array is [1024]
Thanks in advance.
 
Here's pseudo-code for a possibility. It assumes that the arrays begin with index 0 so it will need to be adjusted if you use index one (I'm a C programmer). It assumes that you have to do all the elements at one pass. It assumes that you are using structured text . It assumes that the result array is not allowed to go through temporary values during the execution of the pass.

Bits_In - ARRAY [0..127] of BOOL
Word_Out - ARRAY[0..7] OF WORD
Temp_Words - ARRAY[0..7] OF WORD
UINT Word_Loop, Bit_Loop;
WORD Or_Mask

(* Zero out the temporary array *)
FOR Word_Loop:= 0 to 7 BY 1 DO
Temp_Words[Word_Loop] = 0;
FOR Bit_Loop := 0 to 15 BY 1 DO
IF Bits_In[Word_Loop * 16 + Bit_Loop] == TRUE THEN
Or_Mask := 1;
IF Bit_Loop > 0 THEN
shift Or_Mask left Bit_Loop bits
END_IF;
Temp_Words[Word_Loop] := Temp_Words[Word_Loop] OR OR_Mask;
END_IF;
END_FOR;
Word_Out[Word_Loop] = Temp_Words[Word_Loop];
END_FOR;

You have to make sure the compiler uses a bitwise (not a logical) OR when you use the OR_Mask to turn the bit on.

This quickly given answer is not ready to go - it needs some research to be Schneider-specific. One advantage of it is that the method is mostly processor-independent so it can be easily modified for any CPU.

Eliminating the temporary buffer would give a little more speed. If the shift mechanism is guaranteed to behave itself with a count of zero the extra IF could be eliminated.
 
Copy bool to int and them aliasing maybe work for type conversion.

(or if you have %MW area for words them type same %MW addresses for words and int variables, and type conversion is done on %MW side without int_to_word conversion blocks on code side.)



Years ago I tested DDT to int and bools transfer, so extract block (should) also work.
http://plctalk.net/qanda/showthread.php?p=776365
 

Similar Topics

how to convert a bool array to word? for example I have the array bool variable with name test_arr[16]. How can assign it to the word variable...
Replies
3
Views
3,336
I received the following message via PM, and am posting here publicly to help others. ============================================ I had a...
Replies
10
Views
1,011
Hi, I must move an array of 16 Bool to an array of 2 USINT. I able to do this as attach pisture, but it's not cute! How I can do this with "COP"...
Replies
30
Views
12,001
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,408
Hi out there is it possible to Compare a bool array to a bool, in studio 5000. I'm think that if One of the bool's in my array is true, then i...
Replies
10
Views
6,338
Back
Top Bottom