label3.linktopic = “rslinx|” & “b01主系统”
label3.linkitem = “s:41”
label3.linkmode = 1
label3.linkrequest
label5.linktopic = “rslinx|” & “b01主系统”
label5.linkitem = “s:40”
label5.linkmode = 1
label5.linkrequest
label10.linktopic = “rslinx|” & “b01主系统”
label10.linkitem = “n60:11”
label10.linkmode = 1
label10.linkrequest
label12.linktopic = “rslinx|” & “b01主系统”
label12.linkitem = “n60:130”
label12.linkmode = 1
label12.linkrequest
label14.linktopic = “rslinx|” & “b01主系统”
label14.linkitem = “n60:131”
label14.linkmode = 1
label14.linkrequest
end sub
其中,代码中的“rslinx”和“b01主系统”分别表示应用程序名和主题名,“linkmode”值为1表示连接方式为automatic(即“热连接”)方式。这样当该应用代码被执行时,label的值便随a-b plc内存值的变化而变化。具体执行如图13所示。
2012-11-2 13:49:02 上传
下载附件(48.02 KB)
在excel中实现通过dde方式访问a-b plc 首先必须先安装rs linx创建dde topic. 比如我们定义一个topic名叫“b01主系统”,打开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
rsichan = ddeinitiate(“rslinx”, “ b01主系统”)
varlogging = dderequest(rsichan, “n60/163”)
varcycle = dderequest(rsichan, “n60/161”)
l/?
if varcycle(1) = “1” and varlogging(1) = “1” then
lngrow = 3
if range(“indata!a3”).value 》 3 then
lngrow = range(“indata!a3”).value
end if
for lngrow = lngrow to 65500
if cells(lngrow, 1) = “” then exit for
range(“indata!a3”).value=lngrow + 1
next
rsichan = ddeinitiate(“rslinx”, “n1”)
f810data = dderequest(rsichan, “f8:10”)
f811data = dderequest(rsichan, “f8:11”)
f812data = dderequest(rsichan, “f8:12”) f816data = dderequest(rsichan, “f8:16”) (责任编辑:admin) |