发表于:2007/6/13 22:16:00
#0楼
我用VB做PC与FX1SPLC通信,1对1方式,采用专用协议,格式1,现在现在的问题是PLC没有反映,不知道是怎么回事?我是新手,希望各位指点指点,谢谢了!
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InBufferSize = 1024
MSComm1.InBufferCount = 0
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
MSComm1.InputLen = 0
End Sub
Private Sub Command1_Click()
Dim str As String
Dim rdw As String
Dim rdh As String
Dim rdm As String
rdw = "00FFBT003Y00111Y00050Y00011"
str = Chr(5) + rdw + "FA"
MSComm1.InputLen = 0
MSComm1.Output = str
Debug.Print str
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 5
Debug.Print "1:" & rdh
rdh = MSComm1.Input
Debug.Print "2:" & rdh
If rdh = Chr(6) + "00FF" Then
MsgBox ("测试成功!")
ElseIf rdh = Chr(H15) + "00FF" Then
MsgBox ("传输数据出错!")
Else
MsgBox ("测试失败!")
End If
End Sub
再次谢谢各位了!
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InBufferSize = 1024
MSComm1.InBufferCount = 0
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
MSComm1.InputLen = 0
End Sub
Private Sub Command1_Click()
Dim str As String
Dim rdw As String
Dim rdh As String
Dim rdm As String
rdw = "00FFBT003Y00111Y00050Y00011"
str = Chr(5) + rdw + "FA"
MSComm1.InputLen = 0
MSComm1.Output = str
Debug.Print str
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 5
Debug.Print "1:" & rdh
rdh = MSComm1.Input
Debug.Print "2:" & rdh
If rdh = Chr(6) + "00FF" Then
MsgBox ("测试成功!")
ElseIf rdh = Chr(H15) + "00FF" Then
MsgBox ("传输数据出错!")
Else
MsgBox ("测试失败!")
End If
End Sub
再次谢谢各位了!