Modbus TCP Data Logging to Database

gclshortt

Member
Join Date
Dec 2014
Location
Ontario
Posts
3,217
Here is a recent post that I would like to share.

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.

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.

Read the rest of the post...

See on YouTube:
https://www.youtube.com/watch?v=0edjwp6uai8

Let me know what you think,
Thank you

ModbusTCP MSAccess 010-min.png ModbusTCP MSAccess 080-min.png
 
I looked at your website and I thought it looked good and interesting overall. However I don't know your intended audience but I would have liked to see a more industrial strength solution to the same problem.

To make more industrial and able to move it to something where you could actually use this, there are just a couple of small things you could change.

1) MS Access is not free and not suitable to use as a real database. Use MS SQL Server Express instead. It's free and it's a real database and it works the same as the big brother SQL server.

2) After showing that it worked make the VB.NET application a Windows service instead. It's a pain in the behind to have data collection running as a regular desktop application because then you have to be logged in for it to work. Make it a Windows service instead so it can log data in the background.

With these small suggestion you could actually take your sample project and use it in a real application.


Another couple of small suggestion would be:
3) Don't use a date field and a time field. Use a date/time field instead so you have both in the same field. Makes it a lot easier to sort.

4) Also add a tagname to your table and put in one row for each value you are collecting. It's more expandable and you can retrieve just one set of values if you like. So the columns in the table would be "timestamp", "tagname", "value" or whatever you like to call them.

5) In a future episode/version of your sample project you could change your service so it would fetch it's what values it would collect from a configuration table in the database. That way you could have a table with all values you wanted to collect and if you restarted the service it would read these values and start logging them automatically. An excellent way to make it configurable. Now you have a modbus tcp historian!

.
 
Last edited:
Hi Pete,
Thank you for your feedback.
The intent is to give people an idea of how data is retrieved moved around and stored.
1 - MS SQL Server Express is a good alternative 10GB of database storage compared to 2GB of storage in an Access database and free.
2 - VB.NET application as Windows service is a good idea for deployment.
3 /4 - Date/Time field and the table names would be an improvement
5 - Great idea on making a Modbus TCP Historian.

Thanks again Pete for your suggestions,
 
Hi Garry,

I was given this link by Pete S as it offers something which might be able to help me in a project.

For what I need, I would want to read a Data Block within Siemens S7 PLC, and every time one of the data bits becomes TRUE, log in in a database, along with Time and Date.

In your example, you are transferring a value into a register and that value is being read every minute.

For me, I won't be dealing with values and registers and would want the data to be recorded on a change. If I monitored every minute then I may miss changes in the data block.

Any suggestions on how to do this?
 
Hi Leem
I would start by looking at the program in the PLC. When the bits turn on and you want to log the data, move it to a location and increment the address.
The SCADA system can then read the location to see if any data needs to be logged. If there is the system will read all of the values and reset the address to store the information.
This is what I refer to as robust logging. It will read the data always, whether we are connected or not. Timing for the SCADA system does not have to be instantaneous.
https://dl.dropboxusercontent.com/u/33455595/Robust%20Data%20Logging%20for%20Free.pdf

Hope this helps,
 
Hi Leem
I would start by looking at the program in the PLC. When the bits turn on and you want to log the data, move it to a location and increment the address.
The SCADA system can then read the location to see if any data needs to be logged. If there is the system will read all of the values and reset the address to store the information.
This is what I refer to as robust logging. It will read the data always, whether we are connected or not. Timing for the SCADA system does not have to be instantaneous.
https://dl.dropboxusercontent.com/u/33455595/Robust%20Data%20Logging%20for%20Free.pdf

Hope this helps,
Hi Garry, I read this through your website.

I'm still at a bit of a loss as to how to get the DB to report as a list.

Again, this data in your (excellent - btw) guide deals with numbers.

For me, I'm not after numbers.

I'll try and make it clearer....

Here is a (made-up) sample of a Datablock we have which is used for errors, warnings and messages to be displayed on the control desk HMI.

Sample-DB.png


As a bool bit becomes true, I want my data logger to detect it and add it to a database. The database will log any event and add a time stamp. This database can then be queried to create a list of errors between certain dates/times. It can be very useful for fault finding purposes as often many warnings go un-reported until there is an error.

Log.png


So... my requirement doesn't deal with numerical data. I'm not sure how to send this data and how to get the logging system to interpret it (mainly because I have NO experience in passing data from S7 to anything other than Siemens devices!)

This is a new avenue for me (so forgive me if I seem a bit daft in this area!) and something I'd really like to implement in our plant for various reasons. I'd like to find out what the top errors are on the machines which we can use to focus our pro-active engineering tasks. Also, as much as you ask operators to report certain errors, quite often they reset and run on and after a while it appears "fixed" until something big breaks!
 
Hi Leem,
So you have basically 2 words (16bits) of data. One way is to read the two words of data and then look for the bits that are on and then log to the database.
http://accautomation.ca/building-a-plc-program-that-you-can-be-proud-of-part-6/
This above link will show you how to break the words into bits using VB.

The other method would be to log the data into the memory of the PLC when the bits turn on. You would move the information indirectly when any of the bits turn on and then move the date, time and 2 words into the PLC memory.

Regards,
 

Similar Topics

I am working on a project, inside an AB CLX, I implemented the Modbus TCP Client AOI published on AB website, to interreact with a Modbus ASCII...
Replies
7
Views
3,457
I've got 16-bit data at address 40200 on a Schneider Scapack 350. I can grab the data over Modbus TCP using Kepware at IP 172.16.1.100. When I...
Replies
8
Views
2,427
Hi all, Has any of you got any example of reading data from modbus tcp, using FBD? I am just trying to get my head around, doesnt look like a...
Replies
6
Views
2,483
Dear all, glad to be here and I hope that we all can benefit from this great community. I am trying to send and receive data between two Mico850...
Replies
4
Views
2,668
Back
Top Bottom