Ts4
Hi I am new here, I would like to use the Ethernet/IP communication protocol for my PLC.  How would I go about implementing this on the openPLC?
Quote 0 0
thiagoralves
OpenPLC's network layer is responsible for the network communication over SCADA protocols. In order to respond to network requests from the SCADA protocols, this layer has access to the input and output image tables, which are memory regions defined in the OpenPLC application that stores the current state of all inputs and outputs. Specifically, they are defined in the arrays: *bool_input[][], *bool_output[][], *int_input[], *int_output[], which represents digital inputs (%IXn.n), digital outputs (%QXn.n), analog inputs (%IWn), and analog outputs (%QWn) respectively. 

The base functionality of the network layer is implemented in the server.cpp file. This file contains routines to create, bind, open and close TCP/IP network sockets on a threaded environment. Once a connection with a client is established and a message is received, the message is then forwarded to the routine that can interpret the protocol-specific data. Currently, as you may know, OpenPLC has support for Modbus/TCP and DNP3 protocols. You can check the modbus.cpp and dnp3.cpp files to understand how the specific implementation of each protocol was made, and then try to implement Ethernet/IP using the same approach.

Modbus implementation was built from scratch, based on the Modbus Application Protocol Specification, which is a document released by the Modbus organization that defines the protocol. OpenPLC's Modbus implementation uses the routines from server.cpp for TCP socket handling and parses the protocol-specific messages on the modbus.cpp file.  Modbus is a request/reply protocol and offers services specified by function codes. If you check the modbus.cpp file you will see that it has a bunch of functions, each one responsible for a specific Modbus function code, like ReadInputRegisters(), WriteCoil(), WriteRegister(), etc. The data is received by the main function processModbusMessage() that parses the packet looking for the Modbus function code. Once the function code requested is found, the packet is redirected to the specific function inside the modbus.cpp file that will take care or processing it.

The DNP3 implementation was based on the opendnp3 library and therefore does not make use of the server.cpp file. Opendnp3 is a portable, scalable, and rigorously tested implementation of the DNP3 protocol stack written in C++11. The library is designed for high-performance applications with many concurrent TCP sessions, although it can also be easily embedded on smaller platforms. You may also want to check if there are any Ethernet/IP libraries that are trustworthy and open source and then use it to implement Ethernet/IP on OpenPLC, instead of writing your own implementation from scratch.
Quote 0 0
pedromorgan
Hi @thialgroves...
Its valuable stuff like this that should go into a manual.. imho.. as we discuss..
Quote 0 0
thiagoralves
Hi Pedro. You’re right. I’m writing my PhD thesis right now, and most of the stuff I wrote in the post above was actually a copy/paste from my dissertation. Once I have my dissertation finished, there will be plenty of documentation for the project. I might then just convert it into a wiki and be done! 🙂
Quote 2 0
Ts4
Thank you all for the help! I think I will try and use OpenER and implement it on openPLC.
Quote 0 0
pedromorgan
Out of curious.. in what "format" are u writing the "differtation"... markdown ?

Maybe u should create your dissertation in a repos, so all u punters can validate it for u..? (ducks)
Quote 0 0
pedromorgan
BTW.. I better get the webserver part fixed soon, cos if we need to make it works, before u submit it.. !!! 
Quote 0 0
thiagoralves
pedromorgan wrote:
Out of curious.. in what "format" are u writing the "differtation"... markdown ?

Maybe u should create your dissertation in a repos, so all u punters can validate it for u..? (ducks)

I'm writing my "differtation" in latex. I'm almost finished with it, putting it in a repository will just make it a mess. Should I share what I have here?
Quote 1 0
jjmg
"You may also want to check if there are any Ethernet/IP libraries that are trustworthy and open source and then use it to implement Ethernet/IP on OpenPLC, instead of writing your own implementation from scratch."

https://github.com/leicht/TuxPLC/tree/master/tuxeip
Quote 0 0
thiagoralves
All libraries I checked (including the one you posted) only implements the client side of the protocol, i.e., making requests to the PLC. What I need is the server side, which means, the one that receives the requests. I was able to find one library that implements the server side, but it only handled the ground generic part of the protocol, and was of no use to me.
Quote 0 0