The FactorySoft OPC Server

来源:互联网 发布:ubuntu ikev2 搭建 编辑:程序博客网 时间:2024/06/01 22:29

The FactorySoft OPC Server
       最近在看opc的东西,一开始看的是潘爱民的《COM原理与应用》,这本书买了老早了,几年前领导想在在组态王6.03里面添加我们公司的设备的驱动,到北京组态王的总部去了一趟,没接触过怎么做组态王的驱动,请教了接待我们的MM经理,她说很简单,用到了COM和C++,下午就去了书店买了回来,后来安装上开发包研究了下,书也没看就把驱动写完了,一直放到现在。

       后来做工控的上位,西门子的PLC使用的最多,所以上位软件就选择了wincc。老多项目要与其他厂家的设备通过串口通讯,可是wincc支持的设备驱动比较少,现在wincc6.0里面支持添加mscomm控件读写串口,一直没有机会试一下效果怎么样,当时用的是wincc5.0还是5.1(不知道mscomm控件能不能用),它可以作为OPC server 也可以作为OPC client,就想着做个程序通过串口获得现场数据,作为opc client,将数据传到wincc里面去。用了几次总感觉哪里不对劲,就像做个opc server。这样实现opc server代码的部分不用改动,只要做与现场设备通讯的那部分就可以了,现在想到的比较好的方式就是添加驱动,具体怎么实现现在还没有个思路,这部分先放着等opc server做起来后慢慢的再改动。

《COM原理与应用》看得很粗,看过后就没什么印象了,主要是只看没有实践,自己直接写OPC Server有点难度,有些地方还没弄明白,所以就找了个开发包先熟悉下,最后从网上找到了The FactorySoft OPC Server Development Toolkit,带全部源码的。

以下是引用开发包里面的说明文件


A COM server can be either in-process or out-of-process. An in-process server is a DLL with certain predefined entry points. An out-of-process server is an executable file (.exe). Out-of-process servers are referred to as local when they reside on the same computer as the client, and as remote when they are running on a different computer and communicating over a network. Distributed COM (DCOM) provides for remote servers.

In-process servers are faster than out-of-process servers. COM is involved in creating an object in the first place, but the interface pointer is a real pointer to a class in the same address space. Therefore, after an object is created, calling functions on it is as fast as calling any C++ object’s virtual function. One drawback to using in-process servers in the Automation industry arises when multiple OPC clients want to connect to your server and collect data, for example, through a serial COM port. The problem is that because a COM port cannot be opened more than once, the first in-process server can use the COM port to communicate, but the next time a client connects to the server, the server operates in a different address space and cannot use the COM port. This is a common issue to DLLs. If a server needs to use a non-sharable resource, then an in-process server is most likely ruled out; however, if a server uses a sharable resource, such as a network connection or a plug-in board, then an in-process server has a significant speed advantage. At this time, in-process servers also are not remotable, which means that DCOM cannot give network access to the server. In addition, in-process servers have no user interface; therefore, a separate configuration program is required if server configuration is needed. If a separate configuration program is used, however, the in-process servers cannot see the configuration changes. This is not a trivial problem, but it can be solved.

Out-of-process servers are stand-alone programs that host COM objects. These servers may be existing programs that are making data available to clients, or they may be servers that need exclusive access to a resource, such as a COM port. An out-of-process server has a user interface. The Modbus server’s user interface provides a means for configuring the tags in the server. An out-of-process server is remotable through DCOM, which allows clients on the same computer or across a network, or even the Internet, to access OPC data in the server. A central point of communication can often cache data in a more efficient manner.

The main disadvantage to using an out-of-process server is speed. COM is involved in marshalling data from one process to another in a way that is transparent to the client. There is an additional proxy/stub DLL that handles marshalling of the OPC interfaces which needs to be distributed and registered.

感觉Out-of-process比较适合做设备通讯opc server。就先从最简单的开始做起。

The FactorySoft OPC Server (FSServer) DLL 提供了简单易用的接口隐藏了OPC Server的细节,还是贴原文看着顺眼,简介如下


The FactorySoft OPC Server (FSServer) DLL provides an easy-to-use interface by hiding the details that are common to most OPC servers. The division between application and FSServer DLL is at a high level. Through a very simple interface, an application handles reading and writing data through its protocol, while the FSServer DLL serves data through OPC. The interface allows this DLL to be added to existing applications as well as new ones. FSServer also hides OPC details so that any kind of application can use it, including windows SDK, MFC, console applications, and services.

The FSServer DLL creates a thread that runs its own message loop and registers its COM objects for free-threaded use. It handles all OPC communications. It just relies on the application to provide names and data for tags. It supports all required OPC Custom 2.0 interfaces as well as the optional Browse interface.

The Shell example for 2.0 includes a hierarchy of names for browsing and it matches names to find existing items.

原创粉丝点击