ctwincattwincat-ads

How to pass an array from PLC program to C module instance in TwinCAT?


I am a beginner in TwinCAT and is using XAE to test some functionalities.
My current program requires me to pass an array of bytes from the PLC ST program to C module instance. However TwinCAT 3 doesn't allow this and the error message says 'Structured value types not allowed in external function calls'.
Is there any workaround for this?
Is there any other way of passing a byte array to the C module instance?


Solution

  • In your C/C++ project you will be able to find a folder called "TMC Files". In the .tmc file you can define Data Areas for your module. You can define inputs for the module using "Input-Destination" and then defining the data structures and naming that you need. When you later instantiate your module you can link this data area to variables in your PLC code.

    Here is an example of the .tmc file from my project (not using arrays but other input data types):

    TMC file