西门子 OPC 客户端的 VB6 代码示例?

发布于 2024-12-17 20:12:40 字数 221 浏览 5 评论 0原文

我正在尝试更新一个古老的 VB6 项目以启用与远程 OPC 服务器的通信。我已经安装了西门子工具包,但我找不到任何有关如何将其与 VB6 一起使用的有用文档。 (适用于 C#)

该应用程序非常简单。我只需要连接到远程服务器并写入/读取单个地址。

我发现 DatCon OCX 控件我认为它可以处理通信,但我尝试手动输入的所有 ServerName 值都不起作用。

有人可以帮忙吗?

I am trying to update an ancient VB6 project to enable communication with a remote OPC Server. I have installed the Siemens toolkit but I am unable to find any useful documentation on how to use it with VB6. (Works with C#)

The application is very simple. I just need to connect to the remote server and write/read single addresses.

I found the DatCon OCX control which I assume handles the communication but all the ServerName values I tried to enter by hand did not work.

Can anyone help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟燃烟灭 2024-12-24 20:12:40

将 DLL 或 OCX(seimens 工具包)的引用添加到 VB6 项目中,然后使用对象浏览器浏览公开的对象。你常常可以通过这样做来弄清楚你需要什么。

C# 文档还应该提供丰富的信息。如果该库是 COM 库,则您将按照与 VB6 基本相同的方式使用它。

Add a reference to the DLL or OCX (the seimens toolkit) to your VB6 project and then use the object browser to browse around the exposed objects. You can often times figure out what you need just be doing that.

The C# docs should also provide a wealth of info. If the library is a COM library, you'll use it essentially the same way from VB6.

热血少△年 2024-12-24 20:12:40

自从发帖以来,我确实取得了一些进步。下面的例子帮助我开始。

http://support.automation.siemens.com/WW/llisapi.dll?func=cslib.csinfo&objId=25229521&load=treecontent&lang=en&siteid=cseus&aktprim=0& objaction=csview&extranet=standard&viewreg=WW

这是我当前的代码。这并不多 - 只是与服务器联系并尝试写入一个值。我没有再进一步。我开始收到 COM 错误并认为安装有问题(我在安装时遇到了问题),所以我决定重新安装。它不起作用。安装是不可能的。等待西门子升级。

'
' OPC Communication
'
' Paul Ramsden 24.11.2011
'
'

Option Explicit
Option Base 1

Public MyOpcServer As OPCServer
Public ServerHandle As Variant

Private ServerName As String
Private ServerNode As String
Private TestGroup As OPCGroup
Private MyOpcItem As OPCItem
Private IsInitialised As Boolean


Public Sub InitialiseOPC()
    On Error GoTo ProcError
    IsInitialised = False

    Set MyOpcServer = New OPCServer
    ServerNode = "xyz.abc.10.101"
    ServerName = "OPC.SimaticNET.1"
    Dim LocalServers
    LocalServers = MyOpcServer.GetOPCServers(ServerNode)
    Dim tmp
    ServerHandle = ""
    For Each tmp In LocalServers
        If CStr(tmp) = ServerName Then
            Call MyOpcServer.Connect(tmp)
            MsgBox MyOpcServer.ServerNode & vbCr & MyOpcServer.ServerName & vbCr & MyOpcServer.ServerState
            ServerHandle = tmp
            Set TestGroup = MyOpcServer.OPCGroups.Add("TestGroup")
            Exit For
        End If
    Next

    If ServerHandle = "" Then
        MsgBox "Could not find server " & ServerName & " on " & ServerNode
    Else
        IsInitialised = True
    End If
ProcExit:
    Exit Sub

ProcError:
    MsgBox Err.Description
    Resume ProcExit
End Sub

Private Sub ClearGroup()
    Dim handles() As Long
    Dim errors() As Long

    Call TestGroup.OPCItems.Remove(TestGroup.OPCItems.Count, handles, errors)
End Sub

Public Sub WriteOPC(address As String, value As String)
    On Error GoTo ProcError
    Call ClearGroup
    Set MyOpcItem = TestGroup.OPCItems.AddItem(address, 2011)
    MyOpcItem.Write (value)
    Exit Sub

ProcError:
    MsgBox "Write error! " & Err.Description
End Sub

Public Function ReadOPC(address As String) As String
    On Error GoTo ProcError

    Call ClearGroup
    Set MyOpcItem = TestGroup.OPCItems.AddItem(address, 2011)
    Dim value As String
    ReadOPC = MyOpcItem.Read

ProcError:
    MsgBox "Read error! " & Err.Description
End Function

Public Sub TestOPC()
    InitialiseOPC
    WriteOPC "SIMATIC 300(1).CPU 315-2 DP.Q0_0TestAusgang1", "1"
End Sub

Since posting, I did make some progress. The following example helped me to get going.

http://support.automation.siemens.com/WW/llisapi.dll?func=cslib.csinfo&objId=25229521&load=treecontent&lang=en&siteid=cseus&aktprim=0&objaction=csview&extranet=standard&viewreg=WW

Here is my current code. It's not much - just makes contact with the server and tries to write a value. I didn't get any further. I started getting COM errors and assumed the installation was bad (I had had problems installing) so I decided to reinstall. It didn't work. Installation was impossible. Waiting for an upgrade from Siemens.

'
' OPC Communication
'
' Paul Ramsden 24.11.2011
'
'

Option Explicit
Option Base 1

Public MyOpcServer As OPCServer
Public ServerHandle As Variant

Private ServerName As String
Private ServerNode As String
Private TestGroup As OPCGroup
Private MyOpcItem As OPCItem
Private IsInitialised As Boolean


Public Sub InitialiseOPC()
    On Error GoTo ProcError
    IsInitialised = False

    Set MyOpcServer = New OPCServer
    ServerNode = "xyz.abc.10.101"
    ServerName = "OPC.SimaticNET.1"
    Dim LocalServers
    LocalServers = MyOpcServer.GetOPCServers(ServerNode)
    Dim tmp
    ServerHandle = ""
    For Each tmp In LocalServers
        If CStr(tmp) = ServerName Then
            Call MyOpcServer.Connect(tmp)
            MsgBox MyOpcServer.ServerNode & vbCr & MyOpcServer.ServerName & vbCr & MyOpcServer.ServerState
            ServerHandle = tmp
            Set TestGroup = MyOpcServer.OPCGroups.Add("TestGroup")
            Exit For
        End If
    Next

    If ServerHandle = "" Then
        MsgBox "Could not find server " & ServerName & " on " & ServerNode
    Else
        IsInitialised = True
    End If
ProcExit:
    Exit Sub

ProcError:
    MsgBox Err.Description
    Resume ProcExit
End Sub

Private Sub ClearGroup()
    Dim handles() As Long
    Dim errors() As Long

    Call TestGroup.OPCItems.Remove(TestGroup.OPCItems.Count, handles, errors)
End Sub

Public Sub WriteOPC(address As String, value As String)
    On Error GoTo ProcError
    Call ClearGroup
    Set MyOpcItem = TestGroup.OPCItems.AddItem(address, 2011)
    MyOpcItem.Write (value)
    Exit Sub

ProcError:
    MsgBox "Write error! " & Err.Description
End Sub

Public Function ReadOPC(address As String) As String
    On Error GoTo ProcError

    Call ClearGroup
    Set MyOpcItem = TestGroup.OPCItems.AddItem(address, 2011)
    Dim value As String
    ReadOPC = MyOpcItem.Read

ProcError:
    MsgBox "Read error! " & Err.Description
End Function

Public Sub TestOPC()
    InitialiseOPC
    WriteOPC "SIMATIC 300(1).CPU 315-2 DP.Q0_0TestAusgang1", "1"
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文