PC与西门子PLC - 通讯实例+源代码 

PC与西门子PLC 通讯实例+源代码

此实例为PC调用西门子第三方驱动libnodave.dll,通过VB6.0编写而成,可成功从SIEMENS SL系统PLC中读取其DB数据块,input输入/output输出映像区,Marker位存储区数据.【libnodave.dll 可百度下载,或者Mail我】

Private Sub Command1_Click() Dim peer As String peer = Form1.Text1.Text ph = openSocket(102, peer) If ph = 0 Then

MsgBox \Else

If ph > 0 Then '需要更换新的端口

di = daveNewInterface(ph, ph, \0, daveProtoISOTCP, daveSpeed187k) '建立新的连接

res = daveInitAdapter(di) '初始化适配器 If res = daveResOK Then

dc = daveNewConnection(di, 2, Rack, Slot) '建立新的PLC连接

res = daveConnectPLC(dc) '连接PLC If res = daveResOK Then MsgBox \\End If End If End If End If End Sub

Private Sub Command2_Click() If dc <> 0 Then

res = daveDisconnectPLC(dc) '断开连接

Seccussfully!\

vbInformation,

Call daveFree(dc) '释放内存 dc = 0 End If If di <> 0 Then

res = daveDisconnectAdapter(di) '断开适配器 Call daveFree(di) '释放内存 di = 0 End If If ph <> 0 Then

res = closePort(ph) '关闭端口 ph = 0 End If

MsgBox \\End Sub

Private Sub Command3_Click() Dim RetCode As Long

Dim PLCTime As T_S7_PLCTime

RetCode = S7_ReadPLCTime(dc, PLCTime) If RetCode <> daveResOK Then

MsgBox \Read PLC Time failed!\vbInformation, \ Exit Sub

Successfully!\

vbInformation,

End If

Form1.Label1.Caption = \Date is \& Format(PLCTime.Jahr, \& \& Format(PLCTime.Monat, \ Form1.Label2.Caption = \Time Format(PLCTime.Stunden, \& Format(PLCTime.Minuten, \& Format(PLCTime.Sekunden, \& Format(PLCTime.Millisekunden, \End Sub

Private Sub Command4_Click()

res = daveReadBytes(dc, daveFlags, 0, 0, 16, 0) If res = daveResOK Then v1 = daveGetS32(dc) MsgBox \ v2 = daveGetS32(dc) MsgBox \ v3 = daveGetS32(dc) MsgBox \ v4 = daveGetFloat(dc) MsgBox \ v5 = daveGetFloatAt(dc, 12) MsgBox \ Else

is \\\\

& & & &

MsgBox \ End If End Sub

Private Sub Command5_Click()

res = daveReadBytes(dc, daveDB, 21, 3, 1, 0) If res = daveResOK Then MsgBox daveGetS32(dc) Else

MsgBox \End If End Sub

2015-12-29



联系客服:cand57il.com