Logging OPC Data and Events
It is a common requirement in automation to log the data from OPC servers into various file formats or databases. QuickOPC will make it easy for you to add OPC logging functionality into your OPC client application. Resilient subscription to data changes in OPC Data Access server, or to event notifications coming from OPC Alarms and Events server can be achieved in just several lines of code. OPC-UA (Unified Architecture) is also supported. You can also trigger the logging by other conditions in the systems. QuickOPC components hide the complexities of OPC client creation and allow you to focus on your main task.
Dedicated solutions that provide OPC logging exist from various vendors. Such packages do a good job for standard usage, but if your needs are quite simple, then the off-the-shelf logging product may come too costly. On the other hand, if your application is more specialized, the dedicate logging product may not be able to provide the necessary level of customization. These are situations where OPC client components such as QuickOPC can help. Using programming language of your choice, you can integrate OPC logging into your application, and possibly also add custom application logic to it.
How can OPC logging be integrated into your application? There are multiple ways of doing it. We have classified them into three main groups:
- Logging to XML file,
- Logging to SQL database, and
One of advantages of using QuickOPC for logging is that the code you write does not have to contain any special logic for handling reconnections. Such logic is handled by QuickOPC, and in case of problems, your code gets a notification about the error. After a configurable period, a connection attempt is automatically made, and the data may start flow again. The savings in amount of code you need to write are tremendous.
Logging to SQL Database
There are various ways how to connect to the SQL server, such as ADO.NET, OLEDB, or ODBC, and you have full flexibility in using them. Similarly, your code can be written C/C++, C#, VB6, VB.NET, or just about anything else. You just need to choose between QuickOPC.NET or QuickOPC-COM, depending on the language and tools you are using.
Our example logs OPC data item changes into a table in Microsoft SQL server using ADO.NET connection. The example is written in C#, but can be easily ported to VB.NET. Each logging entry contains information about which item has changed, its value, timestamp, and quality, associated error message (if any), and more. Same technique can be used to log notifications coming from OPC Alarms and Events servers.
Other approaches exist as well; it is, for example, possible to put the logging code into the SQL Server itself. For details, see OPC with Microsoft SQL Server.
Logging to XML File
In this case, you can take advantage of the fact that QuickOPC.NET objects are natively serializable into XML. When you subscribe to data or alarms, the event arguments object passed to the event handler already contains all information worth logging. You can therefore write the whole object into the log, or just parts of it, possibly together with additional information required by your specific application.
In the first example, we will log OPC Data Access item changes into an XML file. The example is written in C#, but can be easily ported to VB.NET. Each logging entry contains information about which item has changed, its value, timestamp, and quality, associated error message (if any), and more.
Our second example will be similar, except that it will log notifications coming from OPC Alarms and Events server. Each notification is logged with information such as the qualified source name, time of the event, event type, event category, event severity, condition name, message, etc.
Logging to Other Formats and Targets
Using the same or similar techniques as described above, you can log the OPC data into other formats and targets as well - for example, Microsoft Access, mySQL, Oracle, and various file formats such as CSV. We will post examples of such usages as they become available.
Footnote & required disclosure: QuickOPC (including its Options) is a software development kit (SDK) for development of OPC clients. Installing QuickOPC or its Options does not change system settings.