发表于:2007/6/2 7:43:00
#0楼
求高手帮帮忙,我的VB程序有问题还是我设置的有问题,具体运行结果见“程序及运行结果”
Private Sub Command1_Click()
Dim OutputStr As String
Dim send As String
send = "@00WR0000001"
MSComm1.OutBufferCount = 0
OutputStr = send + FCS(send) + "*"
MSComm1.Output = OutputStr + Chr$(13)
End Sub
Function FCS(ByVal InputStr As String) As String
Dim Slen, i, Xorresult As Integer
Dim Tempfes As String
Slen = Len(InputStr)
Xorresult = 0
For i = 1 To Slen
Xorresult = Xorresult Xor Asc(Mid$(InputStr, i, 1))
Next i
Tempfes = Hex$(Xorresult)
If Len(Tempfes) = 1 Then Tempfes = "0" + Tempfes
FCS = Tempfes
End Function
Private Sub Form1_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.Settings = "9600,E,7,2"
End Sub
Private Sub Command1_Click()
Dim OutputStr As String
Dim send As String
send = "@00WR0000001"
MSComm1.OutBufferCount = 0
OutputStr = send + FCS(send) + "*"
MSComm1.Output = OutputStr + Chr$(13)
End Sub
Function FCS(ByVal InputStr As String) As String
Dim Slen, i, Xorresult As Integer
Dim Tempfes As String
Slen = Len(InputStr)
Xorresult = 0
For i = 1 To Slen
Xorresult = Xorresult Xor Asc(Mid$(InputStr, i, 1))
Next i
Tempfes = Hex$(Xorresult)
If Len(Tempfes) = 1 Then Tempfes = "0" + Tempfes
FCS = Tempfes
End Function
Private Sub Form1_Load()
MSComm1.CommPort = 1
MSComm1.PortOpen = True
MSComm1.Settings = "9600,E,7,2"
End Sub