Step 7 pointers

Alfbox

Member
Join Date
Feb 2006
Location
Liberec
Posts
12
Hi,
I program S7-300 CPUs but I'm not skilled in it yet.
Now I'm facing the problem with comparing static array values with dynamically changing values in a DB.
I need it for evaluating errors of Simotion Safety unit.
The codes of errors are stored in the array and the DB is a buffer of errors of the SSU. If a new fault occurs, the DB is changed.
I don't need to compare the whole DB with the array in one cycle.
I know I should use the pointers but don't know how exactly.
How to reveal the cell of array by means of indirect addressing? How to increase the "cell number" in a loop?
Does anyone know or can paste a link with help?
Thanks a lot
 
Alfbox

I am not sure if this is what you are after, but Siemens have a function called TBL_FIND, this is FC86. It can be found in the block library, Standard library -> TI-S7 Converting Blocks.

This might be what you are after.

Paul
 
Alfbox - please see below my implementation of the array operation
B[n]:=A[m] (The arrays are assumed to be zero based).

Cut and paste the code into your source folder and then compile it. Note then when monitoring blocks that use any pointers, you will not be able to 'see' the variables at the block call - just access them in another network. I've not done any checking to make sure the arrays are of the same type, but you should get the idea of indirect addressing (and any pointers !)

Code:
FUNCTION FC 6 : VOID
TITLE =Generalised Array element access, B[n]:=A[m];
VERSION : 0.1
 
