2

I have an Excel macros that can't connect with KEPServer using Visual Basic.

The thing is that for some versions of windows computers can connect with it while for others can't. Currently I'm using windows 10, Excel 2010 and KEPServer 5.13. The macros used to work perfectly, so some kind of windows update must have make it fail.

The program fails while doing a DDERequest and it returns the Error 2023. I also noticed that KEPServer keeps giving the following error:

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

The Vba used code is:

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
  ...

It uses NetDDE to connect with the KEPServer. I know it is obsolete and think that might be the problem and there is a more modern way to do it, using OLE, but I dont really know how to do it and if it will even work.

What do you think I can do in order to fix it or if it exists any way to connect them using OLE?

Obsidian
  • 3,719
  • 8
  • 17
  • 30

1 Answers1

0

In my limited experience with iot:P,The use of OPCUA or OPCDA requires the use of reasonable DDE components, and when these components are updated, there may be coordination problems between versions.

You can consider using MQTT or HTTP, which is a simpler and common way to obtain PLC data, such as using LECPServer (similar to Kepserver), but he can use HTTP protocol to read and write PLC content.

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

The VBA code is as follows

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
JamesChan
  • 51
  • 3