组态上位机
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
上位机软件设计
上位机组态软件设计的界面中进行数据、曲线等监控、实时报警。
在Visual Basic 可视化编程中要通过选取通讯控件对其属性进行设置。在程序
中进行初始化对波特率、通信数据长度、停止位长度、校验等参数进行设置。
下位机编程时同样要进行初始化对波特率、通信数据长度、停止位长度、校验等参数进行设置。
表5-3
放组态画的控制界面图
上位机程序
VB与组态王、应用程序间的动态数据交换(DDE)程序Dim A(8) As String
Dim i As Integer
Dim plc1 As String
Dim plc2 As String
Dim plc3 As String
Dim sg(10) As Long
Dim strData As String
Dim str As String
Dim measureValue As String
Dim giveValue As String
Dim success As String
Dim canShu As Double
Private Sub Form_Load()
For i = 0 To 8
A(i) = "A" & (i + 1)
Next i
'For i = 0 To 8
' Text1(i).Text = A(i)
'Next i
'定义远程主机及端口和对应本地端口For i = 0 To 8
udpClient(i).RemoteHost = A(i) udpClient(i).RemotePort = 2000 udpClient(i).Bind (2001 + i) Next i
'定义远程主机及端口和对应本地端口udpClient(9).RemoteHost = "B1" udpClient(9).RemotePort = 2000 udpClient(9).Bind 2011
udpClient(10).RemoteHost = "B2" udpClient(10).RemotePort = 2000
udpClient(10).Bind 2012
'**********************定义从组态王接收的数据*************************
For i = 0 To 10
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' plc1 = "errorValue"
plc1 = plc1 & i
plc1 = plc1 + ".STATIC100"
Text4(i).LinkTopic = "VIEW|tagname"
Text4(i).LinkItem = plc1 'errorValue
Text4(i).LinkMode = vbLinkNone
Text4(i).LinkMode = vbLinkAutomatic
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' plc2 = "giveMinute"
plc2 = plc2 & (i + 1)
plc2 = plc2 + ".STATIC100"
Text5(i).LinkTopic = "VIEW|tagname"
Text5(i).LinkItem = plc2 'giveMinute
Text5(i).LinkMode = vbLinkNone
Text5(i).LinkMode = vbLinkAutomatic
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' plc3 = "wordPlc"
plc3 = plc3 & i
plc3 = plc3 + ".STATIC5"
Text6(i).LinkTopic = "VIEW|tagname"
Text6(i).LinkItem = plc3
Text6(i).LinkMode = vbLinkNone
Text6(i).LinkMode = vbLinkAutomatic
Next i
End Sub
Private Sub Text6_Change(Index As Integer)
Dim wordToServer As String
Dim wordToAll As String
If Text6(Index).Text = 1 Then
wordToServer = InputBox(message, "给他发信息")
If wordToServer <> "" And Label1(Index).ForeColor = vbGreen Then On Error Resume Next
udpClient(Index).SendData "W" & wordToServer
End If
End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' If Text6(0).Text = 3 Then
wordToAll = InputBox(message, "给所有人发信息")
If wordToAll <> "" Then
For i = 0 To 10
If Label1(i).ForeColor = vbGreen Then
On Error Resume Next
udpClient(i).SendData "W" & wordToAll
End If