r2k-in-the-vortex
So I recently wrote rudimentary EtherCAT support for OpenPLC.
https://openplc.discussion.community/post/ethercat-drivers-8802560?pid=1297869655
Configurable with fairly simple conf file.

Problem is, EtherCAT networks can get rather big and complex and writing and managing this conf file for practical projects becomes nonviable, keeping that many numbers, addresses etc straight manually is just not practical. Especially because making a mistake will result in OpenPLC crashing and burning with a segfault.

So clearly, an UI is needed for this configuration.

Luckily extensions can be added to PLCOpen editor.

So my first idea is to do just that. Write an extension that can use SOEM slaveinfo to scan the EtherCAT network. Use the ESI description files provided by device manufacturers to get information about the devices, draw out device tree, IO variables, PDO configurations, CoE registers etc. With that information do the linking to OpenPLC variable lists and in the end generate the conf file that tells OpenPLC how to put two and two together.

Now then, does anyone here have experience writing an extension for Beremiz and could give me some tips to start out? Or even point me towards an existing EtherCAT extension for Beremiz, I know similar things have been done with Beremiz, I just couldn't find source anywhere. Any existing extension would still have to be modified to work for OpenPLC, but it would be lot less work that starting from zero.
Reply 0 0
skv
Hi,

PLCOpenEditor doesn't support extensions. If you want to write extension, then you'd better go with Beremiz. It has infrastructure for extensions. Most features in Beremiz are made using extensions: Python runtime support, C extension, wxHMI, Modbus support, CANOpen support.

There are several articles about how to write own extension, but they are in Russian (see http://www.beremiz.org/doc).
But the project is open source and you can look at Beremiz source code on bitbucket for examples.
For EtherCAT extension you probably require some non-trivial configuration interface. You may look how CANOpen extension is done.
If you have any questions about Beremiz and writing extensions, you are welcome to ask on beremiz-devel mailing list (https://sourceforge.net/p/beremiz/mailman/beremiz-devel/). You have to be subscribed to post there.
Reply 0 0
r2k-in-the-vortex
Yeah, Beremiz extension was what I meant. I had a quick look and poke at it, but I don't really have much experience with python and I didn't get very far. I'll try to revisit the idea when things calm down at work and I have time to spare again.
Reply 0 0
skv
If you can write rudimentary EtherCAT support for OpenPLC, then you certainly will learn Python very quickly.
It's created to be easy to learn.


Start then with simple one.
Look at the c_ext (C extension), it does not much. Only couple of small python files.
Here is the basic information about Beremiz extensions.
Main goal of any extension is to generate C file, that will be compiled with other C source code generated by matiec (IEC to C compiler).
Every extension has four callbacks:
__init_XXXXX        - called before starting PLC program
__cleanup_XXXXX  - called after finishing PLC program
__retrieve_XXXXX - called before every PLC cycle (get values of input variables)
__publish_XXXXX  - called after every PLC cycle (set valous of output variables)

All extensions are registered in features.py (see catalog variable).

Join beremiz-devel mailinst list. I think together we could create wiki article to help other people understand who to write own basic Beremiz extension. =)
Reply 0 0
r2k-in-the-vortex
Oh, thank you very much skv.
I figured out the Features.py part, easy enough, just add
('EtherCAText', _('EtherCAT adapter'), _('Add EtherCAT adapter'), 'EtherCAText.EtherCAT'),

It appears in Add element menu and getting the correct icon for it wasn't exactly rocket science. 

The PLC synced callbacks at this point are not really important, I'm not currently planning to make live IO monitoring or manual read/write ops, maybe one day. 
The goal is to just generate the config file with device settings and IO variable linking.

To that end I need bunch of config views, adding and editing the treenodes under the extension root node, and lots of putting two and two together from various xml and text sources.
And eventually spitting out the textual conf file that my OpenPLC EtherCAT extension reads in, that's the easy part I guess.

The part I stumbled at was creating the appropriate config menus, Editors I guess, but they are just views with appropriate textboxes, drop down menus and buttons.
But I didn't quite figure out what does what with all the wx controls and properties, what parts are essential and what are not.
Reply 0 0
skv
You *do* need PLC synced callbacks. They are used to update your linked IO variables in PLC program. By the way, live IO monitoring for linked variables and manual forcing of variables you get for free with Beremiz.

On this forum nobody except me can answer your questions.
Better move this discussion to beremiz-devel mailing list, because over subscribers (some of them have written own Beremiz extensions already) could give you some tips and correct my comments. And this discussion will be more useful for Beremiz users, than users of OpenPLC.
Reply 0 0
r2k-in-the-vortex
Ah, I get the idea. I already have the IO updating in OpenPLC EtherCAT driver, the problem is that writing the conf file for that manually is not practical if you have system that has a larger number of IO-s and devices.
The idea is to generate that conf file with the extension.

I guess i'll move the discussion to your recommended mailing list. But at the moment, I don't really have the time to dedicate to this project anymore, idle time at work ran out.
I'll revisit the project once I have lots of spare time again. Maybe I have to reconsider how I do it.
Reply 0 0
skv
Generate conf file with Beremiz extension is not a problem. It's python, you can do everything. :-)
By the way, if tree-like structure of nodes with simple fixed list of properties for every node is good enough for you, than you don't need to make GUI yourself. Just describe all your nodes in XML schema and Beremiz will draw UI for you and handle load/store operations in XML for your configuration (see attached Modbus example).

Bildschirmfoto von 2017-09-19 09-55-35.png 

You only need to write couple functions:
 1. One that says PLC program what variables are exported on what IEC address
 2. Code to update variables at runtime (and in your case code to generate from project nodes conf file).

You can look at Mario's Modbus extension, how to do it. This is not complicated.
https://bitbucket.org/mjsousa/beremiz/src/c1298e7ffe3a3079ffa1e3e3fdc4548b2213bc04/modbus/?at=default
Reply 0 0
r2k-in-the-vortex
Hmmmzz.. great tips, thank you. It will be a while before I can work on it tho, I'll be out country for a month or so, maybe I'll find time when I get back, will see.
Reply 0 0
Reply