| |
---|---|
(点击题目可以在互联网中搜索该题目的相关内容) 日期:2006-7-10 22:34:27 来源: 作者: 点击: | |
如何使用Excel通过 DDE VBA方式访问Allen Bradley PLC? 首先必须先安装RS Linx创建DDE topic. 比如我们定义一个topic名叫“N1” 打开Excel,创建宏命令 ,编写VBA脚本如何读取和写入数据,从而完成与PLC的数据交换. <<<<<<<<<<<<<<<<<<<开始>>>>>>>>>>>>>>>>>> Sub Start() Dim lngRow As Long Dim varCycle As Variant Dim varLogging As Variant Dim varResults As Variant On Error GoTo Error opens a COLD DDE link RSIchan = DDEInitiate("RSLinx", "N1") assign PLC bit values to VB variant varibles varLogging = DDERequest(RSIchan, "B3/163") varCycle = DDERequest(RSIchan, "B3/161") close COLD DDE link DDETerminate (RSIchan) check to see if the Cycle bit went to "1" if it did, excute read data If varCycle(1) = "1" And varLogging(1) = "1" Then starts at row 3 of sheet lngRow = 3 If Range("INDATA!A3").Value > 3 Then look up last cell and change position lngRow = Range("INDATA!A3").Value End If check until end of sheet For lngRow = lngRow To 65500 look for next empty cell If Cells(lngRow, 1) = "" Then Exit For write current cell location to sheet INDATA rather than writing a loop to search on every cycle, by the time the log is at row 21,500 | |
上一篇: 基于OPC技术的上位机与PLC之间的通信 下一篇: 如何通过VB以DDE方式与AB PLC进行通讯? |