Join us today!
Determine Array Datatype with FB_INIT
Hey all,
I was wondering if there is a way to initialize a fixed length array with the datatype it needs to have using FB_INIT? I have Googled, searched the forum, and using LinkedIn's TwinCAT Forum, but haven't found an answer.
My use-case is I have a multiple fixed-length arrays of different datatypes (REAL, LREAL, INT), and I need to perform the same operations on the arrays. I would like to avoid making separate FB's with the same code, so I was wondering if there was a way to set the type of data in the array with FB_INIT.
Thank you for any help!
@adam-haney I would suggest to use similar approach a used at my ultimate sorting function: https://github.com/theshamot/Higher-Level-TwinCAT-3-Library/tree/main/TcList/HL3/DataProcessing/Sort
You will pass two things into your function/fb
1. You will pass array as ANY - you will receive pointer and byte size of an array
2. You will pass first element of an array as ANY - this will give you datatype bytesize to iterate through array and datatype so you can properly compare them. You can use casting pointers to types to compare as done on my github link https://infosys.beckhoff.com/content/1033/tcplclib_tc2_utilities/35273739.html?id=557344440327821413
Thank you very much for your response and effort in putting together the repo! I appreciate it.
- 17 Forums
- 265 Topics
- 932 Posts
- 2 Online
- 689 Members