BOOL array to USINT

I’m onboard this.

Sory for delay...

It's a array on 16 bool to convert to an array of 2 USINT.

Also I need to copy of 1 INT to an array of 16 Bool.

I'm not able to do this with COP inctruction.

I modyfy a little bit the code... The code is now:

Code:
//Pour les sorties, permet de passer un tableau de binaire BoolArray[0..15] en 1 
tableau de 2 variable USINT Datatologix
*/
Datatologix[1] := 0;
Datatologix[2] := 0;
FOR i := 0 to 7 DO
  IF Output[i] THEN // Si le bit est vrai
   Datatologix[1] := Datatologix[1] + ANY_TO_USINT(EXPT(2.0,i)); //Le I represente la valeur de exposant de 2
  END_IF;
  IF Output[i+8] THEN // On fait la même chose pour les bits de 8 a 15
   Datatologix[2] := Datatologix[2] + ANY_TO_USINT(EXPT(2.0,i));
  END_IF;
END_FOR;

/* Pour les entrées, la variable INT_InputLogix dans un tableau de binaire Input[0..15] 
pour facilité le travail */
For i:=0 to 15 DO
 Mem_INT_InputLogix:= SHR(ANY_TO_DINT(INT_InputLogix), i); // Décale les bits à droite
 Mask:= AND_MASK(Mem_INT_InputLogix, 1); // Vérifie le bit de poids faible seulement
 If Mask.0 THEN // Inscrit 0 ou 1 selon le niveau du bit
  Input[i]:= TRUE;
 ELSE
  Input[i]:= FALSE;
 END_IF;
END_FOR;

Thank you
 
Code:
/* Pour les entrées, la variable INT_InputLogix dans un tableau de binaire Input[0..15] 
pour facilité le travail */
For i:=0 to 15 DO
 Mem_INT_InputLogix:= SHR(ANY_TO_DINT(INT_InputLogix), i); // Décale les bits à droite
 Mask:= AND_MASK(Mem_INT_InputLogix, 1); // Vérifie le bit de poids faible seulement
 If Mask.0 THEN // Inscrit 0 ou 1 selon le niveau du bit
  Input[i]:= TRUE;
 ELSE
  Input[i]:= FALSE;
 END_IF;
END_FOR;


Ah, I missed the other way around. What if you try this:
Code:
 FOR i := 0 TO 15 DO
  Input[i] := ANY_TO_WORD(INT_InputLogix) AND SHL(1, i);
END_FOR;
 
Ah, I missed the other way around. What if you try this:
Code:
 FOR i := 0 TO 15 DO
  Input[i] := ANY_TO_WORD(INT_InputLogix) AND SHL(1, i);
END_FOR;

I try the code , but it give me an error... The expression :

"ANY_TO_WORD(INT_InputLogix) AND SHL(1, i);" it's not a boolean, say CCW... I dont find how to correct the problem.

I don't know why it's difficult to work with bit in CCW. I need only the bit that OUT...

Thank a lot for your help, if you have a other idea, I try it!
 
I was assuming anything > 0 would have been TRUE but it seems no. Then maybe the longer will do:

Code:
FOR i := 0 TO 15 DO
  Input[i] := FALSE;
  IF (ANY_TO_WORD(INT_InputLogix) AND SHL(1, i)) > 0 THEN
    Input[i] := TRUE;
  END_IF;
END_FOR;


Edit, try this one first:
Code:
FOR i := 0 TO 15 DO
  Input[i] := (ANY_TO_WORD(INT_InputLogix) AND SHL(1, i)) > 0;
END_FOR;
 
Last edited:
Assumes LSBit first, and still ugly:
Code:
TYPE THE_UNION:
  UNION
    aint : INT;
    audint : UDINT;
  END_UNION
END_TYPE
VAR
  ints : THE_UNION;
END_VAR;
...
ints.audint := 1;
FOR i := 0 TO 15 DO
  Input[i] := ANY_TO_BOOL(INT_InputLogix AND ints.aint);
  ints.audint := ints.audint * 2;
END_FOR;
...
 
I was assuming anything > 0 would have been TRUE but it seems no. Then maybe the longer will do:

Code:
FOR i := 0 TO 15 DO
  Input[i] := FALSE;
  IF (ANY_TO_WORD(INT_InputLogix) AND SHL(1, i)) > 0 THEN
    Input[i] := TRUE;
  END_IF;
END_FOR;


Edit, try this one first:
Code:
FOR i := 0 TO 15 DO
  Input[i] := (ANY_TO_WORD(INT_InputLogix) AND SHL(1, i)) > 0;
END_FOR;

I try two code but, always the problem of " No binary instruction"...

drbitboy said:
Code:
Assumes LSBit first, and still ugly:
Code:
TYPE THE_UNION:
  UNION
    aint : INT;
    audint : UDINT;
  END_UNION
END_TYPE
VAR
  ints : THE_UNION;
END_VAR;
...
ints.audint := 1;
FOR i := 0 TO 15 DO
  Input[i] := ANY_TO_BOOL(INT_InputLogix AND ints.aint);
  ints.audint := ints.audint * 2;
END_FOR;

My version of CCW not permit to make a data type (UDT) variable

