Data Transfer From PLC to PC
by Aerobot09 in Circuits > Electronics
9618 Views, 6 Favorites, 0 Comments
Data Transfer From PLC to PC
Hope you all are doing well!!! As in the last article, we learned about accessing the built-in display of PLC to display custom text on it, in this article we will learn about data transfer from PLC to PC using TCP protocol for Siemens LOGO! PLC. The process remains the same for all PLC, the only variables are protocols and a custom python script. Using this process, the input devices connected to the PLC can be monitored. The python script extracts the data from PLC and can create an excel file of the data. This process does not require any proprietary software of PLC. PLC is crucial for industrial automation and controls almost all industrial functions. By logging the data flowing through PLC, it can be later used for analysis and might improve the overall efficiency of the process. PLC is preferred for the task of industrial automation, rather than microcontrollers, as PLCs are more suitable for handling those tasks and are designed to handle more current.
Supplies
Software:
- Siemens LOGO!Soft Comfort
- Python 3.7+
Hardware:
- Siemens LOGO PLC
- Siemens power supply
- Ethernet cable
- Connecting wires
- Push Button
Here, I have used Push Button to simulate inputs from the external device, in practice, the PLC can be directly given input signals.
Information Flow
The inputs are connected to the PLC, the signals from inputs are processed (if necessary) and subsequent output signals are given out. For monitoring of either inputs or outputs, a regular connection with the PLC-PC is made by the means of an ethernet cable. This cable can also transfer the program from PC to PLC.
Python Programming - I
Python programming is crucial for the extraction of data from PLC. The python program will use a specific library designed for the PLC. As in our case, we are using Siemens LOGO!, the python library we are using is “python-sanp7”, it does even support Siemens S7 PLCs. The documentation for the library can be found Welcome to python-snap7’s documentation! — python-snap7 0.0rc0 documentation, just copy the underlined text and enter it on google. The library can be installed in python using the command “pip3 install python-snap7”. The library has various methods such as of
• connect()
• get_connected()
• read()
• write()
• destroy()
and many more. These methods are important for python programming. The sample program shows the implementation of these methods. The python program is used for establishing a connection between PC and PLC. Various parameters need to be passed for the “connect” method. It mainly requires the IP address of the PLC for successful connection.
Python Programming - II
The python program is modified further to read the data from the PLC using the “read” method. The data then can be displayed on the screen using the “print” method. The “read” method requires the address of LOGO! memory. The data is updated every second, or as per the program.
Excel Sheet Generation
For the generation of the excel sheet, another python library “xlsxwriter” is required. The installation process for the library is the same as “pip install xlsxwriter”. The documentation of the library can be found XlsxWriter · PyPI, just copy the underlined text and enter it on google.
Excel Logging
The programs from Step 3 and Step 4 are combined. The program will make an excel sheet and log all the input and output data. Once the logging is stopped, the data will be dumped onto the excel sheet after which you can open the excel file that is generated and see the data. With further modifications in code, various other parameters for logging can be included such as Time and Date.
Conclusion
Data extraction can be used for many purposes. The above process is specifically used for Siemens LOGO! and S7 PLCs. However, with several modifications in program the program can even work for PLCs from other manufacturers. In future articles, we will dive into the program details for PLCs from other manufacturers.
(This article is performed and documented by Trainee Intern: Chaitanya Naik at Veloce Techinsights in collaboration with Aerobotix Techsolutions)