Hi everybody,
I have a struct below and would like to copy in an array (8) but I have a problem because of bools use 1 byte area in memory. This results data loss in array. How can I copy all struct value to array without data loss?
Do you have any method?
When I convert only one BOOL variable to BIT, it allocates 1 bit area in memory.It works as I need. But when tried to convert ARRAY OF BOOL to ARRAY OF BIT, it is not allowed by Codesys. I need same usage for ARRAYs.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everybody,
I have a struct below and would like to copy in an array (8) but I have a problem because of bools use 1 byte area in memory. This results data loss in array. How can I copy all struct value to array without data loss?
Do you have any method?
~~~~~~~~~~~~~~~~~~~~~~~~STRUCT~~~~~~~~~~~~~~~~~~~~~~~~~
TYPE test :
STRUCT
bool1: ARRAY[0..1] OF BOOL;
bool2: ARRAY[0..2] OF BOOL;
bool3: BOOL;
bool4: BOOL;
bool5: BOOL;
bool6: ARRAY[0..5] OF BOOL;
bool7: BOOL;
bool8: BOOL;
word1: WORD;
word2: WORD;
byte1: BYTE;
byte2: BYTE;
END_STRUCT
END_TYPE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~ARRAY~~~~~~~~~~~~~~~~~~~~~~~~~
byte_array: ARRAY [0..7] OF BYTE;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
the BIT datatype actually takes 1 bit, but it can't be in an ARRAY. That may work for you?
When I convert only one BOOL variable to BIT, it allocates 1 bit area in memory.It works as I need. But when tried to convert ARRAY OF BOOL to ARRAY OF BIT, it is not allowed by Codesys. I need same usage for ARRAYs.