CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Mon Jun 26, 2017 2:57 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Feb 23, 2012 5:41 am 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 92
Is there a way to map an array of BOOL to a fixed IEC ADDRESS?

The following does not work

myBoolArary AT %MX0.0 : ARRAY[0..15] OF BOOL;

So Far these are the only combination that I have found to work for fixed memory addressing.

myBool AT %MX0.0 : BOOL; //Boolean Type
myInput AT %IX0.0 : BOOL;
myOut AT %QX0.0 : BOOL;

myByte AT %MB0 : BYTE; //Byte Type
mySINT AT %MB0 : SINT;
myUSINT AT %MB0 : USINT;
myByteArary AT %MB0 : ARRAY[0..10] OF BYTE;

myWORD AT %MW0 : WORD; //16 bit types
myINT AT %MW0 : INT;
myUINT AT %MW0 : UINT;
myWordArary AT %MW0 : ARRAY[0..10] OF WORD;

myDWORD AT %MD0 : DWORD; //32bit Types
myDINT AT %MD0 : DINT;
myUDINT AT %MD0 : UDINT;
myReal AT %MD0 : REAL;
myDwordArray AT %MD0 : ARRAY[0..10] OF DWORD;

mySTRING AT %MB0 : STRING; //STRING

_________________
The Original SoMachine Ninja


Top
   
PostPosted: Thu Feb 23, 2012 7:58 am 
Offline

Joined: Thu Feb 08, 2007 11:21 am
Posts: 44
Keep in mind that a variable of type BOOL uses 8 bits of memory space.

But to answer your question. You can declare the variable as

myBoolArary AT %MB0 : ARRAY[0..15] OF BOOL;

But then you have an array that takes up 16 bytes (16*8 bits) of memory.


Top
   
PostPosted: Thu Feb 23, 2012 1:58 pm 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 92
When trying to use it with my PLC Controller I get:

Bad declaration, use '%MX' for 'BOOL' variable


With CoDeSys_SP_Win PLC it works correctly.


Is there a way to bit align the array. Meaning

myWORD AT %MW0 : WORD;
myBoolArray AT %MB0 : ARRAY[0..15] OF BOOL;

myBoolArray[0] would equal myWord.0 would equal %MX0.0
myBoolArray[1] would equal myWord.1 would equal %MX0.1
myBoolArray[2] would equal myWord.3 would equal %MX0.2
myBoolArray[3] would equal myWord.4 would equal %MX0.3
myBoolArray[4] would equal myWord.5 would equal %MX0.4
myBoolArray[5] would equal myWord.6 would equal %MX0.5
myBoolArray[6] would equal myWord.7 would equal %MX0.6
myBoolArray[7] would equal myWord.8 would equal %MX0.7
myBoolArray[8] would equal myWord.9 would equal %MX1.0
etc

_________________
The Original SoMachine Ninja


Top
   
PostPosted: Thu Feb 23, 2012 2:17 pm 
Offline

Joined: Thu Feb 08, 2007 11:21 am
Posts: 44
Check the PACK and UNPACK functions in the UTIL library.


Top
   
PostPosted: Thu Feb 23, 2012 3:35 pm 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 92
PACK/UNPACK will not work for what I am trying to accomplish. I use a HMI that uses the symbol configuration. This allows the HMI to use variable names instead of fixed addressing. The problem comes when you have to address a single bit inside the HMI. It can not directly address the bit directly in the variable name. This is why a Boolean array works great. The other reason is the following Example below.

For Example if you can bit align the bool array then you could write the following:
myBoolArray AT %MB0 : ARRAY[0..15] OF BOOL; //If it mapped the array %MX0.0 to %MX1.0
myWORD AT %MW0 : WORD;

myWord:=0; //Resets all bits in the Array
myWord:16#FFFF //Set all bits in the ARRAY
myWord:=myWord AND 16#FF00; //Mask the lower byte
myWord:=myWord AND 16#00FF; //Mask the Upper byte
myWord:=myWord XOR 16#FFFF; //INVERT all bits

I know you can accomplish this by remapping the bits into the Array but that makes the variable work in one direction. Thus requiring the variables to be (IN or OUT) and not (IN and OUT).

_________________
The Original SoMachine Ninja


Top
   
PostPosted: Sun Feb 26, 2012 2:31 am 
Offline
User avatar

Joined: Tue Aug 30, 2011 1:21 am
Posts: 92
Not exactly an array but I did find the following how to map a DUT with bitwise alignment. Unfortunately you have to define a new structure for each instance.

TYPE my16bitDUT :
STRUCT
BIT00 AT %MX0.0 : BOOL; //Boolean Type
BIT01 AT %MX0.1 : BOOL;
BIT02 AT %MX0.2 : BOOL;
BIT03 AT %MX0.3 : BOOL;
BIT04 AT %MX0.4 : BOOL;
BIT05 AT %MX0.5 : BOOL;
BIT06 AT %MX0.6 : BOOL;
BIT07 AT %MX0.7 : BOOL;
BIT08 AT %MX1.0 : BOOL;
BIT09 AT %MX1.1 : BOOL;
BIT10 AT %MX1.2 : BOOL;
BIT11 AT %MX1.3 : BOOL;
BIT12 AT %MX1.4 : BOOL;
BIT13 AT %MX1.5 : BOOL;
BIT14 AT %MX1.6 : BOOL;
BIT15 AT %MX1.7 : BOOL;
END_STRUCT
END_TYPE

my16bit: my16bitDUT ;
myWORD AT %MW0 : WORD; //16 bit types

NOW the following works
myWord:=0; //Resets all bits in the Array
myWord:16#FFFF //Set all bits in the ARRAY
myWord:=myWord AND 16#FF00; //Mask the lower byte
myWord:=myWord AND 16#00FF; //Mask the Upper byte
myWord:=myWord XOR 16#FFFF; //INVERT all bits

_________________
The Original SoMachine Ninja


Top
   
PostPosted: Mon Apr 03, 2017 2:32 pm 
Offline

Joined: Thu Mar 30, 2017 12:13 pm
Posts: 7
Hi all,
Well I've also tried something like that:

TYPE t16bitDUT:
STRUCT
BIT00 : BOOL; //Boolean Type
BIT01 : BOOL; //Boolean Type
BIT02 : BOOL; //Boolean Type
BIT03 : BOOL; //Boolean Type
BIT04 : BOOL; //Boolean Type
BIT05 : BOOL; //Boolean Type
BIT06 : BOOL; //Boolean Type
BIT07 : BOOL; //Boolean Type
BIT08 : BOOL; //Boolean Type
BIT09 : BOOL; //Boolean Type
BIT0A : BOOL; //Boolean Type
BIT0B : BOOL; //Boolean Type
BIT0C : BOOL; //Boolean Type
BIT0D : BOOL; //Boolean Type
BIT0E : BOOL; //Boolean Type
BIT0F : BOOL; //Boolean Type
END_STRUCT
END_TYPE

MY16bDUT AT %MW0 : t16bitDUT;
But this does also not work..


Maybe it works as:
UNION
bits: t16bitDUT;
all AT %MW0 : WORD;
END_UNION


or maybe as:
TYPE u16bitDUT
UNION
bits: t16bitDUT;
all AT %MW0 : WORD;
END_UNION
END_TYPE

MY16bDUT AT %MW0 : u16bitDUT;

I'm, not sure..


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 7 posts ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited