-
Notifications
You must be signed in to change notification settings - Fork 74
My team and I are currently exploring some useful features of 4diac and attempting to modify the source code to meet our requirements. So far, we have successfully integrated FMI into 4diac for co-simulation. We are now working towards another goal: encapsulating Python scripts within function blocks to introduce AI capabilities into industrial software. However, there is very limited information available on this topic, and so far, we have no clear direction.
From what I understand, SIFB (Scripted IEC Function Block) seems to be a possible solution, but there is still a lack of documentation in this area. Therefore, my questions are:
Currently, besides the ST language, are other programming languages supported for encapsulation into function blocks?
How can we address the language runtime environment required to execute scripts? For example, if Python scripts are encapsulated within function blocks, the FORTÉ runtime must necessarily include the Python interpreter. Additionally, running Python scripts often requires other third-party libraries, leading to further complications. How can these issues be managed?
How can we map inputs and outputs to the variables or events of the scripting language?
Do we need to deeply modify the FORTÉ runtime or the IDE's code to support writing function block algorithms in Python instead of ST?
All reactions
Replies: 1 comment 2 replies
My team and I are currently exploring some useful features of 4diac and attempting to modify the source code to meet our requirements. So far, we have successfully integrated FMI into 4diac for co-simulation. We are now working towards another goal: encapsulating Python scripts within function blocks to introduce AI capabilities into industrial software. However, there is very limited information available on this topic, and so far, we have no clear direction.
From what I understand, SIFB (Scripted IEC Function Block) seems to be a possible solution, but there is still a lack of documentation in this area. Therefore, my questions are:
Currently, besides the ST language, are other programming languages supported for encapsulation into function blocks?
Not on 4diac IDE level.
How can we address the language runtime environment required to execute scripts? For example, if Python scripts are encapsulated within function blocks, the FORTÉ runtime must necessarily include the Python interpreter. Additionally, running Python scripts often requires other third-party libraries, leading to further complications. How can these issues be managed?
We have already a LUA interpreter included in the 4diac FORTE. You can look into that part of the code to see how we address at least the integration of an interpreter with its libraries. This can also be done as external module which would make it easier for you to separate your code from our code.
As I'm not very proficient in Phyton I don't know how Phyton libraries would be made available.
How can we map inputs and outputs to the variables or events of the scripting language?
This strongly depends on how you integrate the scripting language. Each input or output is represented in 4diac FORTE as an instance of a C++ class with methods to read and write values or convert values. The LUA integration code could serve as a starting point.
Do we need to deeply modify the FORTÉ runtime or the IDE's code to support writing function block algorithms in Python instead of ST?
As written above for 4diac FORTE it should be possible to do that in own modules. The API and infrastructure of 4diac FORTE should allow that.
4diac IDE wise it strongly depends on what you really need or what you want to your users to do and what you would like to do. Do you like you users to write phyton code inside of FBs? Then yes this requires a bigger development effort in 4diac IDE. You would need to come up with your own editors, code generators. Also we would need to talk a bit how 4diac IDE would know if an ST or Phyton editor should be shown. But this should be manageable.
However there are also other options that are maybe more interesting for you and your users:
- You could wrap python calls in such a way that they are available as ST Code for your users. In that way your users would write the ST they know and you would forward that to phyton. This could even be don such that you implement a ST to phyton code generator similar to what we do currently with Lua.
- You wrap the python code and calls in SIFBs and provide your users only a library of SIFBs. This has the great advantage that your users will only get the FB interface, wire it toghether and these SIFBs will only work on 4diac FORTEs where your FBs are compiled in. Writing such SIFBs is normally also rather straight forward. There is a small tutorial on that but we are happy to support you on that as well.
You may have heard that we are running the 4days of Eclipse 4diac Winter School in 4 weeks: https://eclipse.dev/4diac/events/4diacwinterschool
There you will definitely learn more about the insides of 4diac FORTE and IDE and it is also a nice venue to discuss your topic in more detail in person.
All reactions
I have already implemented python scripts execution in 4diac by adding codes to forte , make forte can call python interpreter in the host env. It's easy to do it and thanks your reply
All reactions
Happy to hear that. If you want to share something with the community how you did it and what is now possible feel free to submit a PR to our website hugo repository with a guest news post.