Tim_J
Hi Thiago, 

I am working on a project on network security of Modbus protocol. As a student I have limited resources but do have a Raspi 3 and a PC. I would like to use OpenPLC as a softPLC on the Windows machine to control a simple temperature control system that is running off of my Raspi 3. Ideally I would just use an Arduino as there is already the device type set up in the 'add new slave' however, my budget is limited. So I was wondering, is it possible to set up the raspi in the same way as the arduino would be? Or have I overlooked some factors?
Also, would the pin mapping be the same? 

BR
Tim
Quote 0 0
thiagoralves
Yes you can. Just use a blank program on the Raspberry Pi and make sure it is running. Then on the PC add a Generic Modbus TCP device and make sure the mappings match the available pins on your Raspberry Pi, e.g. the Pi has 14 digital inputs (input status), 11 digital outputs (coils), and 1 analog output (holding register). Then the addressing available on your PC will follow the normal slave device addressing (IX100.0, QX100.0 onwards). 
Quote 0 0
Tim_J

Thanks for the reply! 

just a couple of questions:

1) where did you get the information RE: digital I/O’s relating to the gpio ports, so I can set my circuit on the correct pins?

2) RE: The blank program; do I need to import pymodbus library and assign modbus ID on the raspi before setting into an endless loop?

Thanks for the support!

Quote 0 0
thiagoralves
1) https://static.wixstatic.com/media/757aea_6959b68b342943c980f763a6e44583cd~mv2.png/v1/fill/w_450,h_799,al_c,lg_1,q_85/757aea_6959b68b342943c980f763a6e44583cd~mv2.webp (more information at https://www.openplcproject.com/getting-started-rpi 😉

2) You don't have to do anything. Just install OpenPLC_v3 on the Pi and start it. On the PC side, configure the slave device as I mentioned. Then your Pi will work as a dumb remote I/O. All Pi I/Os will be brought to the PC runtime through the slave device configuration. The programming will happen on the PC side.
Quote 0 0
Tim_J

That’s perfect, I’m sorry I must have missed that on the rpi page!!

That may have thrown a spanner in the works for my project, I need the program to receive an INT in from a DS18B20 temperature sensor (so I needed the raspi to have a %IW input). Is there any way I could change any other pin to a %IW? 

Quote 0 0
thiagoralves
Yes, but for that you will have to create a custom hardware layer code to interface with your DS18B20 and add the readings to %IW0 (or any other %IW you want). Check this for more info: https://openplc.discussion.community/post/ds18b20-temp-sensor-and-simulation-9761433

Just remember that you will have to disable the pins you are using to connect to the DS18B20, otherwise OpenPLC will try to control those too and communication probably won't work well. The post referred above explains how to disable pins from the driver.
Quote 0 0
Tim_J
I have made my custom driver, largely taking from the resource above and also disabled the relevant IX pin. However, the traffic from both the server and client side doesn’t seem to take into account of either the current state of the GPIO pins or the ladder logic program. If I set a coil to be constantly high in the program, it still writes ‘0000’ to all coils. Also, if I read the int of the temperature sensor it’s around 1900, whereas looking at the ‘read holding register’ packet, it states it is a 0. 

There are definitely conversations between both raspi and PLC but they seem to be incorrect. Have you got any ideas?
Quote 0 0
Tim_J
Let me provide some more information about my set up:

Windows machine acing as PLC with simple LL program where if Temperature (INT) is greater than the value 1900 then a coil will activate. 
This is in a LAN with a raspi B new model with a DS18B20 sensor connected to pin 7 (was IX0.2) using the one wire interface. 

The code in the hardware section goes roughly like this:
exclude bool input 2
Define the path to devices, data buffer and device ID

init custom layer
{
obtain the correct path to one wire device
}

update custom In
{
Read the data file that the sensor outputs,
extract the current temperature,
Lock the mutex,
send the current temperature to int_input[0]
unlock mutex
}

Update custom out
{
blank
}
Quote 0 0
thiagoralves
It seems to me that you have the wrong configuration on the slave devices page and/or wrong addresses on your ladder logic program (Windows side, ladder logic for the Pi should be blank). Can you take a screenshot of those please?
Quote 0 0
Tim_J
Hi Thiago, 

On Pi side I am running the dummy empty program. Windows side looks like this:
Quote 0 0
thiagoralves
You’re using the wrong address in your program. If you check the documentation on the OpenPLC project website about slave devices, you will see that slave devices attach to address 100 and above (i.e. %QX100.0). You can see the exact location your slave is attached on the slave devices page.
Quote 0 0
Tim_J
Thanks for pointing that out, I have changed it but still makes no difference. The slave configuration is attached. I have altered the size of discrete inputs down as pin IX0.2 is no longer used, and added an IW holding register is that correct? 
Quote 0 0
thiagoralves
The fact that IX0.2 is disabled doesn’t mean it disappears from the modbus mapping, but only that the driver doesn’t control it anymore. You should keep the size the same. On the other hand, this is irrelevant for the setup to work or not, unless you were trying to read all input pins. How have you changed your main windows program? What does your windows logs (dashboard) look like
Quote 0 0