If you are looking to purchase a PLC system, there are three key components that you should look for. If your current system does not contain these features, you need to replace it with one that does as soon as possible. The three most important features you should look for in your new PLC system are the open communications protocol, the ability to integrate easily with other methods, and the ability to have remote access. Without these three essential requirements, your PLC system will be far less effective and will be more expensive to operate than it needs to be. We are all data companies that need the information for continued improvement. The industrial internet of things (IIoT) is essential, and the ability to take advantage of this starts with the hardware you specify for your PLC control. PLCs are now considered edge devices. This means that information should be able to be sent and received to the PLC controller when it is required.
A human-machine interface (HMI) is present in some form for every PLC. The HMI connects a user to a machine system to exchange information or control data. This interaction with the system can be through hardware or software.
HMIs offer different people information and control in many ways for the automated system. Operators, supervisors, mechanics, electricians, engineers, and programmers all have different needs. The machine HMI(s) must provide or make the information easy for all the people who use the system.
We will now look at some of the ways that human-machine interfaces (HMI) are used in automated systems today. Let’s get started.
Accelerate Learning …
Accelerate Knowledge… ACC Automation In this Covid-19 world, we are continuing to adapt. Social distancing, mask-wearing, hygiene, etc are the way we currently live. Video conferencing with Zoom, Teams, and Google Meet are the norm in business today. Information is knowledge, and everyone more than ever wants to be able to see, control and summarize production data on a regular basis. Open intuitive technologies are available to communicate like never before. Industrial plant data is rapidly changing. Factory 4.0 benefits are being seen and everyone wants to take advantage. We are looking forward to the New Year and new possibilities for implementing your control solution.
Each year we like to take a few minutes and reflect on the past, current, and future of ACC Automation. You have helped us to build the site that you see today through questions, comments, and suggestions. Thank you.
Microsoft SQL Server Express 2014 is a free, edition of SQL Server this is ideal for learning and developing desktop, web, and small server applications. The database size can be 10 gigabytes in size. SQL Server Express 2014 release includes the full version of SQL Server 2014 Management Studio. We will be using SQL Server 2014 Management Studio (SSMS) to create a database. The SQL Server database will be created so we can connect to it for data acquisition (data logging) from our PLC applications.
Microsoft SQL Server Express 2014 is a free, edition of SQL Server this is ideal for learning and developing desktop, web, and small server applications. The database size can be 10 gigabytes in size. SQL Server Express 2014 release includes the full version of SQL Server 2014 Management Studio. This is a method to read, write and maintain our database. (Tools) We will be installing this SQL Server database so we can connect to it for data acquisition (data logging) from our PLC applications.
Installing the software – SQL Express
Download the software
The download file can be obtained from the website for SQL Express 2014. https://www.microsoft.com/en-ca/download/details.aspx?id=42299
We will be installing the ExpressAdv 64Bit\SQLEXPRADV_x64_ENU.exe on a windows 7 64 bit machine.
This is the latest software that can be installed on the Windows 7 operating system.
Using Visual Basic 2015 we will log three holding registers from the PLC along with time and date into a Microsoft Access Database. We will log every minute into the database with the information that we collect from the PLC via Modbus TCP (Ethernet). All code will be done and shown so you can implement this in your application with different parameters. The information collected in the database can then be distributed or analyzed in the future.
VB.net Modbus Data Logging to Access Database
Visual Basic 2015 will be used with the EasyModbusTCP client/server library for .net. We will communicate to an Automation Direct – Do-More PLC. Using the free simulation software of the PLC Designer Software, we will retrieve three values of the Modbus Holding Registers using Modbus TCP. Once we have this information out of the programmable logic controller it will be placed in a Microsoft Access (2010) Database. This will be done by using a SQL command to insert the data.
We will start with the PLC program. The first three holding registers will be used. That will be MHR1, MHR2, and MHR3 in the Do-More PLC. This will correspond to register numbers 40001, 40002, and 40003. The following is a table with all of the references for Modbus communications to the Do-More.
0000 to 270E
MC1 to MC1023
Discrete Output Coils
0000 to 270E
MI1 to MI1023
Discrete Input Contacts
0000 to 270E
MIR1 to MIR2047
Analog Input Registers
0000 to 270E
MHR1 to MHR2047
Analog Output Holding Registers
Note:The Do More PLC uses the Modbus area to communicate. This is because having direct access to the digital I/O can be dangerous when connected via Ethernet to the internet. Data must move in and out of this area via the PLC program.
Here is the PLC program that sets the three registers.
Access 2010 Database Setup – Modbus Data Logging
The next thing to do is set up our Microsoft Access 2010 Database. Our database will be named ACC_Database and it will be located at the following location: “C:\AccLog”. We will have one table called ACC_Log. In the table we will have five fields; LogDate, LogTime, Register1, Register2, Register3.
EasyModbusTCP is a Modbus TCP, Modbus UDP client/server library for .NET, and Client library for JAVA. .NET (.dll) Client/Server also supports Modbus RTU. It supports the following function codes: – Read Coils (FC1)
– Read Discrete Inputs (FC2)
– Read Holding Registers (FC3)
– Read Input Registers (FC4)
– Write Single Coil (FC5)
– Write Single Register (FC6)
– Write Multiple Coils (FC15)
– Write Multiple Registers (FC16)
– Read/Write Multiple Registers (FC23)
Now we will call up visual studio and create our project. The first thing that we must do is reference our EasyModbus.dll file.
Our program will log the three registers based upon a timer function. When the time expires we will set the interval to 1 minute and call a subroutine (Button1). This subroutine will communicate to the PLC via Modbus TCP and get our three registers. It will then insert the data from the registers along with the time and date into an access database.
Here is what our visual basic form will look like:
Here is the visual basic code for our project. We use the Imports command for the EasyModbusTCP namespacing.
Imports EasyModbus 'Import the EasyModbus
Here is the part of the subroutine that will communicate to the PLC via the EasyModbusTCP, You will notice that we have used the ‘Try’ command on the ModbusClient.Connect() statement. This way we can track if we are communicating or not to the PLC.
PrivateSub Button1_Click() Handles Button1.Click
'This subroutine will communicate using the EasyModbusTCP to the PLC
'This will execute when the user clicks the button or at specific intervals from the Timer1
Dim ComError = 0 'Set communication error flag to 0
'Specify the IP Address and Port Number that we are connecting
Dim ModbusClient As EasyModbus.ModbusClient = New EasyModbus.ModbusClient(TextBox1.Text, 502)
ModbusClient.Connect() 'Connect to the PLC
Catch ex AsException'What to do when an error occurs
Label10.ForeColor = Color.Red
Label10.Text = "Communication Error!"
ComError = 1 'Set communication error flag to 1
If ComError = 0 Then'Do the following when communication is OK
Label10.ForeColor = Color.Black
Label10.Text = "Logging..."
Dim Registers AsInteger() 'Where to store the information
Registers = ModbusClient.ReadHoldingRegisters(0, 3) 'Read three registers starting at the first one
Label1.Text = Registers(0) 'Value of MHR1
Label2.Text = Registers(1) 'Value of MHR2
Label3.Text = Registers(2) 'Value of MHR3
ModbusClient.Disconnect() 'Disconnect from the PLC
Here is the code to open the database connection and insert the data into our ACC_Database file. We use the ‘Try’ command to ensure that if errors occur it will not stop our program. The connection string ( Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\AccLog\ACC_Database.accdb) may be different then yours. In order to get your connection string, please review the following from a previous post and search for the connection string.
'Log values into an Access Database
'We will use a SQL instruction to insert a record into the table
Dim SQL AsString'SQL Command String
Dim objCmd AsNew OleDb.OleDbCommand'Command
'Connection String to the Access Database
Dim Con = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\AccLog\ACC_Database.accdb")
'SQL Statement - All values must be set for the table
SQL = "INSERT INTO ACC_Log VALUES ('" & Now.ToString("yyyy/MM/dd") & "', '" & Now.ToString("hh:mm:ss") & "', '" & Registers(0) & "', '" & Registers(1) & "', '" & Registers(2) & "')"
Con.Open() 'Open the database connection
objCmd = New OleDb.OleDbCommand(SQL, Con) 'Set the command
objCmd.ExecuteNonQuery() 'Execute the SQL command
Con.Close() 'Close the database connection
Catch ex AsException'What to do when an error occurs
Label10.ForeColor = Color.Red
Label10.Text = "Database Error!"
This timer is originally set for 100ms. When the program starts, it will log the first time and then set the timer interval to 1 minute. (60000ms)
PrivateSub Timer1_Tick(sender AsObject, e AsEventArgs) Handles Timer1.Tick
Label9.Text = Now 'Display time and date
Timer1.Interval = 60000 'Set interval for 1 minute
Timer1.Enabled = True
CallSub() Button1_Click() 'Call the routine to get the PLC information and store in a database
This will handle the LinkLabel on the form.
PrivateSub LinkLabel1_LinkClicked(sender AsObject, e AsLinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
' Specify that the link was visited.
Me.LinkLabel1.LinkVisited = True
' Navigate to a URL.
Running the program:
The status will show ‘Initializing..’ so that the imports can be loading in the program. This will happen each time the software starts.
Logging will be displayed in the status to indicate that everything is working correctly.
Error messages will show in the status when an error has occurred. We have programmed two errors: Communication Error! – Information is not being received from the PLC. This could be due to the wrong IP address or communications links have been broken. Database Error! – Information cannot be written into the database, the database is not present, etc.
Here is what our database looks like after collecting a few samples.
As you can see, collecting information from the PLC via ModbusTCP and inserting it into an Access database can be easily done. The next step would be to ensure that the data is always collected. What happens when the communication to the PLC is cut? Robust logging is required. This is when we create a buffer in the PLC of the logged values. Please refer to our EBook ‘Robust Data Logging for Free’ .
If you have any questions or need further information please contact me.
If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLCs are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII, and Floating Point.
To get this free article, subscribe to my free email newsletter.
Use the information to inform other people how numbering systems work. Sign up now.
The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.