VAR_INPUT
A : ANY ; 
m : INT ; 
n : INT ; 
END_VAR
VAR_OUTPUT
B : ANY ; 
END_VAR
VAR_TEMP
iType : INT ; 
iDBNumber : INT ; 
dwAreaPointer : DWORD ; 
iSize : INT ; 
bBOOL : BOOL ;	
wWORD : WORD ;	
dwDWORD : DWORD ; 
byBYTE : BYTE ; 
END_VAR
BEGIN
NETWORK
TITLE =de-construct any pointer for input array
	 L	 P##A; 
	 LAR1 ; 
	 L	 B [AR1,P#0.0]; 
	 L	 B [AR1,P#1.0]; 
	 T	 #iType; 
	 L	 W [AR1,P#2.0]; 
	 T	 #iSize; 
	 L	 W [AR1,P#4.0]; 
	 T	 #iDBNumber; 
	 L	 D [AR1,P#6.0]; 
	 LAR1 ; 
NETWORK
TITLE =
//open db if required
	 L	 #iDBNumber; 
	 L	 0; 
	 ==I ; 
	 JC	indb; 
	 OPN DB [#iDBNumber]; 
indb: NOP 0; 
	 L	 #iType; 
	 JL	iype; 
	 JU	inon; 
	 JU	iBol; //type 01= bool
	 JU	iByt; //type 02= byte
	 JU	iByt; //type 03= char (process as byte)
	 JU	iwrd; //type 04= word
	 JU	iwrd; //type 05= int (process as word)
	 JU	idwd; //type 06= dword
	 JU	idwd; //type 07= dint (process as dword)
	 JU	idwd; //type 08= real (process as dword)
iype: JU	inon; 
iBol: NOP 0; 
	 L	 #m; 
	 +AR1 ; 
	 A	 [AR1,P#0.0]; 
	 =	 #bBOOL; 
	 JU	op; 
iByt: L	 #m; 
	 SLD 3; 
	 +AR1 ; 
	 L	 B [AR1,P#0.0]; 
	 T	 #byBYTE; 
	 JU	op; 
iwrd: L	 #m; 
	 SLD 4; 
	 +AR1 ; 
	 L	 W [AR1,P#0.0]; 
	 T	 #wWORD; 
	 JU	op; 
idwd: L	 #m; 
	 SLD 5; 
	 +AR1 ; 
	 L	 D [AR1,P#0.0]; 
	 T	 #dwDWORD; 
	 JU	op; 
inon: JU	exit; 
NETWORK
TITLE =de-construct any pointer for output array
op: L	 P##B; 
	 LAR1 ; 
	 L	 B [AR1,P#0.0]; 
	 L	 B [AR1,P#1.0]; 
	 T	 #iType; 
	 L	 W [AR1,P#2.0]; 
	 T	 #iSize; 
	 L	 W [AR1,P#4.0]; 
	 T	 #iDBNumber; 
	 L	 D [AR1,P#6.0]; 
	 LAR1 ; 
NETWORK
TITLE =
//open db if required
	 L	 #iDBNumber; 
	 L	 0; 
	 ==I ; 
	 JC	ondb; 
	 OPN DB [#iDBNumber]; 
ondb: NOP 0; 
	 L	 #iType; 
	 JL	oype; 
	 JU	onon; 
	 JU	oBol; //type 01= bool
	 JU	oByt; //type 02= byte
	 JU	oByt; //type 03= char (process as byte)
	 JU	owrd; //type 04= word
	 JU	owrd; //type 05= int (process as word)
	 JU	odwd; //type 06= dword
	 JU	odwd; //type 07= dint (process as dword)
	 JU	odwd; //type 08= real (process as dword)
oype: JU	onon; 
oBol: NOP 0; 
	 L	 #n; 
	 +AR1 ; 
	 A	 #bBOOL; 
	 =	 [AR1,P#0.0]; 
	 JU	exit; 
oByt: L	 #n; 
	 SLD 3; 
	 +AR1 ; 
	 L	 #byBYTE; 
	 T	 B [AR1,P#0.0]; 
	 JU	exit; 
owrd: L	 #n; 
	 SLD 4; 
	 +AR1 ; 
	 L	 #wWORD; 
	 T	 W [AR1,P#0.0]; 
	 JU	exit; 
odwd: L	 #n; 
	 SLD 5; 
	 +AR1 ; 
	 L	 #dwDWORD; 
	 T	 D [AR1,P#0.0]; 
onon: JU	exit; 
NETWORK
TITLE =
exit: SET ; 
	 SAVE ; 
END_FUNCTION
 
Bravo!

Thank you,

I've been waiting for such an answer.
Please, think it over prior offend someone.

jacekd said:
Search this forum first (can you see the "Search" in menu up there ?). I'm sure this will bring you the answer.
 
🤷
Alfbox,
I have no idea why you feel offended. This topic was brought up in great details on this Forum many times. If you don't even give a **** to find it and you're just waiting for a ready-made solution from someone else you shouldn't feel offended with my attitude. How ever this is my very private opinion and others may disagree.
 
Jacekd,
I didn't mind if you have posted a notice...Guy, look through threads, I've spoted it there. Your sarkasm offended me.
I have gone through before I posted the topic and haven't found nothing similar. There are tons of topics about pointers, I agree, so it is hard to find the exact one.
My way of seeking something is.. look, look better, ask
You are right..I was waiting for ready-made solution as the majority in the forum..
To answer someone is not compulsory.
There are plenty of topics which have been described many times.
___________
Alf
 
I took me few minutes to find answer to "How to reveal the cell of array by means of indirect addressing? How to increase the "cell number" in a loop?" on this forum. If that is what you call "hard" then pls excuse me.
 
Hi, its me again.
I had to learn a lot, gone through many threads to learn some facts about Step7 pointers. Finaly I was able to write my first STL function moreover with pointers.

IT WORKS fine.
If anyone need help with Simotion Safety Unit error evaluating, please contact me.
Thank you all. PLCS.net really helps.
:site:
 

Similar Topics

Hello everybody! I have a question regarding pointers in step7... As far as I see this is some of the harder things to understand using the S7...
Replies
3
Views
5,607
Hello, I'm new with siemens step 7 (PLC : S7 300) and i have a question about using pointers. I have created a 5 DW shift register for an...
Replies
5
Views
4,586
I am having a step7 v5.4 program where the blocks are encrypted and locked. And the manufacturer is stopped the support. Is there any ways to...
Replies
2
Views
168
Good Morning, Hoping someone with some Siemens experience can give me a hand with this one. Customer has a S7-200 cpu, which has a 6GK7...
Replies
0
Views
239
HI! HOW COULD I OBTAIN THE NAMES OF THE STEPS OF A ROUTINE IN SFC LANGUAGE IN STUDIO5000? Or is there a system variable that gives me those...
Replies
0
Views
338
Back
Top Bottom