发表于:2004/10/26 11:32:00
#0楼
下面是我试编的程序,我往DM0000中写入FFFF,然后将PLC的响应显示在Text1中。运行时,程序没有报告错误,但是在Text1中没有任何反应。请大家帮忙看看。谢谢
Private Sub Command1_Click()
Dim outdata, L, fcs1, i, FCS, instring, fcs2, fcs3 As String
outdata = "@00WD0000FFFF"
L = Len(outdata)
fcs1 = 0
For i = 1 To L
fcs1 = fcs1 Xor Asc(Mid(outdata, i, 1))
Next i
FCS = Hex(fcs1)
Text1.Text = FCS
MSComm1.Output = outdata + "FCS " + "*" + Chr$(13)
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 10
instring = MSComm1.Input
Text2.Text = instring
fcs2 = 0
For i = 1 To Len(instring) - 4
fcs2 = fcs2 Xor Asc(Mid(instring, i, 1))
Next i
fcs3 = Hex(fcs2)
If fcs3 = Mid(instring, Len(instring) - 3, 2) Then
Text3.Text = "right"
Else
Text3.Text = "wrong"
End If
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,7,2"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
End Sub
Private Sub Command1_Click()
Dim outdata, L, fcs1, i, FCS, instring, fcs2, fcs3 As String
outdata = "@00WD0000FFFF"
L = Len(outdata)
fcs1 = 0
For i = 1 To L
fcs1 = fcs1 Xor Asc(Mid(outdata, i, 1))
Next i
FCS = Hex(fcs1)
Text1.Text = FCS
MSComm1.Output = outdata + "FCS " + "*" + Chr$(13)
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 10
instring = MSComm1.Input
Text2.Text = instring
fcs2 = 0
For i = 1 To Len(instring) - 4
fcs2 = fcs2 Xor Asc(Mid(instring, i, 1))
Next i
fcs3 = Hex(fcs2)
If fcs3 = Mid(instring, Len(instring) - 3, 2) Then
Text3.Text = "right"
Else
Text3.Text = "wrong"
End If
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,e,7,2"
MSComm1.InputLen = 0
MSComm1.PortOpen = True
End Sub