Skip to content
  • There are no suggestions because the search field is empty.

Taking data from a CSV file and exposing that to OPC Clients.

I would like to read data from a CSV file and place it into OPC tags so my OPC Clients can access the data.  I was thinking about using DataHub, is this the right product?  If so, how will this be done?

Yes, DataHub is the correct product for you.  Since DataHub's scripting language can read from files and write to OPC tags this is the perfect product for the job.

We often get asked how you can read data from a CSV file and have it appear as point values in DataHub. Some systems can export data as comma separated value files and it may be desirable to import this data into DataHub so that it can be viewed by other client applications, displayed on the web or logged to a database along with other data from your process.

You can download the example script and a sample CSV files from here.

Here are the comments from the beginning of the DataHub script file that explain how the script works. If you have any questions, please email support@softwaretoolbox.com or give us a call at the phone number listed at the bottom of the page.

/*
* This script reads a CSV file and writes the values found there
* into a set of data points in the DataHub. The format of the
* file is:
*
* row 1: name1, name2, name3, ...
* row 2: value1, value2, value3, ...
* row 3: value1, value2, value3, ...
* ...
* row N: value1, value2, value3, ...
*
* The script will read all rows in the file, but ignore all but
* the first and last. The first row contains the point names and
* the last contains the most recent data.
* If a name is left blank then that column is ignored.
* If a point name does not contain a domain name, then the domain
* set in the "domain" member of the application is used.
*
* e.g.,
* default:point1, default:point2, default:point3
* 1, 2, 3
* 4, 5, 6
*
* will result in:
* default:point1 = 4
* default:point2 = 5
* default:point3 = 6
*
* Strings containing ',' characters must be quoted within double quotes,
* like this:
* "hello, friend"
*
* Double-quotes within strings must be escaped, like this:
* "He said, \"hello\"."
*
* This script will guess whether a value is a number or a string. If the
* value can be parsed to a number, it is treated as a number. Otherwise it
* is a string.
*
* This script looks for new data at a set time interval.
*
* This script will operate in one of two modes:
* In "reload" mode, the file is re-read from the beginning on each
* timer tick.
* In "append" mode, the file is kept open, and the file is read
* from the last read position on each timer tick. This mode will
* not work if the writing application does not open the file
* as "shared".
*
* This script adds a menu item to the OPC DataHub system tray icon that
* allows the user to re-load the file, change read mode, and toggle logging
* to the Script Log window.
*/