Skip to Content
|5/31/2012 1:01 PM|
Last visit: 6/1/2012
i'd like to ask you, if its possible to use a pointer to data in this location:
"DB_Test".BLOCKS.DBX26.0 BYTE 250
There is an array of structures like following:
START : BOOL;
RD_WR : BOOL;
DONE : BOOL;
BUSY : BOOL;
ERROR : BOOL;
ID : DWORD;
PORT : INT;
IOL_INDEX : INT;
IOL_SUBINDEX : INT;
LEN : INT;
STATUS : DWORD;
IOL_STATUS : DWORD;
RD_LEN : INT;
Datenbyte : ARRAY[0..399] OF BYTE;
// DB 10
BLOCKS: ARRAY[1..4] OF dbStruct;
Can you help me please, how can i solve this problem ? Thank you a let for your answer...
Last edited by: CS Moderator at: 5/31/2012 3:22 PM
new subject after splitting from /tf/WW/en/Posts/50677#top
|5/31/2012 1:05 PM|
Last visit: 6/1/2012
|At the moment i have normal pointer for one DB like following and its working good. But with UDT structure (more then one DB) i have a problem.
FUNCTION FC10 : VOID
pAny AT pDB: STRUCT
ByteAddressMSB : BYTE; // Byte address most significant bits
ByteAddressLSB : WORD; // Byte address least significant bits
//BytePointer : DWORD;
pAny.DataType:= 16#02; // type BYTE
pAny.Length:= 250; // data length
|6/1/2012 11:58 AM|
Last visit: 7/23/2015
|Not sure what you are trying to achieve.
But let me take a guess.
You want to access each structure (and its members) via an index variable?
If that is the case, you don't need an Any pointer at all. You can simply access the structure elements directly using the form:-
Where <index> is the index for your array of structures, which can be a fixed number of a variable (INT/DINT only though), <element_name> is the structure element names used in your UDT, and <element_index> is an optional index for any arrays in your structure. You can continue down as many levels of structure / arrays as you wish (these are known as levels of indirection in software engineering). So you could have an array of structures than contains in it another array of structures ad inifinitum. To access these, you would just keep adding the structure elements separated by periods '.' (e.g. DBn.structa[indexa].structb[indexb].[...]structn[indexn].element_name ...
IF DB_Test.BLOCKS.START = XXX THEN or b := DB_Test.BLOCKS[i].Datenbyte;
With this, you don't have to worry about the actual address (DBX26.0 BYTE 250 in your case) as the compiler will sort it out for you. This is actually better as using hardcoded addresses is not good programmming practice, as if you change the structure at all, your address will be invalid. This way the addresses will be automatically updated by the compiler if you ever change the structure. The code is also much easier to read and maintain.
Programming today is the race between software engineers building bigger and better idiot proof programs, and the universe producing bigger and better idiots.