Hello everyone! I’m working with a function block (FB) in my program, which includes a matrix. I need to specify the size of this matrix when I instantiate my object in the main application. I've set up my FB with an input parameter: `ppMymatrixPointer`, which is a Pointer to a Pointer of LREAL. However, I'm struggling to use this pointer-to-pointer within my code, as the notation `ppMymatrixPointer[x, y]` is not functioning as expected. Any advice on how to correctly manipulate this pointer-to-pointer structure would be greatly appreciated!
**NaturePhoenix's Inquiry: Working with Pointers in Function Blocks** Hello everyone, I’m currently working with a function block (FB) in my code, and I have an object that includes a matrix. I need to declare the size of this matrix at the moment I create an instance of my object in the Main program. Here's what I've done so far: I defined the input parameter for my FB as `ppMymatrixPointer: Pointer to Pointer to LREAL`. Additionally, I've declared `pPointer: Pointer to REAL`. However, I’m having some difficulty utilizing the pointer to pointer within my FB code, as the syntax `ppMymatrixPointer[x, y]` is not functioning as expected. To initialize the pointers, I used the following code: ```pascal pPointer := __NEW(Pointer to REAL, x); ppMymatrixPointer := __NEW(Pointer to Pointer to REAL, y); ``` If anyone has insights or suggestions on how to effectively use these pointers within my function block, I would greatly appreciate your help! Thank you!
Using a pointer to access another pointer isn't functioning effectively, as it pertains to the memory locations of other memory locations. This approach can lead to complications and inefficiencies.
Although I have yet to experience TwinCAT firsthand, I have not encountered a PLC that supports dynamic array declarations. What I have observed is the capability to pass arrays as pointers, enabling the execution of various operations. Importantly, changes made do not create a local copy of the array; instead, they reflect directly on the original array. Array declarations are determined at compile time, yet the processing can be performed dynamically, which helps eliminate memory leaks while still providing significant flexibility. This combination of features makes it an interesting option for those seeking efficient ways to manage arrays in PLC programming.
My objective is to transfer the dimensions of a matrix as an integer to a function block (FB) where I can create the matrix. The operator __NEW enables this functionality, similar to the malloc function in C. In my current implementation, the pPointer[] works correctly; however, the ppMymatrixPointer[x][y] does not function as expected.
✅ Work Order Management
✅ Asset Tracking
✅ Preventive Maintenance
✅ Inspection Report
We have received your information. We will share Schedule Demo details on your Mail Id.
Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.