请教各位高手,我用VB做FX1S的PLC与PC的通信,可是不知道为什么,连起来试的时候没有反应,把程序贴上来哪位懂得给看看是哪里出问题了?非常感谢各位,谢谢了!
下面的程序实现的功能是,PC向PLC发送数据,PLC再反馈回给PC并显示出来!可是运行到 DoEvents
就没有反应了,单步执行发现out中是空的,也就是说PLC没有回应,不知道是什么原因?拜托各位高手了!
Private Sub Command3_Click()
If Not frm1.MSComm1.PortOpen Then
frm1.MSComm1.PortOpen = True
End If
Dim rd As String
If Text3.Text <> "" And Text4.Text <> "" Then
rd = "00FFTT" + "0" + Trim(Text3.Text) + Trim(Text4.Text)
frm1.Text5.Text = Comm_Write(rd)
End If
End Sub
Function Comm_Write(rd As String) As String
Dim out As String, data As String, a As Integer, b As String
out = Chr(&H5) + rd + GetSumChk(rd)
frm1.MSComm1.InputLen = 0
frm1.MSComm1.InBufferCount = 0
frm1.MSComm1.Output = out
Do
DoEvents
Loop Until frm1.MSComm1.InBufferCount >= 7 + Val(Trim(Text3.Text))
data = frm1.MSComm1.Input
a = Val(Asc(Left(data, 1)))
b = GetSumChk(Mid(data, 2, Len(data) - 3))
If a = 3 And b = Mid(data, Len(data) - 1, 2) Then
Comm_Write = Mid(data, 8, Val(Trim(Text3.Text)))
End If
End Function