各位專家:我參考別人編寫的VB通過三菱PLC的采集(頁 1) - 三菱論壇 - 自動化論壇 Autooo.net - Autooo.Net
自動化論壇完整版 自動化論壇 Autooo.net » 三菱論壇 » 各位專家:我參考別人編寫的VB通過三菱PLC的采集

2008-4-16 23:08 sanling
各位專家:我參考別人編寫的VB通過三菱PLC的采集

各位專家:我參考別人編寫的VB通過三菱PLC的采集各位專家:我參考別人編寫的VB通過三菱PLC的采集程序,不是很明白,請各位幫幫手,萬分感謝!(問題點在程序後打問號的),還有我想問一下多串口通訊采用什麼形式比較好?用VB自帶控件能勝任嗎?用DLL(如:MOXA的PCMM.DLL)是否更好一些?謝謝!!! Public Function ForcingM(PlcPort As Integer, ByVal m_no As Integer, ByVal Is_On As Boolean) As Boolean    Dim oldtime As Long    Dim newtime As Long    Dim senddata As String    Dim ReturnStr As String * 256    Dim Addr As Integer    Dim aa As Integer    Dim i As Integer    Dim ll As Integer    Dim XiaBiao As Integer    Dim FlagTime As Boolean    Dim mbit(4) As String * 1    ForcingM = False         '清空緩衝區    aa = sio_flush(PlcPort, 2)   Addr = &H800   m_no                ?什麼意思?為什麼要 &H800?   For i = 0 To 3     mbit(i) = Hex(Addr And &HF)       ?什麼意思?為什麼要AND &HF?     Addr = Int(Addr / 16)              ?   Next   senddata = Chr$(&H2)   If Is_On Then      senddata = senddata & "7"   Else      senddata = senddata & "8"   End If   senddata = senddata & mbit(1)         ?   senddata = senddata & mbit(0)         ?   senddata = senddata & mbit(3)         ?   senddata = senddata & mbit(2)         ?   senddata = senddata & Chr$(&H3)     aa = 0     For i = 2 To 7       aa = aa   Asc(Mid(senddata, i, 1))      ?什麼意思?       aa = aa And &HFF                         ?     Next        senddata = senddata & Hex(Int(aa / 16) And &HF)    ?什麼意思?   senddata = senddata & Hex(aa And &HF)               ?     '把命令發送     aa = sio_write(PlcPort, senddata, Len(senddata))          '查看緩衝區     oldtime = timeGetTime     FlagTime = False     Do       aa = sio_iqueue(PlcPort)       newtime = timeGetTime       If (newtime < oldtime) Then          oldtime = 0       Else          If (newtime - oldtime) > 1000 Then              FlagTime = True          End If       End If     Loop While aa <> 1 And FlagTime = False          If FlagTime = True Then       '超時       GoTo err     End If          '從緩衝區裏取值,並把緩衝區清空     ll = sio_read(PlcPort, ReturnStr, aa)     If ll <> 1 Then        GoTo err     End If '   Data61 = Val("&H" & Mid(ReturnStr, 6, 1))    If Asc(Mid(ReturnStr, 1, 1)) <> 6 Then          ?是否是確認收到數據(ACK)?      GoTo err    End If     '   aa = sio_close(PlcPort)    ForcingM = True    Exit Function  err:  '  sio_close (PlcPort)    End Function 工控搜索  查找 PLC 工控搜索  查找 三菱 工控搜索  查找 三菱PLC

頁: [1]

Google


Autooo.Net
Copyright © 2007 All rights reserved