Siemens DB, UDT and Pointer

sapoleon

Member
Join Date
Aug 2003
Location
salta, salta
Posts
315
Hi,
I'm having a hard time trying to learn very fast how to do the things in Step 7. I see a lot of options, but I don't have now the time to try them.
I made a function not nice, to get and write data to a DB made of 30 UDTs of the same type. The thing is, I someone can give me a tip on how to do it with pointers.

The UDT1 consist of 2 INT and a DINT.
The DB305 consist of 30 UDT1. (named wagon01 to wagon30).

This makes me a nice database, where the first colum (first INT of the UDT) almost never change,and I have to write a value to the second and third colums.
I get allways which of the 30 lines I have to change, and what's the data to write.

My question is how do I know the correct position of the UDT and in the UDT where the data is to be taken of or writen to with a pointer?

(I made a very ugly function where I access a line according to a comparsison, that is to say, if the #lineNumber == 5, I write in this line, if now keep asking) :oops: I don't want even to post it....

Thanks

ps: btw, I AM reading the posts, and siemens support, and trying to make it by myself...
 
Why are you using UDT's as opposed to an array of structures in your DB ?

Here's a simple example if your udt size and structure is not going to change

Code:
FUNCTION FC 2 : VOID
TITLE =
VERSION : 0.1

VAR_INPUT
  iWagonNumber : INT ; 
  iSizeOfUDTInBytes : INT ; 
  dbWagon : BLOCK_DB ; 
END_VAR
BEGIN
NETWORK
TITLE =wagon[n] access where n=1....30
	  L	 #iWagonNumber; 
	  +	 -1; 
	  L	 #iSizeOfUDTInBytes; 
	  *D	; 
	  SLD   3; 
	  LAR1  ; 
	  OPN   #dbWagon; 
	  L	 DBW [AR1,P#0.0]; //L Wagon[iWagonNumber].iFirstUDTName
	  L	 DBW [AR1,P#2.0]; //L Wagon[iWagonNumber].iSecondUDTName
	  L	 DBD [AR1,P#4.0]; //L Wagon[iWagonNumber].diThirdUDTName
	  T	 DBW [AR1,P#0.0]; //T Wagon[iWagonNumber].iFirstUDTName
	  T	 DBW [AR1,P#2.0]; //T Wagon[iWagonNumber].iSecondUDTName
	  T	 DBD [AR1,P#4.0]; //T Wagon[iWagonNumber].diThirdUDTName

END_FUNCTION
 
Last edited:
Hi L D[AR2, P#0.0],

First of all, thanks for your answer and help.

I don't really know why I'm using UDT instead of Array of Struct exactly. First of all, I'm quite new with Siemens, and trying it's features, and making things according at what I read at the moment.
In any case, it will be (at least at this time I think so) a normal structure in the program. It is not going to be just in this DB, it will be used in some other, and maybe pass also like data for some other functions that I am making.
What I may have done, is an Array of the UDT's instead of writing them 30 times, but I was afraid, that that would make my life even more difficult if trying to understand and access them with a pointer... Is there any difference in the accessing if I made a DB with array[1..30] of UDT1?


 
Last edited:

Similar Topics

Hello All: I'm starting to use Intouch (2017). I comunicate with S7-1500 PLC with SIDIRECT using symbolic. I'm trying to create a faceplate. I see...
Replies
0
Views
1,168
How do I move one byte of data in an array to a UDT that is one byte in length. AB would be a slam dunk on this with a simple Copy instruction...
Replies
22
Views
5,345
I have created a UDT. This UDT is a IN_OUT to a FB I am creating. This UDT contains a few strings. Inside the FB I am attempting to use SFC20...
Replies
3
Views
2,355
In S7 Program there is a DB which is created from UDT. To modify DB, UDT was changed because only if UDT changed then DB is changed. My question...
Replies
1
Views
3,931
Can anyone tell me why my variables are red in the attached picture? I just started to use siemens and I am trying to understand how udt works...
Replies
4
Views
3,124
Back
Top Bottom