I have programmed a up/down counter (UDC) module on CoDeSys.
My problem is : I would like to use the same function_block for all my UDC modules but the addresses of the variables (such as "AT %QX0.0") change from one module to another. All the modules are UDC-type but %QX0.0 become %QX2.0 for module 2 and so on...
Is it possible to automatically allocate the addresse of the variables so I can use the same function_block for the different modules ?
Thank you for any response.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok thank you but how do I link "AnUDCInstance.qxSomeOutput" to a physical address after that ?
I mean I know that I could write "%QX1.0:=AnUDCInstance.qxSomeOutput" so the physical Ouput take the value of my variable but how can I do this automatically or with some kind of function ?
Because to every I/O of the function block it exists the I/O of the Wago module but with a different address for every module...
Hope I'm clear enough...
Benoit.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello Benoit,
sorry for the late reply. Had been off for a few days.
```
AnUDCInstance.qxSomeOutput AT QX0.0
``` probably willl not work. I can't imagine, how the compiler could assign an absolute address to just a little part of a function block.
The safe way is to have just variables with certain addresses, to which you assign the output var of the FB instance, as I suggested it in one of my posts.
Rolf
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have programmed a up/down counter (UDC) module on CoDeSys.
My problem is : I would like to use the same function_block for all my UDC modules but the addresses of the variables (such as "AT %QX0.0") change from one module to another. All the modules are UDC-type but %QX0.0 become %QX2.0 for module 2 and so on...
Is it possible to automatically allocate the addresse of the variables so I can use the same function_block for the different modules ?
Thank you for any response.
Hi,
just do not use absolute addresses inside the UDC function block
To get the outputs of a module instance, use the instance identifier :
With CoDeSys, you need absolute addresses fΓΌr physical inputs / outputs only. All other data the compiler is able to allocate dynamically.
Have success
Rolf
.
Ok thank you but how do I link "AnUDCInstance.qxSomeOutput" to a physical address after that ?
I mean I know that I could write "%QX1.0:=AnUDCInstance.qxSomeOutput" so the physical Ouput take the value of my variable but how can I do this automatically or with some kind of function ?
Because to every I/O of the function block it exists the I/O of the Wago module but with a different address for every module...
Hope I'm clear enough...
Benoit.
Hi,
Rolf
ok, nice!
May I write directly :
Or do I have to assign a physical address to a variable and then put the data of my function block in the variable like the way you did ?
Thankt you!
Hello Benoit,
sorry for the late reply. Had been off for a few days.
```
AnUDCInstance.qxSomeOutput AT QX0.0
``` probably willl not work. I can't imagine, how the compiler could assign an absolute address to just a little part of a function block.
The safe way is to have just variables with certain addresses, to which you assign the output var of the FB instance, as I suggested it in one of my posts.
Rolf