Technical Forum

STEP 7 Additional Software

POINTER in SCL - possible to use a pointer to data in this location

Thread Starter: Gordič   Started: 5/31/2012 1:01 PM   Replies: 2

« Previous thread Next thread »
Page 1 of 1 (3 items)
  5/31/2012, 1:01 PM
Joined 5/31/2012
Last visit: 6/1/2012
Posts: 2
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Hello,

i'd like to ask you, if its possible to use a pointer to data in this location:

"DB_Test".BLOCKS[1].DBX26.0 BYTE 250

There is an array of structures like following:

TYPE
dbStruct:   STRUCT
                    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;
            END_STRUCT;
END_TYPE

// DB 10
//-------------------------------------------
DATA_BLOCK DB_Test
    STRUCT
        BLOCKS: ARRAY[1..4] OF dbStruct;
    END_STRUCT;
BEGIN
END_DATA_BLOCK


Can you help me please, how can i solve this problem ? Thank you a let for your answer...



=== Edited by CS Moderator @ 5/31/2012 3:22 PM [GMT ] ===
new subject after splitting from ANY, POINTER in SCL

Top
  5/31/2012, 1:05 PM
Joined 5/31/2012
Last visit: 6/1/2012
Posts: 2
Rating:
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
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.

This working:

FUNCTION FC10 : VOID
VAR_TEMP
pDB: ANY;
    pAny AT pDB: STRUCT
                S7Code: BYTE;
                DataType: BYTE;
                Length: INT;
                DBNumber: INT;
                MemoryArea: BYTE;
                ByteAddressMSB : BYTE;  // Byte address most significant bits
                ByteAddressLSB : WORD;  // Byte address least significant bits
                //BytePointer : DWORD;
                END_STRUCT;
END_VAR
BEGIN

pAny.S7Code:= 16#10;
pAny.DataType:= 16#02;     // type BYTE
pAny.Length:= 250;        // data length
pAny.DBNumber:= 10;
pAny.MemoryArea:= 16#84;
pAny.ByteAddressMSB:= 16#00;
pAny.ByteAddressLSB:= 208;
//pAny.BytePointer:= DW#16#840000D0;
.
.
.
END_FUNCTION

Top
  6/1/2012, 11:58 AM
Joined 1/17/2007
Last visit: 12/18/2014
Posts: 1047
Rating:
Rated: Excellent [4.44 out of 5 / rated 225 time(s)]. (225) 
Users with special expertise supervising conferences
Rated: no ratings [0 out of 5 / rated 0 time(s)]. (0) 
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:-

DB_Test.BLOCKS[<index>].<element_name>{[<element_index>]}
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 ...

E.G.
IF DB_Test.BLOCKS[1].START = XXX THEN or b := DB_Test.BLOCKS[i].Datenbyte[250];

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.

So far, the universe is winning...
Top
Page 1 of 1 (3 items)
Actions