OPC客户程序(C篇——OPC1.0,2.0规范)
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://bluelough.blogbus.com/logs/7354422.html
OPC客户程序(C篇——OPC1.0,2.0规范) - []
本程序为以前个人学习时,在国外网站上下载,本来想自己重新写一篇,因为各方面的原因,没有写,所以
现在把下载的这个程序帖出来供大家学习。此程序个人觉得值得一看,虽然看起来程序有些长。
本程序一共包括三个文件:opc.idl opccomn.idl opctest.cpp
opc.idl opccomn.idl为OPC规范的IDL定义,opctest.cpp为主程序文件。
opctest.cpp文件如下:
// SST Win32 console OPC client Example
// Copyright ?1998-1999 SST, a division of Woodhead Canada Limited
// www.sstech.on.ca
//
// Created by Richard Illes
// May 21, 1998
// Async updates added June 10, 1998
// Simple write added June 24, 1998
// Async reads added July 20, 1998
// Logging added July 27, 1998
// Cache/Device added August 8, 1998
// Version 2.0 support added August 18, 1998
//
// This is a sample console Win32 client that
// does sync/async reads at 100ms intervals
// with up to 10 items
//
// Critical sections are used for async calls to keep track of the
// transaction ID. This slows the response rate down, but ensures all
// calls are completed. An alternative, the client can place transaction ID's
// into a que from OnDataChange() and after a async call is completed. Then a
// watchdog thread after a set timeout period can check both ques to see if the
// transaction completed. Or the client can simply ignore transaction ID's and
// use the client handle returned as validation.
//
// OPC version 2.0 negates the need for critical sections, since the client
// generates the transaction ID BEFORE the read/write is called.
//
// DISCLAIMER:
// This sample code is provided by SST solely to assist in understanding
// the OPC Data Access Specification in relation to a SST OPC server.
// This code is provided as-is and without warranty or support of any sort.
//
// This code may be freely re-used long as credit is openly given
// to SST.