当前位置:文档之家› OPC客户端编程汇编

OPC客户端编程汇编

OPC客户端编程汇编
OPC客户端编程汇编

OPC编程汇编

OPC客户端的自动化实现

OPC是建立在COM,DCOM的基础商的,因此绝大多数语言都可以很好的进行开发。在Net中开发客户端有以下几种方式:

(1)使用OPCNetAPI,需要用到OPCNetAPI.dll,https://www.doczj.com/doc/1542190.html,.dll

(2)使用自动化接口,需要用到OPCDAAuto.dll

(3)使用自定义接口,需要用到多个Wrapper:OpcRcw.Ae.dll,OpcRcw.Batch.dll,https://www.doczj.com/doc/1542190.html,n.dll,OpcRcw.Da.dll,OpcRcw.Dx.dll,OpcRcw.Hda.dll,OpcRcw.Sec.dll

以上开发方式所需的动态链接库可以从OPC基金会(https://www.doczj.com/doc/1542190.html,/)的网站上下载,一些下载项目可能需要注册,或成为基金会的成员。

不同的方式有各自的有缺点,请参见…

本文使用自动化接口,https://www.doczj.com/doc/1542190.html,语言进行开发,开发项目是无线射频(RFID)卡方面的应用,典型的如公交车,或公司考勤使用的刷卡机。需要注意的是自动化接口存在一个“不是问题”的问题,数组下标是以1开始的,而不是传统计算机开发上的以0开始。不知道设计者头脑是怎么想(有人知道吗?);这可能会给一些语言的开发造成问题(有人碰到吗,没有你就是幸运的)

需求:OPCDAAuto.dll或该Dll的Interop

(一):客户端开发流程

OPC客户端的开发主要遵循下图所示的开发流程,下面就从以下几个开发步骤进行说明

(二):枚举OPC服务器列表

枚举服务器主要是通过OPCServer接口的GetOPCServers方法来实现的,该方法会返回OPC服务器数组(以1为下界,上面已有说明),以下是代码段

'枚举OPC服务器列表

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try

GlobalOPCServer = New OPCAutomation.OPCServerClass()

Dim ServerList As Object = GlobalOPCServer.GetOPCServers

For index As Short = LBound(ServerList) To UBound(ServerList) '加入控件列表中,注意这里使用LBound和UBound cbbServerList.Items.Add(ServerList(index))

Next

If cbbServerList.Items.Count > 0 Then

cbbServerList.SelectedIndex = 0

End If

ResetControlStatus() '设置控件状态

GlobalOPCServer = Nothing

Catch Ex As Exception

MessageBox.Show("List OPC servers failed: " + Ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End Sub

(三):连接OPC服务器

自动化接口中连接到服务器是使用connect方法

Public Overridable Sub Connect(ByVal ProgID As String, Optional ByVal Node As Object = Nothing)

ProgID指服务器的ProgID,Node代表网络节点,如果是本机则放空即可。

连接到服务器后,以下属性需要特别注意:

OPCServer.StartTime:服务器的启动时间

OPCServer.CurrentTime:服务器的当前时间,各个客户端可以通过这个属性值完成一些同步的操作

OPCGroups.DefaultGroupIsActive:以后添加的Group是否默认激活

OPCGroups.DefaultGroupDeadBand:Group的默认死区,变化量超过死区后将会触发DataChange事件,

合理的设置该值可以提高程序性能

OPCGroups.Count:下属组(Group)的数量

OPCGroups.DefaultGroupLocalID:组(Group)的默认通信区域编号,如1024

OPCGroups.DefaultGroupUpdateRate:组(Group)的默认刷新率,该属性也比较重要

OPCGroups.DefaultGroupTimeBias:组(Group)的默认时间偏差

(四):添加组(Group)和项(Item)

添加组和项需要用到Groups.Add和Items.AddItem方法,以下是原型:

Function Add(Optional ByVal Name As Object = Nothing) As OPCAutomation.OPCGroup

Function AddItem(ByVal ItemID As String, ByVal ClientHandle As Integer) As OPCAutomation.OPCItem

组也有两个重要的属性

Group.UpdateRate:刷新率,该属性通Groups的UpdateRate意义一样,如果这个值有设置,则以这个值为准

Group. IsSubscribed:是否使用订阅功能

以下是代码段

'连接到指定的OPC服务器

Private Sub btnConnectServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnectSer ver.Click

If cbbServerList.Text <> ""Then

ConnectedOPCServer = New OPCAutomation.OPCServerClass()

Try

ConnectedOPCServer.Connect(cbbServerList.Text)

'设置组集合的默认属性

ConnectedOPCServer.OPCGroups.DefaultGroupIsActive = True

ConnectedOPCServer.OPCGroups.DefaultGroupDeadband = 0

'添加组

ConnectedGroup = ConnectedOPCServer.OPCGroups.Add()

ConnectedGroup.UpdateRate = 3 * 1000 '刷新虑,用于下面的DataChange事件

ConnectedGroup.IsSubscribed = True'使用订阅功能

'添加项

GlobalOPCItems(0) = ConnectedGroup.OPCItems.AddItem("Reader_Device.OpenCard", 0)

GlobalOPCItems(1) = ConnectedGroup.OPCItems.AddItem("Reader_Device.CloseCard", 1)

GlobalOPCItems(2) = ConnectedGroup.OPCItems.AddItem("Reader_Device.CardNO", 2)

RefreshServerStatus() '刷新服务器状态

Catch ex As Exception

ConnectedOPCServer = Nothing

MessageBox.Show("OPC server connect failed : " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

ResetControlStatus()

End If

End Sub

(五):读写操作与事件控制

读写操作包括同步和异步两种操作方式,以下是这几个方法的原型:

Group的同步读事件

Sub SyncRead(ByVal Source As Short, ByVal NumItems As Integer, ByRef ServerHandles As System.Array, ByRef Values As System.Array, ByRef Errors As System.Array, Optional ByRef Qualities As Object = Nothing, Optional

ByRef TimeStamps As Object = Nothing)

Group的同步写事件

Sub SyncWrite(ByVal NumItems As Integer, ByRef ServerHandles As System.Array, ByRef Values As System.Array, ByRef Er rors As System.Array)

Group的异步读事件

Sub AsyncRead(ByVal NumItems As Integer, ByRef ServerHandles As System.Array, ByRef Errors As System.Array, ByVal Tr ansactionID As Integer, ByRef CancelID As Integer)

Group的异步写事件

Sub AsyncWrite(ByVal NumItems As Integer, ByRef ServerHandles As System.Array, ByRef Values As System.Array, ByRef Errors As System.Array, ByVal TransactionID As Integer, ByRef CancelID As Integer)

如果使用异步的读写操作,那么还需要实现Group中的ReadComplete和WriteComplete两个事件

Public

Event AsyncReadComplete(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.Ar ray, ByRef ItemValues As System.Array, ByRef Qualities As System.Array, ByRef TimeStamps As System.Array, ByRef Errors As System.Array)

Public

Event AsyncWriteComplete(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.A rray, ByRef Errors As System.Array)

其他相关的重要事件包括:

Group数据变化时的通知事件

Public

Event DataChange(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.Array, ByR ef ItemValues As System.Array, ByRef Qualities As System.Array, ByRef TimeStamps As System.Array)

Group的异步取消事件

Public Event AsyncCancelComplete(ByVal CancelID As Integer)

Server(服务器)关闭通知事件

Public Event ServerShutDown(ByVal Reason As String)

以下是这些实现的代码段

'读取卡片指定的块号的值

Private Sub btnReadCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

If Not (ConnectedGroup Is Nothing) Then

Try

'获取块号

Dim BlockNo As Short = CByte(ReadBlockNo.Text)

'如果要获取数据的块所对应的项还没有创建,就创建它

If GlobalOPCBlockItems(BlockNo) Is Nothing Then

GlobalOPCBlockItems(BlockNo) = ConnectedGroup.OPCItems.AddItem("Reader_Device.Block" & CStr(BlockNo), 200 + BlockNo)

End If

'准备参数数组

Dim ServerResults As System.Array

Dim ServerErrors As System.Array

Dim ServerHandles(1) As Integer

ServerHandles(1) = GlobalOPCBlockItems(BlockNo).ServerHandle

'读取值

ConnectedGroup.SyncRead(OPCAutomation.OPCDataSource.OPCDevice, 1, ServerHandles, ServerResults, ServerErrors)

If ServerErrors(1) <> 0 Then

MsgBox("Read Card Failed:" & ServerErrors(1))

Else

txtReadBlockNo.Text = ServerResults(1)

End If

Catch ex As Exception

MessageBox.Show("OPC server Read Card failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End If

End Sub

'写卡片指定块的值

Private Sub btnWriteCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

If Not (ConnectedGroup Is Nothing) Then

Try

'获取块号

Dim BlockNo As Short = CByte(WriteBlockNo.Text)

'如果要写入数据的块所对应的项还没有创建,就创建它

If GlobalOPCBlockItems(BlockNo) Is Nothing Then

GlobalOPCBlockItems(BlockNo) = ConnectedGroup.OPCItems.AddItem("Reader_Device.Block" & CStr(BlockNo), 200 + BlockNo)

End If

'准备参数数组

Dim ServerValues(1) As Object

Dim ServerErrors As Array

Dim ServerHandles(1) As Integer

ServerHandles(1) = GlobalOPCBlockItems(BlockNo).ServerHandle

ServerValues(1) = txtWriteBlockNo.Text

'写入值

ConnectedGroup.SyncWrite(1, ServerHandles, ServerValues, ServerErrors)

If ServerErrors(1) <> 0 Then

MsgBox("Write Card Failed:" & ServerErrors(1))

Else

MsgBox("Write Card Succeed")

End If

Catch ex As Exception

MessageBox.Show("OPC server Write Card failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End If

End Sub

(六):断开服务器

断开服务器只要使用OPCServer的Disconnect方法几个,以下是代码段:

'断开到指定OPC服务器的连接

Private Sub btnDisconnectServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconn ectServer.Click

If Not (ConnectedOPCServer Is Nothing) Then

Try

ConnectedOPCServer.Disconnect()

Catch ex As Exception

MessageBox.Show("OPC server disconnect failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) Finally

ConnectedOPCServer = Nothing

ResetControlStatus()

End Try

End If

End Sub

(七):相关链接

非常好的一个OPC技术网站https://www.doczj.com/doc/1542190.html,/

OPC基金会网址https://www.doczj.com/doc/1542190.html,/

国内的一个比较好的OPC网站https://www.doczj.com/doc/1542190.html,/Index.html

(八):全部源码

Imports System.Runtime.InteropServices

Public Class Form1

Dim GlobalOPCServer As OPCAutomation.OPCServerClass

Dim WithEvents ConnectedOPCServer As OPCAutomation.OPCServerClass

Dim WithEvents ConnectedGroup As OPCAutomation.OPCGroupClass

Dim GlobalOPCItems(4) As OPCAutomation.OPCItem

Dim GlobalOPCBlockItems(64) As OPCAutomation.OPCItem

'枚举OPC服务器列表

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try

GlobalOPCServer = New OPCAutomation.OPCServerClass()

Dim ServerList As Object = GlobalOPCServer.GetOPCServers

For index As Short = LBound(ServerList) To UBound(ServerList) '加入控件列表中,注意这里使用LBound和UBound

cbbServerList.Items.Add(ServerList(index))

Next

If cbbServerList.Items.Count > 0 Then

cbbServerList.SelectedIndex = 0

End If

ResetControlStatus() '设置控件状态

GlobalOPCServer = Nothing

Catch Ex As Exception

MessageBox.Show("List OPC servers failed: " + Ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End Sub

'连接到指定的OPC服务器

Private Sub btnConnectServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConne ctServer.Click

If cbbServerList.Text <> "" Then

ConnectedOPCServer = New OPCAutomation.OPCServerClass()

Try

ConnectedOPCServer.Connect(cbbServerList.Text)

'设置组集合的默认属性

ConnectedOPCServer.OPCGroups.DefaultGroupIsActive = True

ConnectedOPCServer.OPCGroups.DefaultGroupDeadband = 0

'添加组

ConnectedGroup = ConnectedOPCServer.OPCGroups.Add()

ConnectedGroup.UpdateRate = 3 * 1000 '刷新虑,用于下面的DataChange事件

ConnectedGroup.IsSubscribed = True'使用订阅功能

'添加项

GlobalOPCItems(0) = ConnectedGroup.OPCItems.AddItem("Reader_Device.OpenCard", 0)

GlobalOPCItems(1) = ConnectedGroup.OPCItems.AddItem("Reader_Device.CloseCard", 1)

GlobalOPCItems(2) = ConnectedGroup.OPCItems.AddItem("Reader_Device.CardNO", 2)

RefreshServerStatus() '刷新服务器状态

Catch ex As Exception

ConnectedOPCServer = Nothing

MessageBox.Show("OPC server connect failed : " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

ResetControlStatus()

End If

End Sub

'服务器断开事件通知

Private Sub OnServerShutDown(ByVal Reason As String) Handles ConnectedOPCServer.ServerShutDown

btnDisconnectServer_Click(Nothing, New EventArgs())

End Sub

Private Sub OnGroupDataChange(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.Array, ByRef ItemValues As System.Array, ByRef Qualities As System.Array, ByRef TimeStamps As System.Arr

ay) Handles ConnectedGroup.DataChange

For i As Integer = 1 To NumItems

If Qualities(i) = OPCAutomation.OPCQuality.OPCQualityGood Then

Select Case ClientHandles(i)

Case 2

txtCardNo.Text = CStr(ItemValues(i))

Case 200 '测试7张卡片

txtValueBlock0.Text = CStr(ItemValues(i))

Case 201

txtValueBlock1.Text = CStr(ItemValues(i))

Case 202

txtValueBlock2.Text = CStr(ItemValues(i))

Case 203

txtValueBlock3.Text = CStr(ItemValues(i))

Case 204

txtValueBlock4.Text = CStr(ItemValues(i))

Case 205

txtValueBlock5.Text = CStr(ItemValues(i))

Case 206

txtValueBlock6.Text = CStr(ItemValues(i))

Case 207

txtValueBlock7.Text = CStr(ItemValues(i))

Case Else

End Select

End If

Next

End Sub

'断开到指定OPC服务器的连接

Private Sub btnDisconnectServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDis connectServer.Click

If Not (ConnectedOPCServer Is Nothing) Then

Try

ConnectedOPCServer.Disconnect()

Catch ex As Exception

MessageBox.Show("OPC server disconnect failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) Finally

ConnectedOPCServer = Nothing

ResetControlStatus()

End Try

End If

End Sub

'开卡,并返回卡号

Private Sub btnOpenCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

If ConnectedGroup IsNot Nothing Then

Try

'准备参数数组

Dim ServerHandles(1) As Integer

Dim ServerValues(1) As Object

Dim ServerErrors As System.Array

ServerHandles(1) = GlobalOPCItems(0).ServerHandle

ServerValues(1) = 1

'写入值,用于执行OpenCard的操作

ConnectedGroup.SyncWrite(1, ServerHandles, ServerValues, ServerErrors)

If ServerErrors(1) <> 0 Then

MsgBox("OpenCardError: " & ServerErrors(1))

End If

ServerHandles(1) = GlobalOPCItems(2).ServerHandle

Dim ServerResult As System.Array

'读取卡号

ConnectedGroup.SyncRead(OPCAutomation.OPCDataSource.OPCDevice, 1, ServerHandles, ServerResult, Server Errors)

If ServerErrors(1) <> 0 Then

MsgBox("ReadCardNoError: " & ServerErrors(1))

Else

txtCardNo.Text = ServerResult(1)

End If

Catch ex As Exception

MessageBox.Show("OPC server Open Card failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

ResetControlStatus()

End If

End Sub

'读取卡片指定的块号的值

Private Sub btnReadCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

If Not (ConnectedGroup Is Nothing) Then

Try

'获取块号

Dim BlockNo As Short = CByte(ReadBlockNo.Text)

'如果要获取数据的块所对应的项还没有创建,就创建它

If GlobalOPCBlockItems(BlockNo) Is Nothing Then

GlobalOPCBlockItems(BlockNo) = ConnectedGroup.OPCItems.AddItem("Reader_Device.Block" & CStr(Block No), 200 + BlockNo)

End If

'准备参数数组

Dim ServerResults As System.Array

Dim ServerErrors As System.Array

Dim ServerHandles(1) As Integer

ServerHandles(1) = GlobalOPCBlockItems(BlockNo).ServerHandle

'读取值

ConnectedGroup.SyncRead(OPCAutomation.OPCDataSource.OPCDevice, 1, ServerHandles, ServerResults, Serve rErrors)

If ServerErrors(1) <> 0 Then

MsgBox("Read Card Failed:" & ServerErrors(1))

Else

txtReadBlockNo.Text = ServerResults(1)

End If

Catch ex As Exception

MessageBox.Show("OPC server Read Card failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End If

End Sub

'写卡片指定块的值

Private Sub btnWriteCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

If Not (ConnectedGroup Is Nothing) Then

Try

'获取块号

Dim BlockNo As Short = CByte(WriteBlockNo.Text)

'如果要写入数据的块所对应的项还没有创建,就创建它

If GlobalOPCBlockItems(BlockNo) Is Nothing Then

GlobalOPCBlockItems(BlockNo) = ConnectedGroup.OPCItems.AddItem("Reader_Device.Block" & CStr(Block No), 200 + BlockNo)

End If

'准备参数数组

Dim ServerValues(1) As Object

Dim ServerErrors As Array

Dim ServerHandles(1) As Integer

ServerHandles(1) = GlobalOPCBlockItems(BlockNo).ServerHandle

ServerValues(1) = txtWriteBlockNo.Text

'写入值

ConnectedGroup.SyncWrite(1, ServerHandles, ServerValues, ServerErrors)

If ServerErrors(1) <> 0 Then

MsgBox("Write Card Failed:" & ServerErrors(1))

Else

MsgBox("Write Card Succeed")

End If

Catch ex As Exception

MessageBox.Show("OPC server Write Card failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End If

End Sub

'重设控件状态

Private Sub ResetControlStatus()

If ConnectedOPCServer Is Nothing Then

btnConnectServer.Enabled = True

btnDisconnectServer.Enabled = False

btnReadCard.Enabled = False

btnWriteCard.Enabled = False

btnOpenCard.Enabled = False

btnCloseCard.Enabled = False

ReadBlockNo.Value = 0

WriteBlockNo.Value = 0

txtReadBlockNo.Text = ""

txtWriteBlockNo.Text = "00000000000000000000000000000000"

txtCardNo.Text = ""

txtSrvStartTime.Text = ""

txtSrvCurrTime.Text = ""

txtSrvGroupCount.Text = ""

txtSrvGroupDeadBand.Text = ""

txtSrvGroupDefActive.Text = ""

txtSrvGroupLocalID.Text = ""

txtSrvGroupTimeBias.Text = ""

txtSrvRequestRate.Text = ""

btnConnectServer.Enabled = False

btnDisconnectServer.Enabled = True

If txtCardNo.Text = "" Then

btnReadCard.Enabled = False

btnWriteCard.Enabled = False

btnOpenCard.Enabled = True

btnCloseCard.Enabled = False

Else

btnReadCard.Enabled = True

btnWriteCard.Enabled = True

btnOpenCard.Enabled = True

btnCloseCard.Enabled = True

End If

End If

End Sub

'刷新服务器状态属性信息

Private Sub RefreshServerStatus()

If ConnectedOPCServer IsNot Nothing Then

txtSrvStartTime.Text = ConnectedOPCServer.StartTime.ToString()

txtSrvCurrTime.Text = ConnectedOPCServer.CurrentTime.ToString()

With ConnectedOPCServer.OPCGroups

txtSrvGroupCount.Text = CStr(.Count)

txtSrvGroupDeadBand.Text = CStr(.DefaultGroupDeadband)

If .DefaultGroupIsActive Then

txtSrvGroupDefActive.Text = "True"

Else

txtSrvGroupDefActive.Text = "False"

End If

txtSrvGroupLocalID.Text = CStr(.DefaultGroupLocaleID)

txtSrvGroupTimeBias.Text = CStr(.DefaultGroupTimeBias)

txtSrvRequestRate.Text = CStr(.DefaultGroupUpdateRate)

End With

End If

End Sub

'关闭卡片

Private Sub btnCloseCard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

If ConnectedGroup IsNot Nothing Then

Try

Dim ServerHandles(1) As Integer

Dim ServerValues(1) As Object

Dim ServerErrors As System.Array

ServerHandles(1) = GlobalOPCItems(1).ServerHandle

ServerValues(1) = 1

ConnectedGroup.SyncWrite(1, ServerHandles, ServerValues, ServerErrors)

If ServerErrors(1) <> 0 Then

MsgBox("Close Card Error: " & ServerErrors(1))

End If

Catch ex As Exception

MessageBox.Show("OPC server Close Card failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End If

End Class

Prerequisites: ComboBox control named cbbServerList, Button1 and Button2 on Form1.

Code Block

Public Class Form1

Dim GlobalOPCServer As OPCAutomation.OPCServerClass

Dim WithEvents ConnectedOPCServer As OPCAutomation.OPCServerClass

Dim WithEvents ConnectedGroup As OPCAutomation.OPCGroupClass

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles MyBase.Load Try

GlobalOPCServer = New OPCAutomation.OPCServerClass()

Dim ServerList As Object = GlobalOPCServer.GetOPCServers

For index As Short = LBound(ServerList) To UBound(ServerList)

cbbServerList.Items.Add(ServerList(index))

Next

If cbbServerList.Items.Count > 0 Then

cbbServerList.SelectedIndex = 0

End If

GlobalOPCServer = Nothing

Catch Ex As Exception

MessageBox.Show("List OPC servers failed: " + Ex.Message, "OPCSample", MessageBoxButtons.OK)

End Try

End Sub

' Connect to OPC server

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Cl ick

If cbbServerList.Text <> ""Then

ConnectedOPCServer = New OPCAutomation.OPCServerClass()

Try

ConnectedOPCServer.Connect(cbbServerList.Text)

'Set property for Group connection

ConnectedOPCServer.OPCGroups.DefaultGroupIsActive = True

ConnectedOPCServer.OPCGroups.DefaultGroupDeadband = 0

'Add group

ConnectedGroup = ConnectedOPCServer.OPCGroups.Add()

ConnectedGroup.UpdateRate = 3 * 1000

ConnectedGroup.IsSubscribed = True

'Add items

GlobalOPCItems(0) = ConnectedGroup.OPCItems.AddItem("Reader_Device.OpenCard", 0)

GlobalOPCItems(1) = ConnectedGroup.OPCItems.AddItem("Reader_Device.CloseCard", 1)

GlobalOPCItems(2) = ConnectedGroup.OPCItems.AddItem("Reader_Device.CardNO", 2)

Catch ex As Exception

ConnectedOPCServer = Nothing

MessageBox.Show("OPC server connect failed : " + ex.Message, "OPCSample", MessageBoxButtons.OK) End Try

End If

End Sub

' Disconnect to OPC server

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button2.Cl ick

If Not (ConnectedOPCServer Is Nothing) Then

Try

ConnectedOPCServer.Disconnect()

Catch ex As Exception

MessageBox.Show("OPC server disconnect failed: " + ex.Message, "OPCSample", MessageBoxButtons.OK) Finally

ConnectedOPCServer = Nothing

End Try

End If End Sub End Class

The OPC server and the client application communicate each other through the interface of COM. The root class is OPC server object, and it accesses the group object and the item object by using this class.The device datas of PLC (ex. 'X0' and 'D0' etc.) are constructed at the low hierarchy, and you can access the device datas as the unit of item or collection.

When the OPC server is set up, DLL necessary for OPC is automatically registered. For access to OPC Server from Visual Basic, it needs to check "OPC Automation 2.0".

For hooking events of OPC Server, add to "WithEvents" in dimension statement or event handler named "OBJECTNAME_EVENTNAME".

Dim WithEvents Myserver As OPCServer

Dim WithEvents Mygroup As OPCGroup

Dim WithEvents Mygroups As OPCGroups

Dim Myitem As OPCItem

Dim Myitems As OPCItems

Dim MyBrowser As OPCBrowser

It is able to get installed OPC Server name by using OPC Server object. In this sample, it shows OPC Server name in list box and operator can select the target server.

Dim Getserver As OPCServer

Dim Servers As Variant

Set Getserver = New OPCServer

Servers = Getserver.GetOPCServers

For i = LBound(Servers) To UBound(Servers)

List1.AddItem Servers(i)

Next i

Set Getserver=Nothing

It is able to get device name registered in OPC Server by using OPC Server object. You can make the Group under device and OPC Server object is enabled to access this lower layer.

Set Myserver = New OPCServer

Myserver.Connect ServerName.Text, NodeName.Text

Set MyBrowser = Myserver.CreateBrowser

MyBrowser.ShowBranches

Dim bname As Variant

For Each bname In MyBrowser

ItemList.AddItem "+" & bname

Next name

For accessing client application to physical device data, it needs to generate OPC Group object in OPC group collection. The OPC Group object can configure update interval of tags. Normally, the device of accessing same cycle will register in same group. Also, you should be carefully CPU performance to create over groups because OPC Server create a thread for each group.

Dim ClientHandles(16) As Long

Dim OPCItemIDs(16) As String

Set Mygroups = Myserver.OPCGroups

Set Mygroup = Mygroups.Add("Group1")

Mygroup.UpdateRate = "1000"

Mygroup.IsActive = False

For i = 1 To 16

ClientHandles(i) = i

OPCItemIDs(i) = "Device1" + ".D" + Format(i)

Next i

Set Myitems = Mygroup.OPCItems

Myitems.AddItems 16, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors

Mygroup.IsActive = True

Implements event handler of OPC Group object for advice mode. The OPC Server read data for each cycle and if changing the value, callback to client application. The quality flag is normally '0xC0', when occurred error, it will be turn to other value. Mygroup.IsSubscribed = True

Public Sub Mygroup_DataChange(ByVal TID As Long, _

ByVal NumItems As Long, Chd() As Long, ItemValues() As Variant, _

Qualities() As Long, TimeStamps() As Date)

For i = 1 To NumItems

Debug.print ItemValues(i) + ":" + TimeStamps(i) + _":" + Qualities(i)

Next i

End Sub

The OPC has two ways of data access, Synchronize and Asynchronous. In Synchronize, the client application must be wait for completing server work. But the client application can confirm server transaction is normally completed because the OPC Server returns the result on completing the communication work. This is a normally style of procedure.

In Asynchronous mode, the OPC Server turns the handle to client as soon as receiving the request and proceed the transaction on background. After completing this work, calls handler of client application. Asynchronous mode cut down wait time for communication and be able to run client application.

Caution: Asynchronous access is enabled under advice mode.

'Sync Read

Mygroup.SyncRead OPCDevice, 16, ItemServerHandles, ItemValues, ItemServerErrors, ItemQualities, ItemTimeStamps

For i = 1 To 16

Debug.print ItemValues(i) + ":" + ItemTimeStamps(i) + ":" + ItemQuality(i)

Next i

'Sync Write

For i = 1 To 16

ItemVal(i) = i

Next i

Mygroup.SyncWrite 16, ItemServerHandles, ItemVal, ItemServerErrors

For i = 1 To 16

If ItemServerErrors(i) <> 0 Then

MsgBox "Write ERROR " + Format(i)

End If

Next i

'Async Read(TransactionID=10, CancelID=11)

Mygroup.AsyncRead 16, ItemServerHandles, ItemServerErrors, 10, 11

Private Sub Mygroup_AsyncReadComplete(ByVal TransactionID As Long, ByVal NumItems As Long, _

ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, _

TimeStamps() As Date, Errors() As Long)

Debug.print "AsyncRead Comp" + Chr$(9) + Time$ + Chr$(13) + Chr$(10)

End Sub

'Async Write

Dim ItemVal(ItemCount) As Variant

For i = 1 To ItemCount

ItemVal(i) = i

Next i

Mygroup.AsyncWrite 16, ItemServerHandles, ItemVal, ItemServerErrors, 100, 101

Private Sub Mygroup_AsyncWriteComplete(ByVal TransactionID As Long, _

ByVal NumItems As Long, ClientHandles() As Long, Errors() As Long)

Debug.print "AsyncWrite Comp" + Chr$(9) + Time$ + Chr$(13) + Chr$(10)

End Sub

In cache read operation, OPC Server doesn't access the physical device and return the last data on memory. The OPC Server read and caches the value every each time.It will be able to access on high speed if not need newest value.

Mygroup.SyncRead OPCCache, 16, ItemServerHandles, ItemValues, ItemServerErrors, ItemQualities, ItemTimeStamps

For i = 1 To 16

Debug.print ItemValues(i) + ":" + ItemTimeStamps(i) + ":" + ItemQuality(i)

Next i

I am trying to develop an opc - da client using .net technology.

Have gone through the documents on opc and opc client and all,

but am still not sure how to implement it, can someone give me a direction on how to start with it?

59 Answers Found

Answer 1

can you please provide some additional details on exactly what you're trying to do and any other relevant info that I can pass on to our support engineer?

thanks,

-brenda (ISV Buddy Team)

Answer 2

Hey Ksona,

I was just speaking to a college of mine about DA cleints this morning. Have your checked out the opc Exchange at

https://www.doczj.com/doc/1542190.html,/ ?

I know that Eric Murphy is an OPC genius, and he can probably give you a hand, or point you in a great direction.

You can also email me and I can see if one of my college's has some time to help you out? I'm curious as to what devices you are trying to access?

Answer 3

Genius? That's a wee bit over the top, let's just say I've experienced a thing or two about OPC. However, if you're fishing for a response, flattery will get you everywhere :)

As the other replies pointed out, the question is a bit open ended. 'using .NET technology' offers a few possibilites, depending on your develpoment language C#, https://www.doczj.com/doc/1542190.html,, managed C++, etc.

The easiest way, would be to make use of the OPC client .NET wrapper supplied by the OPC Foundation. You do have to be a member to access this, however that offers other advantages such as invitations to the OPC Interoperabilty events to test your client against other vendors.

If that's not an option, I have seen https://www.doczj.com/doc/1542190.html, applications that make use of the OPC Automation dll. This was originally intended for VB apps, but some vendors have upgraded the automation interface to work with https://www.doczj.com/doc/1542190.html, You would have to ask specifically because not all versions do.

Otherwise, you are looking at writing an application that interfaces to unmanaged COM interfaces. From an programatic point of view, an OPC client would be no different from any other COM client. If you're new to OPC, this is not a trivial task...

Answer 4

Hey Ksona,

I agree with what Eric Murphy said, that your best bet is to get the libraries off of the opc Foundation's site. But you might want to try Visicom's excellent .NET interface library here:

https://www.doczj.com/doc/1542190.html,/dotnet/opcdotnet.asp

Again, do not assume that this is of any commercial quality & stability, you're best option is to get the OPC Foundation's.

Hope this helps!

Steve

Answer 5

Hi Eric,

Sounds like you know what you're talking about ... Can I also butter you up and find out if you know anything about using

an opc interface in https://www.doczj.com/doc/1542190.html, that was designed for VB6. The problem is the RSiOPCAuto.dll that Rockwell use to interface to their OPC server (RSlinx). It only accepts Arrays with lower bounds of 1 which is not possible in https://www.doczj.com/doc/1542190.html,. (see refs below)

1) https://www.doczj.com/doc/1542190.html,/1026218609/index_html

2) https://www.doczj.com/doc/1542190.html,/1026222355/index_html

I only dimly understand the article on https://www.doczj.com/doc/1542190.html,/dotnet/opcdotnet.asp. It seems to be saying that if I was using VC++ I could write some kind of code which would make be able to use the OPC interface which was COM and written for VB6. If I was using C++ I'd be laughing.

I'm not. :-)... and while the C++ is interesting and gives me hope, I'm working with https://www.doczj.com/doc/1542190.html, and I'm still trying to figure out how I can use the OPC interface designed for VB6 with https://www.doczj.com/doc/1542190.html,. Why do I even need RSiOPCAuto.dll? If OPC is a standard, can I not just use any OPC interface and hope that RSLinx (the Rockwell OPC server) answers with the right data? Is there not a "General" OPC interface dll?

Puzzled from Leicester

Andrew Smith

andrew.w.smith|at|https://www.doczj.com/doc/1542190.html,

Answer 6

You can use https://www.doczj.com/doc/1542190.html, or c# with rslinx's COM dll.

You just add the reference to RsiOPCAuto.dll to your project and use its classes.

To pass an array to a OPC method, just dim the array to n+1 and fill it starting at index 1.

The method will return object arrays that you will read starting at index 1.

You have to cast to the specific types to get the values.

Excuse me for my bad grammar.

I hope this helps.

Answer 7

I was looking for some help developing a C# OPC client using the OPCAutomation wrapper when I stumbled upon your conversation. Here is a link to a https://www.doczj.com/doc/1542190.html, sample OPC client that helped shed some light on using .Net

to develop OPC clients using the wrapper.

https://www.doczj.com/doc/1542190.html,/Temp/Simple_VB_dot_Net_OPC.zip

Answer 8

Thanks Everyone,

Right now, i am using Advasol https://www.doczj.com/doc/1542190.html,/ opc client components for my opc client development. It looks ok till now :)

Answer 9

Andrew, Perrakus is correct in his discription on using the Automation dll with https://www.doczj.com/doc/1542190.html,. Once you add the reference, you can access all the classes just like in VB6. Since https://www.doczj.com/doc/1542190.html, doesn't seem to support the 'Option Base 1' you will have to handle the offset yourself. A little bit of background on the Automation wrappers. There actually is a "General" opc interface dll. It's called the Automation Wrapper, or OPCDAAuto.dll. When the first OPC DA specifications were released, the OPC Foundation did not wish to support complied applications, so the source code for the OPCDAAuto.dll was supplied to all OPC members. Each vendor then recompiled the code under their own

GUID (Rockwell renamed it RSiOPCAuto.dll). In November of 2005, the OPC Foundation decided to take the responsibility of maintaining various applications (DA Wrapper, Compliance tests, proxy stubs etc). All the bug fixes various vendors had applied over the years was compiled and the OPC Foundation released the 'official' OPCDAAuto.dll v2.02. Many vendors already were supporting 'their' wrapper so continue to ship the vendor branded

version. Version 2.02 of the automation wrapper has been tested with https://www.doczj.com/doc/1542190.html, on Win2000 and WinXP. You can read the details on the Foundation website at

https://www.doczj.com/doc/1542190.html,/DownloadFile.aspx/Data%20Access/OPC%20DA%20Auto%202.02%20 Source%20Code%205.30.htm?RI=306 If you are an OPC Foundation member you can download the files directly. If you are an end user, you need to get the binaries from your OPC Vendor (I assume it's Rockwell in your case) Cheers and Good Luck. Eric

Answer 10

When i try add an Opc group, i get te following error message:

Opc Server add group failed with exception: Unable to cast object of type 'OpcAutomation.OpcServerClass' to type

'OPCAutomation.IOpcGroups'

Does anyone help me?

OPC客户端编程汇编

OPC编程汇编 OPC客户端的自动化实现 OPC是建立在COM,DCOM的基础商的,因此绝大多数语言都可以很好的进行开发。在Net中开发客户端有以下几种方式: (1)使用OPCNetAPI,需要用到OPCNetAPI.dll,https://www.doczj.com/doc/1542190.html,.dll (2)使用自动化接口,需要用到OPCDAAuto.dll (3)使用自定义接口,需要用到多个Wrapper:OpcRcw.Ae.dll,OpcRcw.Batch.dll,https://www.doczj.com/doc/1542190.html,n.dll,OpcRcw.Da.dll,OpcRcw.Dx.dll,OpcRcw.Hda.dll,OpcRcw.Sec.dll 以上开发方式所需的动态链接库可以从OPC基金会(https://www.doczj.com/doc/1542190.html,/)的网站上下载,一些下载项目可能需要注册,或成为基金会的成员。 不同的方式有各自的有缺点,请参见… 本文使用自动化接口,https://www.doczj.com/doc/1542190.html,语言进行开发,开发项目是无线射频(RFID)卡方面的应用,典型的如公交车,或公司考勤使用的刷卡机。需要注意的是自动化接口存在一个“不是问题”的问题,数组下标是以1开始的,而不是传统计算机开发上的以0开始。不知道设计者头脑是怎么想(有人知道吗?);这可能会给一些语言的开发造成问题(有人碰到吗,没有你就是幸运的) 需求:OPCDAAuto.dll或该Dll的Interop (一):客户端开发流程 OPC客户端的开发主要遵循下图所示的开发流程,下面就从以下几个开发步骤进行说明 (二):枚举OPC服务器列表 枚举服务器主要是通过OPCServer接口的GetOPCServers方法来实现的,该方法会返回OPC服务器数组(以1为下界,上面已有说明),以下是代码段 '枚举OPC服务器列表

c#opc客户端开发

using System; using System.Collections.Generic; using https://www.doczj.com/doc/1542190.html,ponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using OPCAutomation; using https://www.doczj.com/doc/1542190.html,; namespace Opc_Client { public partial class Form1 : Form { public Form1() { InitializeComponent(); } #region私?有?D变à?量¢? OPCServer SyServer; OPCGroups SyGroups; OPCGroup SyGroup; OPCItems SyItems; OPCItem SyItem; string strHostIP = string.Empty;

string strHostName = string.Empty; bool opc_connected = false; //连¢?接¨?状á??态?? int itmHandleClient = 0; //客¨a户?ì端?句?柄à¨2 int itmHandleServer = 0; //服¤t务?端?句?柄à¨2 #endregion #region方¤?法¤?§ private void GetLocalServer() { IPHostEntry IPHost = Dns.GetHostEntry(Dns.GetHostName()); if (IPHost.AddressList.Length > 0) { strHostIP = IPHost.AddressList[4].ToString(); this.tboxServerIP.Text = strHostIP.ToString(); } else { return; } IPHostEntry ipHostEntry = Dns.GetHostByAddress(strHostIP); strHostName = ipHostEntry.HostName.ToString(); try { SyServer = new OPCServer(); object serverList = SyServer.GetOPCServers(strHostName); foreach (string turn in (Array)serverList) { this.cmbServerName.Items.Add(turn); cmbServerName.SelectedIndex = 0; btnConnServer.Enabled = true; } } catch (Exception err) { MessageBox.Show("枚?举¨′本à?地ì?OPC服¤t务?器??出?错?¨a:êo"+err.Message,"提?¨¢示o?信?息?é",MessageBoxButtons.OK,MessageBoxIcon.Warning); } }

Delphi7.0开发OPC客户端程序(Siemens_Opc_client)

OPC是OLE for Process Control的缩写,即把OLE应用于工业控制领域,OPC是建立在O LE规范之上,它为工业控制领域提供了一种标准的数据访问机制。OPC服务器由三类对象组成:服务器(Server)、组(Group)、数据项(Item)。服务器对象(Server)拥有服务器的所有信息,同时也是组对象(Group)的容器。组对象(Group)拥有本组的所有信息,同时包容并逻辑组织OPC数据项(Item)。在这里数据项(Item)就是指所有的PLC信号的输入与输出。OPC组对象(Group)提供了客户组织数据的一种方法。客户可对之进行读写,还可以设置客户端的数据更新速率。当服务器缓冲区内的数据发生改变时,OPC将向客户发出通知,客户得到通知后再进行必要的处理。而无须浪费大量的时间进行查询。OPC规范定义了两种组对象:公共组和局部组(私有组)。公共组由多个客户共有,局部组只隶属于一个OPC客户。一般来说,客户和服务器的一对连接只需要定义一个组对象。在每个组对象中,客户可以加入多个OPC数据项(Item)。OPC数据项(Item)是服务器端定义的对象,通常指向设备的一个寄存器单元。OPC客户对设备寄存器的操作都是通过其数据项来完成的,通过OPC数据项(Ite m),OPC规范尽可能地隐藏了设备的特殊信息,也使OPC服务器的通用性大大增强。OPC 数据项(Item)并不提供对外接口,客户不能直接对之进行操作,所有的操作都是通过组对象进行的。每个OPC数据项(Item)的数据结构包括三个成员变量:即数据值、数据质量和时间 戳。数据值是以Variant形式表示的。 Delphi7.0加载Siemens动态库: 1.打开Delphi7.0,点击Project->Import Type Library 2.在Import Type Library里面找到Siemens OPC DAAutomation 2.0 (Version 1.0),在Clas s Nams里面可以看三个类方法(TOPCGroups,TOPCGroup,TOPCServer),默认的Palette Pag e为ActiveX,单击Install… Delphi7.0中编写客户端程序: 1.连接OPC服务器 在Form上面添加三个OPC控件: OPCGroup1: TOPCGroup; OPCGroups1: TOPCGroups; OPCServer1: TOPCServer;

(C#)OPC客户端源码

【转】(C#)OPC客户端源码 转载申明 申明:本文为转载,如需转载本文,请获取原文作者大尾巴狼啊的同意,谢谢合作! 转自:大尾巴狼啊 原文出处:https://www.doczj.com/doc/1542190.html,/xiaosacao/archive/2009/01/13/1374895.html 前几天我就发布过这篇文章,可惜的是,发布后代码有的却看不到,后来我就删了,至今不明白什么原因- -! 关于C++、VB来开发OPC客户端的资料网上有很多,但C#的至今没发现有多少。 由于近期项目的需要,就开发了OPC客户端的一个模块。在我想来,程序员挺累的,原因我很累。所以我想大家也很累~~~嘿嘿。特别是刚接手OPC客户端开发的前几天,天天盯住显示器,百度、GOOGLE不停的搜索。每天早上醒来,眼睛都瑟瑟的。 从事3年以上软件开发的朋友们,估计都会腰酸背痛吧!反正我是这样的。 不说那么多废话了,贴上源码,让需要的同行看看吧,代码的质量并不高,就当做抛砖引玉吧! 1、枚举本地服务器 2、获取服务器信息 3、列出了服务器上Tag 4、可以设置组的属性 5、读\写功能 6、可进行远程连接(DCOM需配置) 先看图:

引用类库: OPC服务器: 开发工具: 当前环境:

源码: ///程式使用C#.NET 2005 编写 ///引用类库OPCDAAuto.dll ///OPCServer采用KEPWare ///在windows xp sp2、sp3、windows 2003上测试通过///完成于:2008年12月31日 ///测试于:2009年01月05日 ///

///作者:潇洒草 ///Email:zhkai868@https://www.doczj.com/doc/1542190.html, ///QQ:44649029 /// ///如分发,请保留此摘要。 ///鄙视那些拿代码当宝贝的人,鄙视那些你不拿源码换就不稀罕你的人,鄙视那些自私的人。///别人看到你的代码,你能死啊?对你有多大威胁啊?强烈鄙视~~~ ///如果你是这样的人,赶紧关了。。偶不欢迎。。 using System; using System.Collections.Generic; using https://www.doczj.com/doc/1542190.html,ponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using https://www.doczj.com/doc/1542190.html,; using System.Collections; using OPCAutomation; namespace OPC测试通过 { public partial class MainFrom : Form { public MainFrom() {

VC环境下的OPC客户端程序开发

VC环境下的OPC客户端程序开发 来源:中国论文下载中心 [ 08-07-30 15:41:00 ] 作者:赵健师奕兵编辑: studa0714 Ads by Google 曙光刀片服务器TC2600支持Intel? Xeon? 5000系列处理器高密度高能效易管理低成本https://www.doczj.com/doc/1542190.html, OPC Grape Seed Extract Save 70% on our Premium Blend: Worldwide Shipping Quoted Upfront https://www.doczj.com/doc/1542190.html, SapphireTrend Premier OPC Trending solution for realtime process control & analysis https://www.doczj.com/doc/1542190.html, 摘要本文通过分析OPC 数据访问规范,介绍了有关OPC技术的基本概念、数据访问方式以及编写OPC客户端接口程序的一般方法。同时给出了一个具体实例,用Visual C++编写了一个OPC客户端接口程序,并利用OPC服务器KEPServer对其进行测试,实现了OPC客户端与OPC服务器之间的数据交换。 关键词OPC服务器;OPC客户端;COM技术 1 引言 随着通信技术、计算机技术和自动化技术的快速发展,大范围信息共享的需求在自动化系统中显得越来越来越重要,现代工业控制系统已逐渐发展成为以现场设备层、过程控制层和中央管理层三个层次组成的系统,因而对其开放性也提出了更高的要求。在传统的控制系统中,现场设备之间以及现场设备与控制软件之间的信息共享主要是通过驱动程序来实现的,不同厂家的设备使用不同的驱动程序,使得软件开发商不得不开发大量驱动程序来连接这些设备,即使设备厂家在硬件上做小小的改动,应用程序就可能重写,这也势必造成工业控制软硬件的升级与维护不便,给用户和软件开发商带来巨大的工作负担。同时,由于不同设备的驱动程序也有所不同,使得不同的应用程序也不能同时访问同一设备的数据,因此,需要制定一种统一开放的接口标准,使应用程序能够方便的存取一台或多台现场设备的数据,为不同厂商的软硬件提供一种系统集成和数据交换的途径。正是在自动化系统开放性要求的驱使下,促使了OPC技术的产生。 2 OPC技术简介 OPC(OLE for Process Control)是基于微软公司的DNA(Distributed InterNet Application)构架和COM (Component Object Model)/DCOM(Distributed COM)技术,根据易扩展性而设计的,OPC规范定义了一个工业标准接口,这个标准使得COM技术适用于过程控制和制造自动化等应用领域。OLE最初意思为对象链接与嵌入,是微软的复合文档技术。随着后续版本OLE2中导入了COM技术之后,现在的OLE在原版的基础上增加了更多新的功能,包括结构化存储、统一数据传输和自动化等,它已经成为独立于计算机语言、操作系统甚至硬件平台的

OPC客户端的实现

1引言 OPC(OLE for Process Control)是一个工业标准,他是许多世界领先的自动化和软、硬件公司与微软公司合作的结晶。管理该标准的组织是OPC基金会。该基金会的会员单位在世界范围内超过150个,包括了世界上几乎全部的控制系统、仪器仪表和过程控制系统的主要供应商。OPC 技术建立了一组符合工业控制要求的接口规范,将现场信号按照统一的标准与SCADA、HMI等软件无缝连接起来,同时将硬件和应用软件有效地分离开。只要硬件开发商提供带有OPC接口的服务器,任何支持OPC接口的客户程序均可采用统一的方式对不同硬件厂商的设备进行存取,无须重复开发驱动程序。如果希望将数据引入数据库进行统计分析,就要进行客户端开发。 2客户程序的设计方法与比较 客户程序的设计主要是指客户程序中OPC接口部分的设计。客户程序本身可以完成很多复杂的数据处理与显示功能,但需要通过OPC接口部分访问OPC服务器,对现场数据进行存取。 开发OPC、Data、Access、Client之前,要弄清服务器的大体情况,比如需要访问的服务器是否提供自动化接口、服务器的OPC的版本等,到目前为止,OPC有1.0和2.0两个版本,两个版本的接口定义不同,2.0版是对1.0的改进,但不兼容。 OPC客户端的主要任务: ①创建服务器对象。 ②建立与服务器的连接。 ③浏览OPC服务器的功能。客户程序需要创建OPC基金会提供的OPC服务器浏览器对象(OPCServerList)再通过该对象的IOPCServerList接口获得OPC服务器名称的列表;可以通过枚举注册表中包含“OPC”子键的程序名来浏览符合OPC数据存取规范的服务器,但效率较低。 ④通过OPC接口读写数据。 ⑤断开连接。

OPC客户端的自动化

OPC客户端的自动化实现 OPC是建立在COM,DCOM的基础商的,因此绝大多数语言都可以很好的进行开发。在Net中开发客户端有以下几种方式: (1)使用OPCNetAPI,需要用到OPCNetAPI.dll,https://www.doczj.com/doc/1542190.html,.dll (2)使用自动化接口,需要用到OPCDAAuto.dll (3)使用自定义接口,需要用到多个Wrapper:OpcRcw.Ae.dll,OpcRcw.Batc h.dll,https://www.doczj.com/doc/1542190.html,n.dll,OpcRcw.Da.dll,OpcRcw.Dx.dll,OpcRcw.Hda. dll,OpcRcw.Sec.dll 以上开发方式所需的动态链接库可以从OPC基金会(http://www.opcfoundati https://www.doczj.com/doc/1542190.html,/)的网站上下载,一些下载项目可能需要注册,或成为基金会的成员。 不同的方式有各自的有缺点,请参见… 本文使用自动化接口,https://www.doczj.com/doc/1542190.html,语言进行开发,开发项目是无线射频(RFID)卡方面的应用,典型的如公交车,或公司考勤使用的刷卡机。需要注意的是自动化接口存在一个“不是问题”的问题,数组下标是以1开始的,而不是传统计算机开发上的以0开始。不知道设计者头脑是怎么想(有人知道吗?);这可能会给一些语言的开发造成问题(有人碰到吗,没有你就是幸运的) 需求:OPCDAAuto.dll或该Dll的Interop (一):客户端开发流程 OPC客户端的开发主要遵循下图所示的开发流程,下面就从以下几个开发步骤进行说明 (二):枚举OPC服务器列表 枚举服务器主要是通过OPCServer接口的GetOPCServers方法来实现的,该方法会返回OPC服务器数组(以1为下界,上面已有说明),以下是代码段'枚举OPC服务器列表 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try GlobalOPCServer = New OPCAutomation.OPCServerClass() Dim ServerList As Object = GlobalOPCServer.GetOPCServers For index As Short = LBound(ServerList) To UBound(ServerList) '加入控件列 表中,注意这里使用LBound和UBound cbbServerList.Items.Add(ServerList(index)) Next If cbbServerList.Items.Count > 0 Then

OPC客户端搭建

1.OPC对象的分层结构 OPC数据访问提供从数据源读取和写入特定数据的手段。OPC数据访问对象是由下图所示的分层结构构成。即一个OPC服务器对象(OPCServer)具有一个作为子对象的OPC组集合对象(OPCGroups)。在这个OPC组集合对象里可以添加多个的OPC组对象(OPCGroup)。各个OPC组对象具有一个作为子对象的OPC标签集合对象(OPCItems)。在这个OPC标签集合对象里可以添加多个的OPC标签对象(OPCItem)。此外,作为选用功能,OPC服务器对象还可以包含一个OPC浏览器对象(OPCBrowser)。 OPC对象中的最上层的对象是OPC服务器。一个OPC服务器里可以设置一个以上的OPC 组。OPC服务器经常对应于某种特定的控制设备。例如,某种DCS控制系统,或者某种PLC 控制装置。OPC组是可以进行某种目的数据访问的多个的OPC标签的集合,例如某监视画面里所有需要更新的位号变量。正因为有了OPC组,OPC应用程序就可以以同时需要的数据为一批的进行数据访问,也可以以OPC组为单位启动或停止数据访问。此外OPC组还提供组内任何OPC标签的数值变化时向OPC应用程序通知的数据变化事件(表1-4)。

2.OPC客户端搭建过程(部分代码) 1)连接服务器 a)查询服务器端主机的名字。 string hostname = Dns.GetHostName(); b)初始化服务器对象,搜索主机上的服务器ID,并枚举出来。 public void searchlocalsvr(string hostName)//寻找本地服务器 { try { OPCSvr = new OPCServer(); object serverList = OPCSvr.GetOPCServers(hostName); foreach (string server in (Array)serverList) { Console.WriteLine("本地OPC服务器:{0}", server); } } catch (Exception err) { Console.WriteLine("枚举本地OPC服务器出错:{0}", err.Message); } } c)连接服务器。 public void ctOPCSever(string HostName)//连接OPC服务器 { string OPCSvrName; searchlocalsvr(HostName); Console.WriteLine("请输入要连接的服务器名字:"); OPCSvrName = Console.ReadLine(); try { OPCSvr.Connect(OPCSvrName, ""); Console.WriteLine("连接服务器成功!"); } catch (Exception err) { Console.WriteLine("连接本地OPC服务器出错:{0}", err.Message); } } 2)创建组(OPCGroups)对象和添加数据项对象(OPCItems) public void CreateGrp()//创建组对象 { try

VB编写OPC客户端程序

如何用VB编写OPC客户端程序 一、引言 在工业自动化领域,计算机早已成为必不可少的工具,计算机技术的不断发展,大大加速了工业自动化技术的进步,而各种各样的工业控制应用软件正是具体实现这一进程的最重要的工具。 以往,应用软件开发商要为每一种硬件开发驱动程序,由于硬件的种类繁多,特征各异,软件开发商的负担异常繁重,尤其是如果硬件特征发生了变化,整个应用软件相应的驱动程序也要相应地修改,这对软件开发商,对整个工程都是很不利的。而且由于驱动程序的不统一,不同应用程序访问同一硬件设备时常常发生冲突。OPC(OLE for Process Control)技术标准正是在这种情况下产生的。OPC 基于微软的OLE、COM和DCOM技术,而且它本身就是一种特殊的COM,也正因为有微软的参与,以及以已经成熟的技术为基础,它比一般的工业标准制定的效率更高,它从开始制定到第一个可运行的规范开始运行,只用了不到一年的时间。 二、OPC原理及应用 OPC技术为工业自动化软件面向对象的开发提供了统一的标准。它大大减轻了软件开发商的负担,软件开发商不必再为每一硬件单独编写驱动程序,只要硬件的特征符合统一的OPC接口程序标准,或者硬件生产商提供OPC服务器,如图一所示,不同的应用软件开发商都可以采用OPC标准设计工控软件,以标准规定的统一接口通过OPC服务器存取现场数据。 这样,当现场设备发生变化或系统中加入新设备时,OPC服务器的提供商需要重新实现服务器接口,以适应硬件的变化,但由于服务器所提供的接口的一致性,工控软件不作更改即可继续使用,只是某些情况下可能需要重新组态(如添加新的PLC站点等),这样,软件开发商可以节省大量的时间致力于工控软件的性能方面的提高,不必再考虑硬件变化带来的影响,大大减小了软件维护的工作量。这正如OPC规范里所说,OPC将应用软件和硬件设备划清了界限。 2.1 OPC基本结构 OPC服务器有两类接口:定制接口(Custom Interface) 、自动化接口(Automation Interface),定制接口比较低级,它提供更多的功能,效率也比后者高,可以用C++语言调用此类接口,自动化接口主要用于VB、DELPHI等开发工具。按照OPC规范,定制接口是服务商必须提供的,而自动化接口则是可选的,不过,OPC基金会(管理OPC标准的国际组织)提供了一个叫做“自动化包装器”的动态连接库,用于在两者间转换。如图二所示: 在OPC的早期规范里主要包括OPC数据存取规范、OPC报警和事件、OPC 历史数据存取规范。OPC数据存取规范详细规定了客户程序和服务器程序进行数据通信的机制,其它类型的OPC服务器往往是在数据存取服务器的基础上通过增加对象、扩展接口而来的,所以该规范也是其它OPC规范的基础。OPC数据存取规范规定的基本对象有三类:OPC Server、OPC Group和OPC Item,OPC Server包含服务器的所有信息,也是OPC Group的容器,OPC Group除了包含它自身信息外,还负责管理OPC Item。它们的结构如图三所示。每一个OPC Item代表到数据源的一个连接,但它没有提供外部接口,客户端程序无法

OPC客户端源码

申明:本文为转载,如需转载本文,请获取原文作者大尾巴狼啊的同意,谢谢合作! 转自:大尾巴狼啊 原文出处: 前几天我就发布过这篇文章,可惜的是,发布后代码有的却看不到,后来我就删了,至今不明白什么原因- -! 关于C++、VB来开发OPC客户端的资料网上有很多,但C#的至今没发现有多少。 由于近期项目的需要,就开发了OPC客户端的一个模块。在我想来,程序员挺累的,原因我很累。所以我想大家也很累~~~嘿嘿。特别是刚接手OPC客户端开发的前几天,天天盯住显示器,百度、GOOGLE不停的搜索。每天早上醒来,眼睛都瑟瑟的。 从事3年以上软件开发的朋友们,估计都会腰酸背痛吧!反正我是这样的。 不说那么多废话了,贴上源码,让需要的同行看看吧,代码的质量并不高,就当做抛砖引玉吧! 1、枚举本地服务器 2、获取服务器信息 3、列出了服务器上Tag 4、可以设置组的属性 5、读\写功能 6、可进行远程连接(DCOM需配置) 先看图: 引用类库: OPC服务器:

当前环境: 源码: ET 2005 编写 oString(); } else { return; } + "."+ } oString() + " Error:"+ (i).ToString(); } } oString(); = (i).ToString(); = (i).ToString(); } } mail 2009-03-31 15:01 | 李默[未注册用户]

能给我份源码吗? 2009-04-04 19:01 | 滕大鹏[未注册用户] #30楼回复引用 我想要文档,能给份吗?谢谢 2009-04-04 19:03 | 滕大鹏[未注册用户] #31楼回复引用 谢谢楼主,我的邮箱是,能给我发一份全部的资料吗? 2009-04-07 14:02 | TJC #32楼回复引用 谢谢,传份给我,要全部资源(文档+源码),万分感谢!2009-04-08 22:02 | hxf[未注册用户] #33楼回复引用 急需一份资料谢谢 2009-04-11 16:34 | jhjohn[未注册用户] #34楼回复引用 麻烦传份给我,要全部资源(文档+源码),万分感谢 2009-04-13 08:36 | yldx #35楼回复引用 您好!麻烦传分全部资源(文档+源码),谢谢 2009-04-15 13:00 | xhm0924[未注册用户] #36楼回复引用 谢谢,传份给我,要全部资源(文档+源码),万分感谢!急用2009-04-25 09:35 | bestyaq

别人学习opc客户端开发的体会

OPC协议的编写 2010-01-28 14:20:46| 分类:通信类| 标签:|字号大中小订阅 我从北京买了一本《OPC应用程序入门》,在此之前基本上只是知道有OPC,在五月四日开始,我学了七天。其中有苦有甜。我写下来,权做休息或是练练打字。 第一天 安装了《入门》提供的东西,包括是下面几个文件。还有个批处理文件,是一个注册过程。 opccomn_ps.dll opcproxy.dll opcdaauto.dll OPCTrend.ocx OPCBar.ocx OpcServer.exe OPCJDADemoServer.exe 看了一阵书,知道了前三个是:通用接口,PROXY-STUB,自动化接口。不明白。 后面两个是demo 服务器。 上网,用GOOGLE,查OPC,很自然就找到了https://www.doczj.com/doc/1542190.html,.,又下了个free 服务器。安装了(注册)。 到了工控网,看到有人在推荐clienttools,就下了一个,叫WXOPC。运行一下, 点击连接服务器图标,立即出现了三个: OPCJ.SAMPLESERVER.1 OPCJ.DADEMOSERVER.1 HEXATEC.PCDATA

第三个是opcconnect上download的计算机基本情况的简单程序。 点击他们,还出现了一些“item”,“value"的内容还在变,有意思。我就想这工具还真不错,不知我能不能做到,但一想,如果这些功能都做不到,这OPC就没多少 人敢学,也就没有市场。 有一段时间没用VB了,先热了热身,看了自己过去编过的code。 第二日 今天先看书。 《OPC应用程序入门》,40元,我花了48元,从汇款到收到用了12天,拿到手上,感觉很单薄。我的看书观点是:在看的过程中迷信书,看完后怀疑书,然后忘记书。尽管这本书上我立即就发现 有错误。我还是仔细地看下去。 这是一本教人们用VB编应用客户端程序的书,希望让一般工控技术员认识OPC其实不复杂, 最起码编用户程序(客户端)不难。 在这之前,我对COM和DCOM技术有所了解,也是很模糊的,OPC以COM和DCOM技术为基础,主要是在服务器端(server),而在用户端并不要很在意它们。 书上对OPC体系有描述,我画了个图。 OPCserver是COM组件,如果安装(注册了)一个OPCserver后,利用WINDOWS的组件工具可以看到,如果这个server安装在别的计算机上,不是本地机,那它就是个DCOM组件(分布式)。 OPC基金会公布了通用接口(用户接口),用C++访问OPCserver只要通过这个接口就可以, 并没有必要了解OPCserver是怎么工作的。 对于VB、VBA、EXCEL、DELPHI等编程软件或工具,不能直接访问通用接口,而要通过所谓的自动化接口(automation interface),OPC组织发布了DATA ACESS 2.0,实际上已经有了3.0版。

OPC客户端开发工具包

OPC客户端开发工具包 使用手册 北京安捷尔软件技术有限公司 版本:2.1

前言 OPC(OLE for Processing Control)是工控行业的软件接口标准,主要用来解决控制系之间或控系统与设备之间数据交换的标准化问题。OPC规范包括数据访问服务器(DA)、历史数据访问服务器(HDA)、事件与报警服务器(A/E)、XML数据访问服务器(XML DA)、等一系列标准规范。OPC规范由OPC基金会负责制定并对OPC产品进行认证。 OPC规范具有如下的优点: (1) 统一的接口标准简化了软件的开发和减低了系统维护的费用 (2) 充分的开放性和标准化特性,保证高度柔韧性系统的实现 (3) 持续的版本升级,保证了规范的先进性 (4) 支持DCOM、.Net架构 本文档介绍OPC数据访问客户端开发工具包(以下简称客户端工具包)的特点和如何利用开发工具包进行OPC 数据访问客户端的开发。 本文共分为四个部分: 一、介绍了OPC的基本概念; 二、DA客户端的开发流程; 三、详细描述了工具包的接口描述; 四、附录部分介绍了一些与DA开发相关的OPC规范和其他内容。

1.工具包简介 1.1. OPC工具包简介 OPC工具包产品以标准动态连接库(DLL)形式提供二次开发接口,与Win98、WinNT、WIN2000、WIN2003系统完全兼容。OPC开发工具包由服务器工具包、客户端开发工具包组成,完全封装了OPC技术实现细节,使二次开发的程序员无需OPC规范底层细节,降低服务器和客户端程序开发的复杂程度和减少了熟悉OPC技术的时间。 1.2. 工具包的特点 数据访问服务器工具包于2004年3月开始研发,经过两次大规模升级,实现了对OPC 数据访问服务器规范(以下简称 DA规范)的全面支持(支持规范版本1.0、2.0、3.0)。工具包具有以下特点: z完全符合DA标准,通过OPC基金会兼容性产品测试 z完全的封装使二次开发人员不需要了解COM技术和OPC规范接口细节 z工具包支持多种开发语言,如VC、BC、VB、Delphi等 z逻辑清晰、功能明确的二次开发函数保证用户进行二次开发简单容易 z支持同步、异步数据通讯方式 z支持自定义属性读写 z支持树型地址空间 z支持分布式体系结构 z完备的产品升级和完善的技术支持,提供现场技术服务和远程技术指导 1.3. 工具包的产品分类 z单一授权(加密锁),用此类工具包开发完成的客户端产品安装的目标计算机需要安装加密锁,没有加密锁服务器无法持续运行。这类产品适合于产品开发次数比较 少的用户,如小型MIS用户、系统集成用户等。 z无限授权(序列号激活),用此类工具包开发完成的客户端产品运行时无需判断加密锁,工具包可以重复进行使用。这类产品适合于硬件厂商开发OPC驱动程序、软 件厂商为软件提供OPC标准服务器接口。 1.无限授权(源码),提供开发工具源码。

OPC客户端的研究与开发

OPC客户端的研究与开发 随着计算机技术的发展,计算机在工业控制领域发挥着越来越重要的作用。各种仪器仪表都提供了与计算机通信的协议相通的功能。但是,不同厂家产品的协议互不相同,即使上一同一家公司的不同产品与计算机之间的通信协议也不尽相同。因为不同的语言和运行环境对驱动程序的接口有不同的要求,所以不仅软件厂商需要编写大量设备驱动,硬件厂家也需要为应用程序开发不同的驱动,这样软硬件厂商无疑都加大了开发成本,同时此方案也不符合软件工程的发展趋势,在这样的背景下,OPC技术应运而生。 OPC(OLE for Process Control)技术为工业控制领域提供了一种标准的数据访问机制,将硬件与应用软件有效的分离开来。不同的硬件厂商只需为各自的设备提供带有OPC接口的服务器,软件厂商可以采用支持OPC接口的客户端程序对它们进行统一方式的访问。 1OPC技术的特点 OPC(OLE for Process Control)是工控行业的软件接口标准,它试图按照标准的方法完成不同设备之间数据的交换。OPC基金会是OPC规范的制定者,制定了数据访问、历史数据访问、事件与报警、批处理、OPC DA XML等一系列标准。 OPC基于微软的COM技术,它具有如下的优点: (1)高速的数据传输; (2)基于分布式COM的安全性管理机制; (3)降低开发成本; (4)可以实现具有高度柔韧性功能的系统; (5)可以实现具有高可靠性的系统。 1.1 OPC服务器 OPC数据访问提供数据源读取和写入特定数据的手段。OPC数据访问对象是如图1所示的分层结构构成。 一个OPC服务器对象(OPC SERVER)具有一个作为子对象的OPC组集合对象(OPC GROUPS);在这个OPC组集合对象里可以添加多个OPC组对象(OPC GROUP);各个OPC 组对象都具有一个作为子对象的OPC标签集合对象(OPC ITEMS);在这个OPC标签集合对象里面可以添加多个OPC标签对象(OPC ITEM)。此外,作为选用功能,OPC服务器对象还可以包含一个OPC浏览器对象(OPC BROWER)。一般OPC服务器包含下述的3类对象,即服务器、组、数据项。 (1)服务器对象。对象包含服务器的所有信息,同时也是组对象的容器。一个OPC服务器对应于一个OPC SERVER,即一种设备的驱动程序。在一个SERVER中,可以有若干个组;(2)组对象。组对象包含本组的所有信息,同时包含并管理OPC数据项。客户可以对其进行读写,还可以设置客户端的数据更新速率。OPC规范定义了2种组对象:公共组(全局组,PUBLIC)和局部组(局域组,LOCAL)。公共组可以被多个客户访问,而局域组只能由建立它的客户端访问;

基于Visual C#的OPC客户端实现

基于Visual C#的OPC客户端实现 时间:2009-04-28 16:08:22 来源:现代电子技术作者:朱立军,安娜,陈未如沈阳化工学 院 摘要:OPC是连接数据源(OPC服务器)和数据的使用者(OPC应用程序)之间的软件接口标准。这里以C#为开发工具,按照OPC技术的规范标准,将OPC技术应用到虚拟仪器显示组件中。具体实现了OPC客户端数据访问服务器的过程,接口步骤及其读写数据的方法,并根据OPC服务器提供的数据,最终在虚拟仪器显示组件中生成了虚拟的正弦波、方波、锯齿波、三角波等。 关键词:OPC;OPC接口;OPC服务器;C# 0 引言 随着计算机技术和数字信号处理技术的发展,人们可以用计算机软件替代传统的硬件实现的一些功能,将计算机硬件和软件有机的融合为一体,这就是所谓的虚拟仪器。近年来,世界各国的虚拟仪器公司开发了不少基于LabVIEW,Matlab,VC++,VB等虚拟仪器开发平台软件,当硬件操作的设备驱动改变时,软件开发人员需要修改大量的驱动程序来连接此设备,因此使得虚拟仪器开发平台开发难度大、通用性差。为此,提出了基于OPC技术的虚拟仪器,它是由硬件供应商和软件开发商之间建立一套完整的“规则”,只要遵循这套规则,数据交互对两者来说都是透明的,硬件供应商无需考虑应用程序的多种需求和传输协议,软件开发商也无需了解硬件的实质和操作过程。 l OPC技术 OPC(OLE Process Contro1)是OPC基金会组织倡导的工业控制和生产自动化领域中使用的硬件和软件的接口标准,以便有效地在应用和过程控制设备之间读写数据,具体的功能实现要由开发商根据需要自主的进行研究与开发。换句话说OPC规范是一套公共的软件标准,任何OPC开发人员所开发的OPC软件都要符合这个标准。 OPC技术的特点可概括为如下3个方面:开放性(Openness)、产业性(Productivity)和“即插即用”的互联性(Connectivity),因此可以说, “OPC=Openness+Productivity+Connectivity”,这也是对OPC优点最概括的描述。因此OPC在短时间内取得了飞速的发展。 1.1 OPC服务器的组成 OPC标准采用C/S模式,OPC服务器负责向OPC客户端不断的提供数据。OPC 服务器包括3类对象(Object):服务器对象(Server)、组对象(roup)和项对象(Item)。3类对象都包括一系列接口,关系如图1所示。

用VB开发OPC客户端程序的步骤与实现

(1)建立新工程或项目,在“工程”菜单下选择“引用”,如图5-3所示。只有引用OPCDAAuoto.DLL后,在程序中才能创建服务器对象,然后进行一系列的操作。 (2)在弹出的引用窗口里单击“浏览(B)…”按钮,弹出添加引用窗口,选择OPCDAAuoto.DLL 文件。 (3)在引用窗口里的OPC Automation 2.0前面打钩,按“确定”按钮。 (4)定义全局变量,这样可以在窗体的任何方法的代码内应用。变量类型应该指定为对象型。这些对象最好在窗体的通用部分声明加上“Option Explicit”语句,表示模块里的所有变量都需要显式声明。由于OPC自动化接口的数组的索引要求必须从1开始,而系统默认是从0开始,为了避免错误最好在代码的最初加上“Option Base 1”语句。为了使对象可以处理事件,必须将objTestGrp和objServer的声明中加上“WithEvents”语句,表示声明的对象可以响应事件。 Option Explicit Option Base 1 Dim WithEvents objServer As OPCServer Dim objGroups As OPCGroups Dim WithEvents objTestGrp As OPCGroup Dim objItems As OPCItems (5)连接OPC服务器和建立OPC组 考虑到代码的可反复使用性,采用子程序进行编程。 Sub Connect(strProgID As String, Optional strNode As String) If objServer Is Nothing Then ' 建立一个OPC服务器对象 Set objServer = New OPCServer End If 服务器状态ServerState属性一共有OPCRunning、OPCFailed、OPCNoconfig、OPCSuspended、OPCTest和OPCDisconnected六个值,分别表示正在运行、失败、没有配置、暂停、测试和

最简单的访问OPC服务器方法

最简单的访问OPC服务器 在网上搜了很多关于https://www.doczj.com/doc/1542190.html,编写客户端访问OPC服务器的资料,同时也根据KEPWARE提供的案例源代码,同时进行研究,最后花了一个星期的时间进行研究,才粗略有了一点头绪,现共享出来,希望后来的初学者有所帮助。 一.要建一个OPC服务器 1)安装OPC服务器软件,KEPware是大家比较常用的,我使用的是Kepware OPC V4.54。如图,添加CHANNEL,添加TAG.把Plc的点位添加进去,我建了6个变量(item)。具体添加的方法需要自行去学习。我添加的三菱Q系列的PLC,PLC采用以太网通讯的方式,在局部网就可以访问了。 2)设置DCOM,这个步骤很重要,具体的设置方法,网上很多资料,按步骤设置就可以。我原来按照组态王提供的方法,总是不成功,后来上了微软网站,按微软提供的方法设置肯定可以成功。 完成了以上两步,你的电脑就变成OPC服务器了。 二.访问服务器 1.利用组态软件访问OPC服务器。 如果用组态王访问,那就太简单了,左边列表,选opc服务器,点击添加服务器,就会弹出一个窗口,把本机的OPC服务器列成清单。在清单里面就可以发现KEPSERVER的名称: KEPware.KEPserverEx.V4,选择,然后按确定,就完成了添加服务器。

在组态王的数据词典,新建变量,I/O变量,连接设备选择OPC服务器,寄存器可以看到KEPserver的变量(item),建立之后,就可以利用组网王,开发监控应用,组态软件的使用在此就不赘述了,总之,利用组态软件访问OPC是最简单的。 2.用https://www.doczj.com/doc/1542190.html,开发客户端访问 访问opc服务器,必须使用OPC基金会提供的OPCdaauto.dll。学习过程,最好下载说明书,

相关主题
文本预览
相关文档 最新文档