vb调用 dll文件的函数实现与s7-200的通讯问题
硬件:一台pc机,无CP5611一类的卡
编程线缆PC adapter USB(进口),PC/PPI
CPU224 (6ES7 214-1BD23 0XB0),无扩展模块
实现:VB编写上位机程序(已附于问题后面),调用prodave V5.6 W95_s7.dll
条件:1、PC/PG设定Local地址为0,搜索到的CPU224地址为1
2、波特率设定为9.6Kbps
3、PC adapter USB(进口),PC/PPI两种连接均尝试过
问题:上述实验条件下
Res = load_tool(1, "S7ONLINE", plcadr) ''S7ONLINE Micro/WIN
返回的Res的值总是0X320,,查手册错误代码的含义是hardware error
求解:上述问题的原因以及解决的办法。
ps.
QQ:499051120
Email:311gip@163.com
/*声明部分*/
Public plcadr As plcadrtype
Public gb_PlcConnected As Boolean
Type plcadrtype
ADR As Byte
SEGMENTID As Byte
SLOTNO As Byte
RACKNO As Byte
End Type
Public Res As Long
Public Declare Function as200_e_field_read Lib "w95_s7.dll" (ByVal nr As Long, ByVal anz As Long, value As Byte) As Long
Public Declare Function as200_a_field_write Lib "w95_s7.dll" (ByVal nr As Long, ByVal anz As Long, value As Byte) As Long
Public Declare Function as200_vs_field_read Lib "w95_s7.dll" (ByVal nr As Long, ByVal anz As Long, value As Byte) As Long
Public Declare Function load_tool Lib "w95_s7.dll" (ByVal nr As Byte, ByVal dev As String, ADR As plcadrtype) As Long
Public Declare Function unload_tool Lib "w95_s7.dll" () As Long
/*窗体部分*/
Private Sub Test_Click()
Dim buffer(1) As Byte
plcadr.ADR = 1
plcadr.SEGMENTID = 0
plcadr.SLOTNO = 1
plcadr.RACKNO = 0
Res = load_tool(1, "S7ONLINE", plcadr) ''S7ONLINE Micro/WIN
If Res <> 0 Then
MsgBox ("PLC连接错误")
gb_PlcConnected = False
Else
gb_PlcConnected = True
MsgBox ("plc连接正确")
Test.Caption = buffer(0)
End If
Res = unload_tool()
End Sub
//---------------------------------------------------------------------------------------------------------
问题补充:
PC机上安装了
Micro Win 4.0 sp4
Step7 V5.4
最佳答案
请参看下述连接:
http://wsj180.blog.163.com/blog/static/298363622010919103243674/
http://www.ad.siemens.com.cn/service/answer/solve_68591_1028.html
http://www.docin.com/p-6061149.html
提问者对于答案的评价:
问题找到了
1、貌似pc/ppi线缆不能用于prodave直接连接pc跟s7-200,pc adapter usb可以
2、连接函数load_tool(1, "S7ONLINE", plcadr)中plcadr的参数应为【1,0,0,0】
3、Micro/Win 由V4.0 sp4 升级为sp8
反正我是这么给解决了问题
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc303099.html