Mike Lee
I’m currently working on integrating a custom C function into OpenPLC by wrapping it inside a function block using import_tool.py . While the import process into the OpenPLC Editor completed successfully and the .st code was generated correctly, I encountered an issue during runtime compilation.
 
Has anyone else encountered this problem when using import_tool.py ? Is there a recommended way to avoid this issue or patch the generation logic?
Any advice or suggested workaround would be greatly appreciated.
 
aps_sdk.h
error1.png
 
OpenPLC runtime
error2.png
Reply 0 0
thiagoralves
I suspect the problem might be on the .st file you're using. This code is generated by MatIEC, so something on the source .st might be off.
Reply 0 0
Mike Lee
I suspect the problem might be on the .st file you're using. This code is generated by MatIEC, so something on the source .st might be off.
Thanks for the reply.
To eliminate other factors, I simplified the .st file to only contain a single custom function block call that wraps one line of C API. However, I’m still encountering the same compilation error from the generated C code.
 
FUNCTION_BLOCK APS_get_system_timer
VAR_OUTPUT
TMR : DINT;
ERRCODE : DINT;
END_VAR
{{
xyz();
}}
END_FUNCTION_BLOCK
 
So it seems the problem may not be with the complexity of the .st file, but perhaps how import_tool.py or MatIEC generates the C code for custom function blocks.
Any thoughts on this?
Reply 0 0
thiagoralves
The .st code must be generated by the editor, not by hand. The import tool is tied to the specific way that the editor builds the .st file. I don’t think adding pragmas {{ }} will work well. Ideally you should edit the C code manually after it has been generated
Reply 1 0
Mike Lee
The .st code must be generated by the editor, not by hand. The import tool is tied to the specific way that the editor builds the .st file. I don’t think adding pragmas {{ }} will work well. Ideally you should edit the C code manually after it has been generated
Thanks again for your explanation.
As a final note, I'd like to point out that even a minimal FUNCTION_BLOCK with an empty {} block still triggers a code generation error during runtime compilation. Here's an example that causes the issue:
 
FUNCTION_BLOCK APS_get_system_timer
VAR_OUTPUT
TMR : DINT;
ERRCODE : DINT;
END_VAR
IF TMR <> 0 THEN
ERRCODE := 1;
{}
END_IF;
END_FUNCTION_BLOCK
Reply 0 0
thiagoralves
Yes, as I mentioned earlier, I don't think C pragmas will work well on this process. You will have to exclude all C code from the .st file, and then edit the generated C files later to add whatever C code you need. There might be patches possible in the import_tool.py that perhaps solves this and allows direct C code in the .st file. Feel free to look into that if you have time/knowledge.
Reply 0 0
Reply