发表于:2006/7/7 16:28:00
#0楼
我想利用下面这段代码检测PC是否与PLC连接上,但是老是显示“没有与远程连接”,请教各位高手,这个问题出在哪里?我的PLC是三菱的FX2n
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
LoopData = "00FFTT008ABCDEFGH"
MSComm1.Output = Chr(5) + LoopData + SumChk(LoopData)
If Err Then
MsgBox Error$, 48, "回路检测"
Exit Sub
End If
Tim = Timer
Do
If Timer > Tim + 1 Then MsgBox "没有与远程连接!": Exit Sub
Loop Until MSComm1.InBufferCount > 17
If Left$(MSComm1.Input, 16) = Chr(2) + cboStation.Text + "FF08ABCDEFGH" + Chr(3) Then
MsgBox "接通正常...", , "回路检测"
Else
MsgBox "通信出错!!", 48, "回路检测"
End If
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
LoopData = "00FFTT008ABCDEFGH"
MSComm1.Output = Chr(5) + LoopData + SumChk(LoopData)
If Err Then
MsgBox Error$, 48, "回路检测"
Exit Sub
End If
Tim = Timer
Do
If Timer > Tim + 1 Then MsgBox "没有与远程连接!": Exit Sub
Loop Until MSComm1.InBufferCount > 17
If Left$(MSComm1.Input, 16) = Chr(2) + cboStation.Text + "FF08ABCDEFGH" + Chr(3) Then
MsgBox "接通正常...", , "回路检测"
Else
MsgBox "通信出错!!", 48, "回路检测"
End If