Practicalities of using Rusty #678
Replies: 3 comments 1 reply
-
I'll try to answer the question below as far as I understand them
We have not done any testing with Matiec, but we already link RuSTy code against a C++ based runtime, so this is possible, I'll try to expand on how below
RuSTy is under very active development, anything not yet working is definitely a bug, and contributions/bug reports are always welcome :)
You can also directly generate a C object or a statically linked object like this:
You need
We can call system functions already, any C function can be linked and used in ST see External Functions, this applies to any function, you just need to declare the appropriate header and link the library correctly ( Hardware and Retain are planned, and we have rudimentary support for hardware. The change we are planning would be that the address itself would become a variable that could be assigned, and the global variable would then possibly become a pointer to that address. This might make hardware access more efficient. Hope this helps, and please don't hesitate to ask further questions. |
Beta Was this translation helpful? Give feedback.
-
Alright, that definitely helps, with that basic IO and cyclic call should be viable. Of course its a runtime thing rather than language thing, but the language exists to be used in runtime, so it's probably a useful point of feedback to actually integrate it into a fully fledged plc. Anyway, here's the fixed calls from cpp for anyone attempting similar thing in the future. PLC.st file
main.cpp file
compile and run like this, it also spits out the json for IO
|
Beta Was this translation helpful? Give feedback.
-
It might be easier to expose the entire structure of everything in PLC, that's what TwinCAT does with it's tmc file. There is also the hmi question for future considerations - that will want to poke all sorts of variables available in PLC and it's pretty popular to add non-realtime services and interfaces to PLC similarly too - be it over OPC for most PLCs or in case of TwinCAT direct ads access is popular. It's all the same thing, external things having access to pretty much all variables in PLC when they want it. For that the memory structure has to be described somewhere. |
Beta Was this translation helpful? Give feedback.
-
My idea is to deploy Rusty as alternative to Matiec in OpenPLC
While it doesn't seem to be a very mature alternative right this moment, down the line I can see Rusty developing and becoming better and more capable while Matiec is what it is, nobody is seriously developing it.
There are some practical challenges with that and not many samples to work off of. To begin with, OpenPLC is written in C/C++ as would likely most other PLCs that might want to use rusty compiled code.
How do I get PLC object file to link to begin with?
I have PLC.st, easy enough
I compile it to object like so, that works
$ rustyc -c PLC.st -o PLC.o
I have minimal main.cpp file like so
and I compile it to main.o
$ g++ -c main.cpp
so far so goodbut when it comes time to link, it doesn't
Where am I going wrong?
Well, I can see where I'm going wrong, in object file PLC is not a function, but how do I fix it?
Do I need some sort of #[no_mangle] pragma in st?
(alt.o is a cpp compile equivalent to what PLC.o should be)
That's just an entry point though, a practical PLC needs to access hardware, handle retain variables, call system functions... well that's beyond absolute minimal viable example.
Beta Was this translation helpful? Give feedback.
All reactions