Thank you!
 
Code:
 VAR
   aint : INT;
   i : INT;
 END_VAR;
 ...
Input[15] = INT_InputLogix < 0;
aint := 16384;
FOR i := 0 TO 14 DO
   Input[14-i] := ANY_TO_BOOL(INT_InputLogix AND aint);
   aint := aint / 2;
END_FOR;

Still ugly. I assume ST has some way to run a FOR loop index backwards, but I can't be bothered to look it up.
 
Whoops; the binary AND operator does not do bit-wise and-ing, and I think AND_MASK works on DINTs only.

Code:
  VAR
   adint : DINT;
   i : INT;
 END_VAR;
 ...
adint := 1;
FOR i := 0 TO 15 DO
   Input[i] := ANY_TO_BOOL(AND_MASK(ANY_TO_DINT(INT_InputLogix),adint));
   adint := adint * 2;
END_FOR;
Still ugly.
 
Last edited:
I try two code but, always the problem of " No binary instruction"...

Whoops; the binary AND operator does not do bit-wise and-ing, and I think AND_MASK works on DINTs only.


Oh for the love of god, that explains alot.
Since i havent used CCW i looked quickly at the Codesys help for reference of the AND operator and they support bitwise operation on WORD data type.


Maybe try this instead pasbra:
Code:
FOR i := 0 TO 15 DO
  Input[i] := (ANY_TO_DINT(INT_InputLogix) AND SHL(1, i)) > 0;
END_FOR;

or

FOR i := 0 TO 15 DO
  Input[i] := FALSE;
  IF (ANY_TO_DINT(INT_InputLogix) AND SHL(1, i)) > 0 THEN
    Input[i] := TRUE;
  END_IF;
END_FOR;
 
Maybe try this instead pasbra:
Code:
FOR i := 0 TO 15 DO
  Input[i] := (ANY_TO_DINT(INT_InputLogix) AND SHL(1, i)) > 0;
END_FOR;

or

FOR i := 0 TO 15 DO
  Input[i] := FALSE;
  IF (ANY_TO_DINT(INT_InputLogix) AND SHL(1, i)) > 0 THEN
    Input[i] := TRUE;
  END_IF;
END_FOR;

The expression: (ANY_TO_DINT(INT_InputLogix) AND SHL(1, i)) it's not permit!

drbitboy said:
Code:
adint := 1;
FOR i := 0 TO 15 DO
   Input[i] := ANY_TO_BOOL(AND_MASK(ANY_TO_DINT(INT_InputLogix),adint));
   adint := adint * 2;
END_FOR;
This code work properly and it's "cute"

drbitboy and ojz0r, your have a great idea!:geek:

Thank you!
 
Code:
FOR i := 0 TO 15 DO
  Input[i] := (ANY_TO_DINT(INT_InputLogix) AND SHL(1, i)) > 0;
END_FOR;
@ojz0r's approach (above) is the best, however it needs to be
Code:
FOR i := 0 TO 15 DO
  Input[i] := AND_MASK(ANY_TO_DINT(INT_InputLogix),SHL(1, i)) <> 0;
END_FOR;
To work with the Fisher-Price, I mean with the Connected Components Workbench, software.
 
Code:
 VAR
   aint : INT;
   i : INT;
 END_VAR;
 ...
Input[15] = INT_InputLogix < 0;
aint := 16384;
FOR i := 0 TO 14 DO
   Input[14-i] := ANY_TO_BOOL(INT_InputLogix AND aint);
   aint := aint / 2;
END_FOR;

Still ugly. I assume ST has some way to run a FOR loop index backwards, but I can't be bothered to look it up.
While loop. It's also more compact from a memory POV.
 
My question is:
Why does the OP have a BOOL[15] datatype in the first place? Bool arrays are fairly useless, and if you really need to reference a bit by a pointer (which is main thing one would use a BOOL array for) without regard to word boundaries imposed by integer datatypes, that can be done by addressing contacts and coils like so:

SintArray[(IDX AND NOT 15)/16].[IDX AND 15]
 
My question is:
Why does the OP have a BOOL[15] datatype in the first place? Bool arrays are fairly useless, and if you really need to reference a bit by a pointer (which is main thing one would use a BOOL array for) without regard to word boundaries imposed by integer datatypes, that can be done by addressing contacts and coils like so:

SintArray[(IDX AND NOT 15)/16].[IDX AND 15]

I post shortly a new post for read and write data to compact Logix and where i use this. I find that it's more simple for user... Also, I like use Bool array, when I make "Sequentiel fonctionnal Chart" (SFC). One bool array for a SFC.

Your solution: SintArray(1).IDX seems simple, and I try it, but with CCW its not possible, if no mistake, to have an IDX after "."

It is possible, to write this: SintArray(1).0 but not SintArray(1).IDX even if IDX=0...

It's very bad!
 

Similar Topics

I received the following message via PM, and am posting here publicly to help others. ============================================ I had a...
Replies
10
Views
1,025
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...
Replies
4
Views
1,353
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,442
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,376
We are using an array of bools for our fault code logic, and I need to reset all the bits in the array when the operator presses the fault reset...
Replies
2
Views
2,146
Back
Top Bottom