将 Excel VBA 宏与 KEPServer 连接:DDERequest 错误 2023

问题描述 投票:0回答:1

某些版本的 Windows 计算机可以连接。

我使用的是 Windows 10、Excel 2010 和 KEPServer 5.13。该宏曾经有效,因此 Windows 更新一定导致其失败。

DDERequest 返回错误 2023。

KEPServer 也给出以下错误:

Date        Time         Level        Source                      Event
21/01/2020  16:57:23     Error        DDE                         Attempt to add DDE item 'TOOL1.PLC.MESCADA_BoxProductionCounter' failed.

VBA代码:

Private Sub Establish_Connection_Click()

    Dim Tmp_Old_BoxProductionCounter As Variant
    
    RSIchan = DDEInitiate("kepdde", "_ddedata")
    
    Estat_Conexio.Text = " Connected to hardware "
    
    Mode = "Automatic"
    
    Tmp_Old_BoxProductionCounter = DDERequest(RSIchan, "TOOL1.PLC.MESCADA_BoxProductionCounter")'<-- It fails here   
    
    Old_BoxProductionCounter = Tmp_Old_BoxProductionCounter(1)
    
    Call Worksheet_Activate
    collected_rows = 2
  
    Initiate_Study.Enabled = False
    ...

它使用 NetDDE 与 KEPServer 连接。我知道它已经过时了,这可能是问题所在,并且有一种更现代的方法,即使用 OLE,但我不知道它如何以及是否有效。

excel vba opc kepserverex
1个回答
0
投票

以我有限的iot经验:P,使用OPCUA或OPCDA需要使用合理的DDE组件,并且当这些组件更新时,版本之间可能会出现协调问题。

可以考虑使用MQTT或者HTTP,这是一种更简单、常用的获取PLC数据的方式,比如使用LECPServer(类似Kepserver),但是他可以使用HTTP协议来读写PLC内容。

https://github.com/xeden3/LECPServer https://lecpserver.com/feature/

VBA代码如下

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
URL = "http://172.10.26.11"
objHTTP.Open "POST", URL, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.send "{""action"":""plc_read_node"", ""node"":""NODES.DEV01.D100""}"
sResp = oHttp.ResponseText
© www.soinside.com 2019 - 2024. All rights reserved.