发布于 2012-09-17 20:57:06
4楼
下面是我的源码,应该没有问题啊?
****在模块中声明****:
Public plcadr As plcadrtype
Public gb_PlcConnected As Boolean
Type plcadrtype
adr As Byte ‘站地址,默认值为2
SEGMENTID As Byte ‘段标识符,固定值为0
SLOTNO As Byte ‘槽的编号,默认值为2
RACKNO As Byte ‘机架号,固定为0
End Type
Public Res As Long
Declare Function load_tool Lib "w95_s7.dll" (ByVal nr As Byte, ByVal dev As String, adr As plcadrtype) As Long
。。。。。。。 ‘省略其它定义函数。
Declare Function as200_vs_field_read Lib "w95_s7.dll" (ByVal nr As Long, ByVal anz As Long, value As Byte) As Long ‘读200PLC V存储区的数据函数
****在窗体中声明****
Private Sub Form_Load()
Dim buffer(1) As Byte
plcadr.adr = 2
plcadr.SEGMENTID = 0
plcadr.SLOTNO = 2
plcadr.RACKNO = 0
Res = load_tool(1, "S7ONLINE", plcadr)
Res = as200_vs_field_read(0, 2, buffer(0))
If Res <> 0 Then
MsgBox ("PLC连接错误")
gb_PlcConnected = False
Else
gb_PlcConnected = True
MsgBox ("plc连接正确")
Label1.Caption = buffer(0) * 256 + buffer(1)
End If
End Sub
执行Res = load_tool(1, "S7ONLINE", plcadr)时,res=206,这是什么错误?