⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmmain.vb

📁 OPC CLIENT开发包
💻 VB
📖 第 1 页 / 共 2 页
字号:
	Public Sub mnuGroupStatus_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuGroupStatus.Click
		frmGroupStatus.frmGroupName = GroupName
        frmGroupStatus.ShowDialog()
		If frmGroupStatus.mbReturn Then
			If frmGroupStatus.frmGroupName <> GroupName Then
                If OPC_SetGroupName(ServerHandle, GroupHandle, frmGroupStatus.frmGroupName) Then
                    GroupName = frmGroupStatus.frmGroupName
                End If
			End If
            OPC_SetGroupStat(ServerHandle, GroupHandle, frmGroupStatus.UpdateRate, frmGroupStatus.Active, frmGroupStatus.TimeBias, frmGroupStatus.DeadBand, 0)
		End If
	End Sub
	
	Public Sub mnuHelpAbout_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuHelpAbout.Click
        frmAbout.ShowDialog()
	End Sub
	
	Public Sub mnuItemStatus_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuItemStatus.Click
        Dim bactive As Integer
        If lvListView.FocusedItem Is Nothing Then Exit Sub
		frmItemStatus.ItemName = lvListView.FocusedItem.Text
        frmItemStatus.ShowDialog()
        If frmItemStatus.DialogResult = Windows.Forms.DialogResult.OK Then
            If frmItemStatus.bActive.Checked Then
                bactive = 1
            Else
                bactive = 0
            End If
            OPC_ActiveItem(ServerHandle, GroupHandle, Integer.Parse(lvListView.FocusedItem.Tag.ToString()), bactive)
        End If
    End Sub
	
	Public Sub mnuReadItem_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuReadItem.Click
		Dim lvItem As System.Windows.Forms.ListViewItem
		
		If lvListView.FocusedItem Is Nothing Then Exit Sub
		Dim Var As Object
		Dim Ft As Double
		Dim ftdt As FILETIME
		Dim Quality As Short
		
        If OPC_ReadItem(ServerHandle, GroupHandle, Integer.Parse(lvListView.FocusedItem.Tag.ToString()), Var, Ft, Quality) Then
            ftdt = DoubleToFileTime(Ft)
            ItemArr(lvListView.FocusedItem.Tag).Value = Var
            ItemArr(lvListView.FocusedItem.Tag).Quality = Quality
            ItemArr(lvListView.FocusedItem.Tag).Ft = ftdt
            If lvListView.FocusedItem.SubItems.Count > 1 Then
                lvListView.FocusedItem.SubItems(1).Text = Var
            Else
                lvListView.FocusedItem.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, Var))
            End If
            If lvListView.FocusedItem.SubItems.Count > 2 Then
                lvListView.FocusedItem.SubItems(2).Text = Quality.ToString()
            Else
                lvListView.FocusedItem.SubItems.Insert(2, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, Quality.ToString()))
            End If
            If lvListView.FocusedItem.SubItems.Count > 3 Then
                lvListView.FocusedItem.SubItems(3).Text = FileTimeToDate(ftdt).ToString()
            Else
                lvListView.FocusedItem.SubItems.Insert(3, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, FileTimeToDate(ftdt).ToString()))
            End If
        End If
	End Sub
	
	
	Public Sub mnuGroupRefresh_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuGroupRefresh.Click
        OPC_RefreshGroup(ServerHandle, GroupHandle, 1)
	End Sub
	
	
	Public Sub mnuRemoveItem_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuRemoveItem.Click
        'Dim lvItem As System.Windows.Forms.ListViewItem
		
		If lvListView.FocusedItem Is Nothing Then Exit Sub
		
		If RemoveItem(lvListView.FocusedItem.Tag) Then
			lvListView.Items.RemoveAt(lvListView.FocusedItem.Index)
		End If
	End Sub
	
	Public Sub AddItem(ByRef ItemName As String)
		Dim Index As Integer
		Dim lvItem As System.Windows.Forms.ListViewItem
		Index = AddItemM(ItemName)
		If Index > 0 Then
            lvItem = lvListView.Items.Insert(0, "K" & Index.ToString(), ItemName, "")
            lvItem.Tag = Index.ToString()
            If lvItem.SubItems.Count > 1 Then
                lvItem.SubItems(1).Text = "Bad"
            Else
                lvItem.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, "Bad"))
            End If
            If lvItem.SubItems.Count > 2 Then
                lvItem.SubItems(2).Text = ""
            Else
                lvItem.SubItems.Insert(2, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, ""))
            End If
            If lvItem.SubItems.Count > 3 Then
                lvItem.SubItems(3).Text = ""
            Else
                lvItem.SubItems.Insert(3, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, ""))
            End If
		End If
	End Sub
	
	Public Sub RefreshItem(ByRef Index As Short)
		On Error Resume Next
		Dim lvItem As System.Windows.Forms.ListViewItem
        lvItem = lvListView.Items.Item("K" & Index.ToString()) 'Index
		If lvItem Is Nothing Then Exit Sub
        If lvItem.SubItems.Count > 1 Then
            lvItem.SubItems(1).Text = ItemArr(Index).Value
        Else
            lvItem.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, ItemArr(Index).Value))
        End If
        If lvItem.SubItems.Count > 2 Then
            lvItem.SubItems(2).Text = ItemArr(Index).Quality.ToString()
        Else
            lvItem.SubItems.Insert(2, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, ItemArr(Index).Quality.ToString()))
        End If
        If lvItem.SubItems.Count > 3 Then
            lvItem.SubItems(3).Text = CStr(FileTimeToDate(ItemArr(Index).Ft))
        Else
            lvItem.SubItems.Insert(3, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, FileTimeToDate(ItemArr(Index).Ft).ToString()))
        End If
		
	End Sub
	
	Public Sub mnuServerStatus_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuServerStatus.Click
		Dim ftStart, ftCurrent As Object
		Dim ftUpdate As Double
		Dim BandWidth As Object
		Dim GroupCount As Integer
		Dim MajorVersion, State, MinorVersion As Object
		Dim BuildNumber As Short
		Dim vendor As String
        vendor = New String(New Char, 128)
        If OPC_GetServerStatus(ServerHandle, ftStart, ftCurrent, ftUpdate, State, BandWidth, GroupCount, MajorVersion, MinorVersion, BuildNumber, vendor, 128) Then
            frmServerStatus.Text1.Text = FileTimeToDate(DoubleToFileTime(ftStart)).ToString()
            frmServerStatus.Text2.Text = FileTimeToDate(DoubleToFileTime(ftCurrent)).ToString()
            frmServerStatus.Text3.Text = FileTimeToDate(DoubleToFileTime(ftUpdate)).ToString()
            frmServerStatus.Text4.Text = BandWidth.ToString()
            frmServerStatus.Text5.Text = State.ToString()
            frmServerStatus.Text6.Text = GroupCount.ToString()
            frmServerStatus.Text7.Text = MajorVersion.ToString()
            frmServerStatus.Text8.Text = MinorVersion.ToString()
            frmServerStatus.Text9.Text = BuildNumber.ToString()
            frmServerStatus.ShowDialog()
        End If
	End Sub
	
	Public Sub mnuWriteItem_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles mnuWriteItem.Click
		Dim Index As Integer
		Dim Value As Object
		If lvListView.FocusedItem Is Nothing Then Exit Sub
        frmItemWrite.ShowDialog()
		If frmItemWrite.mbReturn = False Then Exit Sub
		If frmItemWrite.Value = "" Then Exit Sub
        Index = lvListView.FocusedItem.Tag
        Value = frmItemWrite.Value
        If OPC_WriteItem(ServerHandle, GroupHandle, Index, Value, frmItemWrite.Async) Then
            ItemArr(Index).Value = Value
            If lvListView.FocusedItem.SubItems.Count > 1 Then
                lvListView.FocusedItem.SubItems(1).Text = Value
            Else
                lvListView.FocusedItem.SubItems.Insert(1, New System.Windows.Forms.ListViewItem.ListViewSubItem(Nothing, Value))
            End If
        End If
	End Sub

    Private Sub lvListView_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles lvListView.ItemSelectionChanged
        If lvListView.FocusedItem Is Nothing Then
            Exit Sub
        End If
        mnuReadItem.Enabled = True
        mnuWriteItem.Enabled = True
        mnuItemStatus.Enabled = True
        mnuRemoveItem.Enabled = True
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -