Substantially, downloading the Codesys ISO image and installing it into the Raspberry SD card, it's possible to transform your PI into a PLC controller. And it's for free! (you can buy the "fully licensed version for 35€, anyway the demo version run fully featured for 2 hours).

So I though to realize a cheap fully working distributed architecture where:

  • Raspberry PI= PLC Controller (Codesys 3.5 SP
  • Arduino Mega 2560= 1st remote I/O
  • Arduino Uno=  2nd remote I/O
  • Modbus TCP/IP: communication protocol

CoDeSys+ Raspberry+ArduinoLogo+Banner-Modbus= (PLC + remote I/O) 

Recently I've been involved into a PLC development environment not equipped to physical memory storage area such as Merker, DB, %T,... In that project, I had to acquire a 32 bit single precision floating point variable from remote I/O located not directly as REAL but as 2 WORDS: respectively  LSW ( Least Significant Word) and MSW (Most Significant Word). Then, starting from the floating definition (Wikipedia):

 IEEE753 32Single Wiki

     31------------------------MSW-------------------16 + 15----------------------LSW------------------------0

As I think a lot of people involved into the automation world  know , Siemens always shown a kind of "adversity" to equip its products with not-native Siemens protocols. One of these, born on far 1979 but still common, is the Modbus protocol for networks TCP/IP. Anyway, available from few years, Siemens release its on licensed-library in order to use Modbus TCP communication into the PN type CPU (300, 400, 400H), into the CP (343, 443) or into the CPU-PN equipped ET200S. Recently I had the possibility to test this library developing an application (S7-317 2PN/DP)  who needs to run as Modbus Master (Client) reading / writings data to some relay controller (Areva) in order to control an hydroelectric power plant. Then I though to wrote this tutorial as a memo for some future similar jobs. Wish it'll be useful you too.

Into this article I'll explain hot to implement to modbus TCP Client (Master) functionality into a CPU S7-315 2PN/DP firmware 3.2. Here follow hardware and software needed coponents:

  • Software S7 Open Modbus TCP CPU PN Single License cod.2XV9450-1MB02 v.1.3 (for details take a look at)
  • Software Simatic Step 7 v.5.5 service pack 3
  • CPU S7 315 2PN/DP cod 6ES7315-2EH14-0AB0 + MMC (512kb is enough)

In this article I'll describe how to use an ANY data type as pointer input in a simple subroutine in Simatic Step 7 v.5.5. ANY parameter type, according to Simatic on-line help, is a 10 byte length with the following structure:

ANY Definition

Reading some forum and blog about  some Modbus implementation for Arduino I feel my curiosity grow up about that..then I decided to test it on my on Arduino Mega 2560 board. I have to admit I've been successfully surprised! In few steps I saw a full running system that could represent a good source point to practice with Modbus Scada (as Proview). Following I wrote the steps I've done:

HW used:

  1. Arduino Mega 2560 
  2. Arduino Ethernet Shield R3

Software used:

  1. Arduino IDE 1.5.5 (free download  from Arduino main website)
  2. Arduino Modbus TCP server (Mudbus.h v.1.0)