发表于:2006/5/18 22:03:00
#0楼
还是刚才的问题,这是我的接口程序,各位大虾看看,帮我找找原因,我用的是CPM1A40点的PLC
Private Sub exitcmd_Click()
MSComm1.PortOpen = False
Unload Me
End Sub
'Mscomm 空间初始化
Private Sub Form_Load()
MSComm1.CommPort = 1 '(设置串口号为1 ,串口号的范围为1 - 16 ,默认为1)
MSComm1.Settings = "9600 ,E ,7 ,2" '(设置通信参数)
MSComm1.InputMode = comInputModeText '(以文本方式接收数据)
'(打开串口)
MSComm1.PortOpen = True
init = "@00SC02"
MSComm1.Output = fcs(init) + "*" + Chr$(13) '(启动PLC)
End Sub
'校验码FCS 的计算程序
Private Function fcs(frame As String) As String
Dim L As Integer
Dim i As Integer
Dim A, B
Dim fcsd, fcsp
B = 0
L = Len(frame)
A = Right(frame, 1)
If A = "*" Then L = L - 3 Else L = L - 2
fcsp = Mid(frame, L + 1, 2)
Print fcsp
For i = 1 To L
B = Asc(Mid(frame, i, 1)) Xor B
Next i
fcsd = Hex(B)
Print fcsd
If Len(fcsd) = 1 Then fcs = "0" + fcsd
If fcsd <> fcsp Then fcs = "ERR"
Print fcs
fcs = frame + fcs
End Function
'发送命令
Private Sub SendMsg_Click()
Dim SendMsg1 As String
SendMsg1 = "@00WD0005080"
MSComm1.Output = fcs(SendMsg1) + "* " + Chr$(13)
End Sub
'接收数据
Private Sub RecMsg_Click()
Dim response As String
Dim cmdStr As String
cmdStr = "@00RD00050012"
MSComm1.Output = fcs(cmdStr) + "* " + Chr$(13)
For i = 1 To 3000
i = i + 1
Next i
response = MSComm1.Input
rectxt.Text = response
End Sub
还有现在想在VB界面上建一个可以输入PLC一些简单指令的文本框(不需要支持梯形图),从哪里可以找到这些指令对应的机器码,或者还有其他什么方法?
Private Sub exitcmd_Click()
MSComm1.PortOpen = False
Unload Me
End Sub
'Mscomm 空间初始化
Private Sub Form_Load()
MSComm1.CommPort = 1 '(设置串口号为1 ,串口号的范围为1 - 16 ,默认为1)
MSComm1.Settings = "9600 ,E ,7 ,2" '(设置通信参数)
MSComm1.InputMode = comInputModeText '(以文本方式接收数据)
'(打开串口)
MSComm1.PortOpen = True
init = "@00SC02"
MSComm1.Output = fcs(init) + "*" + Chr$(13) '(启动PLC)
End Sub
'校验码FCS 的计算程序
Private Function fcs(frame As String) As String
Dim L As Integer
Dim i As Integer
Dim A, B
Dim fcsd, fcsp
B = 0
L = Len(frame)
A = Right(frame, 1)
If A = "*" Then L = L - 3 Else L = L - 2
fcsp = Mid(frame, L + 1, 2)
Print fcsp
For i = 1 To L
B = Asc(Mid(frame, i, 1)) Xor B
Next i
fcsd = Hex(B)
Print fcsd
If Len(fcsd) = 1 Then fcs = "0" + fcsd
If fcsd <> fcsp Then fcs = "ERR"
Print fcs
fcs = frame + fcs
End Function
'发送命令
Private Sub SendMsg_Click()
Dim SendMsg1 As String
SendMsg1 = "@00WD0005080"
MSComm1.Output = fcs(SendMsg1) + "* " + Chr$(13)
End Sub
'接收数据
Private Sub RecMsg_Click()
Dim response As String
Dim cmdStr As String
cmdStr = "@00RD00050012"
MSComm1.Output = fcs(cmdStr) + "* " + Chr$(13)
For i = 1 To 3000
i = i + 1
Next i
response = MSComm1.Input
rectxt.Text = response
End Sub
还有现在想在VB界面上建一个可以输入PLC一些简单指令的文本框(不需要支持梯形图),从哪里可以找到这些指令对应的机器码,或者还有其他什么方法?