Jump to content
  • Sign in to follow this  

    How to use PLC with SQL Database?

       (0 reviews)

    caixiaofeng

    In today’s world of industrial automation, data is a very important part. Getting instant data from sources and using them for different purposes is as crucial as running a system.

    Everyone usually knows how to integrate SCADA with various database systems, like SQL servers. However many ignore the power of PLC in integrating with databases. They too can be used for this purpose.

    PLC with SQL Database

    11-1.jpg

    If we use PLC, programmers can work with them in emergency situations like SCADA failure and get their work done by coding it appropriately. In this post, we will see how to use PLC with SQL database.

    For those who are not familiar with SQL server, it is a database management tool which stores a large amount of data in real time format sequentially, and queries are written in it either through some external source, like a PLC, for retrieving data.

    For storing data in it, logic is written in PLC which when executed stores data in SQL. This is a simple concept, which is explained further in the post more briefly for it’s advantages.

    Scheduler PLC

    Suppose you have a very large-scale system where the operator has to feed hundreds of time schedules for operating particular functions every day. Instead of using vast coding and variables in PLC for storing data entered in SCADA and operating it once the time arrives, just feed all the variable data to the SQL server through PLC every time a new recipe is created.

    The SQL will store real-time date and time of the values entered and will give operators option of choosing them according to date and time filtered. For example, the SQL has five entries from 1st Oct to 5th Oct for various types of schedules entered. The benefit is that the operator can choose any one required and then run the system.

    If SQL was not there, he would have to run only one option of either 1st Oct or any other date. Or else, he would have to utilize memory of SCADA or PLC, which is waste of data and coding. This same thing becomes easier through SQL server.

    Another advantage is that SCADA code size becomes reduced and it would be used for other purposes. Scheduling is used in many applications and using PLC for it along with SQL makes system more efficient.

    Sequencing

    Consider a plant having 10 sequences. Every sequence has a barcode reader in it for starting the action on the required product. If the barcode is read in SCADA, then the corresponding data feed to PLC or in short, SCADA is the medial intervene for initiating communication between PLC and data; then just directly connect PLC with SQL.

    SQL will directly communicate with PLC for determining barcodes and other data for starting or stopping a sequence. Such bulk data from plant sequences helps reduce coding in SCADA and makes system faster to operate. Because PLC is written with coding for sequence operation, why not directly connect it with SQL and use the system.

    Synchronize multiple PLCs

    There are many applications where one PLC in a location needs data from another PLC location for doing a work. In that case too, traditionally SCADA is used for integrating all the PLC’s and managing them.

    In that case, if PLCs are directly connected to the SQL server, data will be synchronized through the date and time of SQL; thus, eliminating problems of multiple RTC (real-time clock) synchronization of PLCs.

    Also, PLC will directly communicate with other PLC for asking any data or give any data through the SQL server. Any alarm or event in a PLC will also be communicated to other PLC and would help in tracking real-time records.

    Handshaking

    Handshaking is a process where one party is acknowledged by the other party that the job has been completed. Basically, it is a response required so that the party can start its other work. This method works well with PLC and SQL servers.

    The SQL server can directly communicate with PLC by sending event notifications in real time, or alarm notification data in real-time. This means, suppose that the job has taken 3 days to complete.

    Then the completion acknowledgment will be sent as a separate event to the PLC, and as it also has 3 days of data in it, the operator can view the whole process in SCADA reports easily. So, handshaking is an important reason for communicating PLC with SQL directly.

    PLC Database Basics

    • Establish a connection between the PLC and the SQL database using middleware or a gateway that facilitates communication between industrial network protocols and database languages.
    • Select a communication protocol that both the PLC and the SQL database can understand, such as OPC UA, Modbus TCP, or any other protocol supported by your PLC and middleware.
    • Configure the PLC to send and receive data by setting up the necessary parameters, registers, or tags that will be read from or written to. This might involve programming the PLC using its respective software to ensure it’s ready for data exchange.
    • Set up the SQL database by creating a new database or configuring an existing one to store data from the PLC. Define tables, columns, and data types that align with the data structure being sent from the PLC.
    • Map each PLC data point to the corresponding field in the SQL database. Ensure that the data types are compatible and that the mapping makes logical sense for the application’s needs.
    • Implement data transfer logic using scripts or database stored procedures. Determine how often data should be transferred, under what conditions, and whether the transfer should be triggered by events or on a schedule.
    • Test the communication between the PLC and the SQL database thoroughly. Check for any errors or data mismatches and ensure that the system behaves as expected under various conditions.
    • Continuously monitor the system for operational integrity, data accuracy, and any anomalies. Set up alerts or notifications for system errors or significant events.
    • Regularly review and update the system as needed to accommodate changes in the PLC setup, database structure, or additional requirements. Keep documentation updated for any system changes.
    • Ensure security measures are in place for both the PLC and the SQL database to protect against unauthorized access and data breaches. Consider implementing encryption, firewalls, and secure access protocols.
    Sign in to follow this  


    User Feedback

    Recommended Comments

    There are no comments to display.



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

Apply for friendship links:WhatsApp or E-mail: admin@plchmis.com
×
×
  • Create New...