发表于:2014/7/20 9:56:25
#0楼
无论PLC还是VB6.0,我都是菜鸟。开始学PLC已经半年,结合手边的模型,写的PLC已经能够正常运行,进一步把PLC的运行数据记录到PC数据库的数据表中,成了逾越不去的坎。根据中达电通王乃全公布的程序架构,完全能够对PLC进行启动停止控制。主要是读不出寄存器中的数据,也不发出“传输错误”的提醒。请高手帮忙看看下面的读取程序错在什么地方:
'读取PLC数据
Private Sub read_Click()
RThreshold = 0项目
SThreshold = 0
Dim q1 As String
Dim q2 As String
Dim q22
Dim q3 As String
Dim q4 As String
Dim q9Len As Integer
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
q2 = "010310190004" '01--PLC站号;03--读取寄存器命令;1019--DVP PLC始读寄存器D25地址;0004--连续读取4位寄存器至 D28
q22 = LRC(q2)
q1 = ":" + q2 + q22 + Chr$(13) + Chr$(10)
MSComm1.Output = q1
Timer5.Enabled = False '关闭定时器
q3 = MSComm1.Input
q4 = Mid(q3, 1, 5)
If q4 = ":" & "0103" Then
q5$ = Mid(q3, 8, 4)
q6$ = Mid(q3, 12, 4)
q7$ = Mid(q3, 16, 4)
q8$ = Mid(q3, 20, 4)
q15$ = "&h" + q5$
q16$ = "&h" + q6$
q17$ = "&h" + q7$
q18$ = "&h" + q8$
q25! = Val(q15$)
q26! = Val(q16$)
q27! = Val(q17$)
q28! = Val(q18$)
Text3.Text = q25!
Text4.Text = q26!
Text5.Text = q27!
Text6.Text = q28!
Else
MsgBox "传输错误"
End If
Timer5.Enabled = True '打开定时器
End Sub
'读取PLC数据
Private Sub read_Click()
RThreshold = 0项目
SThreshold = 0
Dim q1 As String
Dim q2 As String
Dim q22
Dim q3 As String
Dim q4 As String
Dim q9Len As Integer
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
q2 = "010310190004" '01--PLC站号;03--读取寄存器命令;1019--DVP PLC始读寄存器D25地址;0004--连续读取4位寄存器至 D28
q22 = LRC(q2)
q1 = ":" + q2 + q22 + Chr$(13) + Chr$(10)
MSComm1.Output = q1
Timer5.Enabled = False '关闭定时器
q3 = MSComm1.Input
q4 = Mid(q3, 1, 5)
If q4 = ":" & "0103" Then
q5$ = Mid(q3, 8, 4)
q6$ = Mid(q3, 12, 4)
q7$ = Mid(q3, 16, 4)
q8$ = Mid(q3, 20, 4)
q15$ = "&h" + q5$
q16$ = "&h" + q6$
q17$ = "&h" + q7$
q18$ = "&h" + q8$
q25! = Val(q15$)
q26! = Val(q16$)
q27! = Val(q17$)
q28! = Val(q18$)
Text3.Text = q25!
Text4.Text = q26!
Text5.Text = q27!
Text6.Text = q28!
Else
MsgBox "传输错误"
End If
Timer5.Enabled = True '打开定时器
End Sub
[此贴子已经被作者于2014/7/20 14:13:53编辑过]