BoolArray[0]:=Byte.0;  BoolArray[1]:=Byte.1;  BoolArray[2]:=Byte.2;  BoolArray[3]:=Byte.3;  BoolArray[4]:=Byte.4;  BoolArray[5]:=Byte.5;  BoolArray[6]:=Byte.6;  BoolArray[7]:=Byte.7;
TYPEMyPumpCmd_STRUCT:STRUCTÂ Â Bit0:BIT;Â Â Bit1:BIT;Â Â Bit2:BIT;Â Â Bit3:BIT;Â Â Bit4:BIT;Â Â Bit5_Run:BIT;Â Â Bit6_Reverse:BIT;Â Â Bit7_QuickStop:BIT;END_STRUCTEND_TYPE
TYPEMyPumpCmd_UNION:UNIONÂ Â aByte:BYTE;Â Â aStruct:MyPumpCmd_STRUCT;END_UNIONEND_TYPE
VAR_GLOBALÂ Â MyPumpCmd:MyPumpCmd_UNION;END_VAR
Then, usage :
MyPumpCmd.Bit5_Run:=TRUE%OB5:=MyPumpCmd.aByte
EDIT 2019/01/21: Correct "Bit3 : BOOL;" to "Bit3 : BIT;"
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks dFx. I learned something new but there was one issue I ran into when testing this. When you specified BOOL for Bit3 it causes it to not work. All data types appear to have to be BIT in order for the union to work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Originally created by: Le_Baloo
Hello all,
Have you got any ideas of how i can convert byte into an array in order to read and access to the datas ?
Thanks for your help
Byte into an bit array ? Then declare a union datatype with Byte and your bits (named into a DUT or in array)
Originally created by: ph0010421
I don't think that will work.
You can't make an array of BIT, and a BOOL occupies 8 bits, so it won't align.
There's probably an OSCAT block, but I can never find anything I want in OSCAT
I'd just:
A union would be nice but believe this doesn't work because of what Le_Baloo said. Been a while since I have tested it though.
What if you just use the UNPACK function. Input would be your byte and the output could tie each bit to your array.
https://help.codesys.com/webapp/unpack;product=codesys;version=3.5.11.0
Or you could do it by hand.
Related
Talk.ru: 1
Talk.ru: 2
Talk.ru: 3
Talk.ru: 5
Talk.ru: 7
So if you want to name it, declarations :
Then, usage :
EDIT 2019/01/21: Correct "Bit3 : BOOL;" to "Bit3 : BIT;"
Thanks dFx. I learned something new but there was one issue I ran into when testing this. When you specified BOOL for Bit3 it causes it to not work. All data types appear to have to be BIT in order for the union to work.
Just a typo mistake. Edited my previous post.
BIT datatype is a bit length in memory, while BOOL is 8 bit length (a Byte).