Join us today!

Notifications
Clear all

Determine Array Datatype with FB_INIT

3 Posts
2 Users
0 Reactions
405 Views
Posts: 20
Topic starter
(@adam-haney)
Eminent Member
Joined: 2 years ago

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!

Reply
2 Replies
2 Replies
(@theshamot)
Joined: 1 year ago

Active Member
Posts: 7

@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

Reply
(@adam-haney)
Joined: 2 years ago

Eminent Member
Posts: 20

@theshamot 

Thank you very much for your response and effort in putting together the repo! I appreciate it.

Reply
Share: