Basics 06: Communicate with OpenPLC Runtime using Python
Вставка
- Опубліковано 24 жов 2024
- On Basics 06 we will use Python and PyModbus to communicate with your OpenPLC device over the network. We will also dive into the Modbus protocol to understand what type of data we can retrieve from our PLC runtime. Finally, we will build a little terminal application in Python that retrieves and displays PLC data in real time
Modbus deep dive 00:54
Crafting the test program 06:11
Programming an ESP 8266 10:16
Playing around with Python live 13:31
Running our Python program 19:06
openplcproject...
Please consider supporting OpenPLC by joining our Patreon: / openplc
OpenPLC Friends:
Freewave
FACTS Engineering
this is awesome. thinking of using this as a cybersecurity project on the modbus protocol to pentest devices operating on that protocol
Thank you so very much for the quality of your video courses.
Glad you like them!
thank you Thiago!
You will change the IoT and PLC world ... that is 100% the tool for fighting the world climate change.
My dream is a toolbox of "energy-saving FunctionBlocks" and project-templates for i. e. heatpump, aircondition and cooling applications.
I will try to help🙄
Well explained. Do we have features on OpenPLC to make ESP32 as Modbus Master to make it read values from another Device/PLC, RTU or TCP over RS485 or Ethernet?
This will be added in future releases
This is absolutely brilliant! Thank you so much
Hello Thiago. This needs a device able to run Python, like a Raspberry Pi with an OS. A lot of sensor have a C library to run on µC like Arduino. Would it be possible to mix LADDER and C/C++ programming to run on an Arduino ?
Thank you very much ! Could you please present a scenario where you interact with multiple slaves instead of only one ? I'm curious to see how it has to be configured on the OpenPLC side
From the Python perspective, all you have to do is connect to each one of your slaves individually using client_n = ModbusTcpClient('slave_ip_address'). Then each 'client_n' will be an instance connected to a particular slave.
@@openplc Thank you ! Clear from a Python perspective, but how would you manage multiple slaves from the OpenPLC perspective ? By assigning the location attribute of your variables to one slave or another ?
@@EpicCalamar That's quite simple. As you add more slaves on the Slave Devices tab you will see the I/O mapping for each one of your slave devices on the slave devices table. For more information, check this video ua-cam.com/video/dQ8GcfpGDuA/v-deo.html particularly from minute 7:45
I could not read the counter_value. then I assign the counter_value to the location: %QW1 and was able to read the counter_value , just in case some body was having the same problem. Also I use a program called ModbusTool V 1.1.4 an the register values were reading %QW0 (counter_max) = 2560 instead of 10, to fix that changing the byte order to: 2143 (was 1234 by default)
That cmd programming is a strange method to do live edits
Thank you and Can I get this code?
Do you mean the Python code? Here it is:
from pymodbus.client import ModbusTcpClient
import time
client = ModbusTcpClient(“192.168.0.192”)
if client.connect() is True:
while True:
rr = client.read_holding_registers(0,2)
print(“Counter value: “ + str(rr.registers[1]))
time.sleep(0.3)
✌