access udt to move to an array of udt in a db

bvrm

Member
Join Date
Mar 2010
Location
Belgium
Posts
15
Hi,

I'm quite new to pointers and i have a question.

I have made an udt1 of one integer and one timeofday (total of 6 bytes).
I have also a DB with a array[0..15] of udt1.
Now i want to write a function / functionblock that copies the udt to the DB.

Following inputs to the function:

i_udtUDT as UDT1
i_SizeinbytesofUDT1
i_Index as integer; (0-15)

I wanted to use the SFC20 'BLKMOV'. The target pointer is no problem.

But building the source pointer (any) pointing to the udt doesn't work for me.
Is it true you can't make a any pointer to the start adres of an udt?

I don't want something in the function, about the structure of the udt itself.
So not:

L i_index
L i_SizeinbytesofUDT1
*I
ITD
SLW3
LAR1

L udtUDT.iInteger
T DB20[AR1,P#0.0]

L udtUDT.iTime
T DB20[AR1,P#2.0]

I would like it completely independent from the structure of the udt. And copy it to the DB.
So if i change the structure of the udt (for example adding a integer) i only need to change the input parameter size when calling this function.

Is this possible? And if yes, how?

I'll be very grateful.

Regards,
Bvrm
 
Hi,

I understand your solution, but i can't get it to work.
Because when running, the plc goes in stop mode.

The problem is at the following line:

> OPN DB [#iSrcDB]
L B [AR2,P#0.0]

probably the iScrDB isn't correct.

So nevertheless the proceeding code executes well, the value that is transferred into iScrDB must be wrong:

L P##UDTToWrite //data to copy into array
LAR2
L W [AR2,P#0.0] //db number of data to write into array
T #iSrcDB



Or the problem can be the following:

OPN DB [#iSrcDB]

doesn't work for an UDT (is it possible to call an UDT a DB when opening?)

I hope you can help.

regards,
bvrm
 
what do you mean with MW202? i never used this. :confused:

I'm sure the target pointer is correct, i put the following 2 lines in comment and replaced them by L 0. It wrote 0 to all records of the correct udt in the array.
 
Last edited:
Are you running the code as posted, or have you modified it ?

Here's OB1 from the original project:

mw202.JPG
 
If you are having problems tracking down what is wrong, copy your blocks to a library and post the archived library.
 
That would be very usefull, there are some comments/ variable names in dutch. I'll post it. Thank you VERY much in advance :geek:
 
Why have you changed my original FC2 into your FB4 ? FC2 was designed as a function and will not directly convert to a function block - this is your problem.
 
Ok, i'll make an FC of it. Thank you for the response.

I've seen that MW202 contains the index of the place in the array where the udt must be written to. In my case this will be a value between 0..15.
Guess that isn't the problem.

I'll let you know if it works by making a FC of it.
 
Hi,

It works !! Thank you, you're the best.

I still have some minor questions.

1) To determine the size of the udt, you make a local variable of type udt1 as temp. Why isn't it possible to determine this from the udt as IN-variable?

2) can you explain the SAVE instruction? + is it necessary?

i found this in the help

'SAVE saves the RLO into the BR bit. The first check bit /FC is not reset. For this reason, the status of the BR bit is included in the AND logic operation in the next network.
The use of SAVE and a subsequent query of the BR bit in the same block or in secondary blocks is not recommended because the BR bit can be changed by numerous instructions between the two. It makes sense to use the SAVE instruction before exiting a block because this sets the ENO output (= BR bit) to the value of the RLO bit and you can then add error handling of the block to this.'

but i don't really understand what it does.


I would be very pleased if you find some time to answer these questions too. So i can even better understand your solution.

Thank you (once again) for solving the problem. (y)


regards,
bvrm
 
1. Yes you can determine the size of the UDT as an IN parameter, but the parameter type has to be of type ANY

2. I use SET SAVE at the end of this type of block so that the ENO output from the block (when viewed in ladder) is true.
 
srry for the late reply, but i had a week no acces to internet. I guess the admins can declare this thread as [solved].
thanks once again !
 

Similar Topics

Hi All! I've created some AOI and have added a local tag of my UDT. I've set external access to Read/Write in AOI's tag browser. So, I've created...
Replies
14
Views
5,749
Hello, I have a problem I cannot solve. How can I access user defined data type tag member using VBA. I have written a short script that allow...
Replies
2
Views
2,399
I should use FB that has UDT in IN_OUT as multiple instance within FB and I can not access its data via symbolic adressing. UDT has 16 bits and 4...
Replies
1
Views
1,921
Hi Siemens guys! I am experiencing SF fault on our S7-300 (6ES7 315-2AH14-0AB0) CPU from time to time. I've checked the diagnostic buffer and...
Replies
13
Views
174
Can we use a Simotion D455 ethernet port x127 as a gate, to access S7-1500 plc Tia Portal program ? In the Simatic manager, we used Netpro to do...
Replies
2
Views
87
Back
Top Bottom