Join us today!
interface method with different inputs and quantity according to the FB class where it is implemented, with Abstract FB, or as it would be...??
Hello,
I have a method declared in an interface, it can have different inputs and number and quantity depending on the FB class where the interface is implemented, as it would be with Abstract FB, can someone give me a small example?
Best regards, Víctor.
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
Hello,
This was just answered on the linkedin forum:
"Unfortunately overloading is not allowed in twincat 3. Not for methods, properties nor variables themselves.
it sucks I know, but you gotta play with the cards you got..
So you need to do something around the limitations."
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
My post on codesys forum about how to overload a sort function may interest you:
https://forge.codesys.com/forge/talk/Runtime/thread/6ae1b1ff98/?page=1&limit=25#f6da
It is not exactly what you are trying to do, but it is an approach.
For an Adition function with undifined parameter inputs, I will do it like this:
- Create a function per type you want to return (DINT and REAL)
- Each function will have 3 arguments
- element_count: the number of element you want to add
- pData : pointer to array of byte containing the element you want to add
- element_size : the byte count of each of your element
- Perform a loop that:
- cast an element of the pData array to the correct type
- add the cast element with the result
- increment the byte number depending on element_size
Unfortunately it is not possible to have an undifined number of parameter in ST. The compiler is not capable to determine it itself like other language (in C we have the '...' argument with VA_List type). So you have to perform it yourself.
This is how it is done in C:
- 17 Forums
- 265 Topics
- 932 Posts
- 1 Online
- 688 Members