Today is...
Sunday, August 25, 2019
Welcome to Control.com, the global online
community of automation professionals.
Featured Video...
Featured Video
A demonstration of EtherCAT control of linear motors using the CTC EtherCAT master.
Our Advertisers
Help keep our servers running...
Patronize our advertisers!
Visit our Post Archive
Easy PC code for Logging Modbus TCP
Looking for source code for a Windows environment to use with Modbus so I can build a basic historian.

I am looking for some fairly basic source code for Windows so that I can poll my PLC registers about every 10s to get around 100 tags.

Then I just want to save them off into a file.

There seems to be lots of Modbus C++ code for Linux, but was looking for something I could use on Windows 10.

Not being very familiar with any Socket type functions it is a bit daunting. My C++ code is limited to processing files, so the whole getting data over Modbus is new to me in this environment.

(Generally I use Modbus between devices such as PLC to Scree, or PLC to Drive etc, but not back to a PC).

Any suggestions would be appreciated.

We have a free tool available for Windows that can read holding registers from Modbus/TCP or Modbus RTU devices and log values to a CSV file. You define the registers you would like to access by defining an XML profile file.

The software is called the ICC Modbus Master Tool and is available here:
http://www.iccdesigns.com/software/43-icc-modbus-master-tool.html

The link above also includes documentation on how to use the tool as well as a link to tutorial videos.

Thanks, yes I have tried that and it works fine. It just has a few problems that I would like to overcome.

1) The data is all stored in a column. eg, you do each tag, and when you have 100 tags, every 10s it gets quite big, quite quickly. It would be much nicer if I could put in a <Register> value in the .xml, and then a sequential number of tags that it would read separating them with commas, so it would import as a grid.

2) getting big, I can't write an automatic function that after a certain period of time will close the file, and start writing to a new file.

So I am having to re-invent the wheel, I know.

There are a few free software libraries for Modbus available on the internet.

If you are comfortable working with C#, NModbus is an easy library to use:
https://github.com/NModbus/NModbus

Otherwise for C or C++, there is a C library called libmodbus:
https://libmodbus.org/

For what you are describing, I don't think words like basic, easy and Windows 10 go together. This would be an ideal app for a $35 Raspberry Pi and some of the available Open Source software. Still not basic or particularly easy, but having the source would make it easier to get just what you want. You could probably even do Python which would be easier than C, C++, or C#. I've been putting this off, due to lack of time, waiting for a compelling reason (a paying gig) as any of the options would involve serious study of a library and low level programming time. But I do want the capability. I have a 300gb MySql server (< $100) set up and waiting.