depending on what you need, you may not need the union.
You can always use the dot notation to access the bits in a word.
MyWord:WORD;Bit0:=MyWord.0;Bit1:=MyWord.1;
Not sure if this works with INT type but easy to try in simulation mode.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2015-10-02
Originally created by: scott_cunningham
BOOLs are stored as BYTE size in CoDeSys. Use bit level access as described by ndzied1. Either the util library or oscat.de library has pack/unpack functions you can use if you need to break apart a bit coded variable.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2015-10-02
Originally created by: ph0010421
Thank you both for the quick answers.
Have a good weekend.
Paul
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just for your information (not the best solution, but just as information what is possible):
You could create a structure of BITS (REGARD THE FACT THAT THEY ARE BIT AND NOT BOOL:
TYPESTR_BITS:STRUCTÂ Â x1:BIT;Â Â x2:BIT;Â Â x3:BIT;Â Â x4:BIT;Â Â x5:BIT;Â Â x6:BIT;Â Â x7:BIT;Â Â x8:BIT;Â Â x9:BIT;Â Â x10:BIT;Â Â x11:BIT;Â Â x12:BIT;Â Â x13:BIT;Â Â x14:BIT;Â Â x15:BIT;Â Â x16:BIT;END_STRUCTEND_TYPE
Then you can create a UNION containing the structure and the WORD:
TYPEUNION_BITS_WORD:UNIONÂ Â strBits:STR_BITS;Â Â wWord:WORD;END_UNIONEND_TYPE
Now it is possible to use the union with BIT/WORD access:
PROGRAMMainVAR  u1:UNION_BITS_WORD;  //Declarationofaunionvariable  xBool1:BOOL;      //justabool  xBool5:BOOL;      //justaboolEND_VAR//Assignsomevaluetothewordoftheunionu1.wWord:=16#F0F0;//GetthebitvaluefromthestructureofbitsandassignittoaBOOLxBool1:=u1.strBits.x1;xBool5:=u1.strBits.x5;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: ph0010421
Hello
How can I 'UNION' an INT with an ARRAY[0..15] of BOOL
Each 'BOOL' seems to take 1 byte...
Bit 0 is 1
Bit 1 is 256
...
Thanks
depending on what you need, you may not need the union.
You can always use the dot notation to access the bits in a word.
Not sure if this works with INT type but easy to try in simulation mode.
Originally created by: scott_cunningham
BOOLs are stored as BYTE size in CoDeSys. Use bit level access as described by ndzied1. Either the util library or oscat.de library has pack/unpack functions you can use if you need to break apart a bit coded variable.
Originally created by: ph0010421
Thank you both for the quick answers.
Have a good weekend.
Paul
Just for your information (not the best solution, but just as information what is possible):
You could create a structure of BITS (REGARD THE FACT THAT THEY ARE BIT AND NOT BOOL:
Then you can create a UNION containing the structure and the WORD:
Now it is possible to use the union with BIT/WORD access:
For this very reason I wish 3s would allow BIT as array type then you would be able to do the following
Since BIT is not allowed as a base type of an array this would not work. Can someone at 3s add a request?