发表于:2002/3/17 10:03:00
#0楼
各位专家:我参考别人编写的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 = Tr
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 = Tr