Author Topic: BasicButton with context menu (multiple address access)  (Read 10451 times)

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
BasicButton with context menu (multiple address access)
« on: December 04, 2017, 10:20:40 PM »

This control should be used by those who can understand its functionality, generally for testing/troubleshooting purposes.
If not set properly then it could possibly create a potential hazard in a production environment, so be careful of whether to use it at all.


Could be used for quick writes to any address from its collection, which is populated by the designer/user.

The context menu, which pops up on the right-click of the mouse, will have the current address selected.
It can also show/hide the OutputType submenu to allow for its quick change (and will have the current OutputType selected).
Every time the WriteValue output type is selected then a new form will pop up offering to change the current ValueToWrite.

There is also a property to display the current value of the selected PLC address as a text on the button (which turns this button into a sort of BasicLabel).

Do report any bugs if found.
« Last Edit: December 10, 2017, 08:37:23 PM by Godra »

des.subhasish

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: BasicButton with context menu (multiple address access)
« Reply #1 on: May 05, 2023, 09:10:29 AM »
Greetings!!! At the outset thanks for the support. I want to change the options for output types. I only need "Momentary Set" and "False", these two output types. How to do that?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: BasicButton with context menu (multiple address access)
« Reply #2 on: May 05, 2023, 10:36:04 AM »
You cannot really remove these options since they are all a part of the built-in "OutputType".

There is only one thing that I can think of - remove or comment out the actions of the options you don't want found here:

Code: [Select]
#Region "Events"

    '****************************
    '* Event - Mouse Down
    '****************************
    Private Sub MomentaryButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        MouseIsDown = True
        HoldTimeMet = False

        If e.Button = Windows.Forms.MouseButtons.Left Then
            If (Not String.IsNullOrEmpty(Me.m_PLCAddressClick)) AndAlso m_ComComponent IsNot Nothing Then
                Try
                    Select Case m_OutputType
                        Case MfgControl.AdvancedHMI.Controls.OutputType.MomentarySet
                            m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {"1"})
                            If m_MinimumHoldTime > 0 Then MinHoldTimer.Enabled = True
                            If m_MaximumHoldTime > 0 Then MaxHoldTimer.Enabled = True
                        Case MfgControl.AdvancedHMI.Controls.OutputType.MomentaryReset
                            m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {"0"})
                            If m_MinimumHoldTime > 0 Then MinHoldTimer.Enabled = True
                            If m_MaximumHoldTime > 0 Then MaxHoldTimer.Enabled = True
                        Case MfgControl.AdvancedHMI.Controls.OutputType.SetTrue : m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {"1"})
                        Case MfgControl.AdvancedHMI.Controls.OutputType.SetFalse : m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {"0"})
                        Case MfgControl.AdvancedHMI.Controls.OutputType.Toggle
                            Dim CurrentValue As Boolean
                            CurrentValue = m_ComComponent.Read(m_PLCAddressClick, 1)(0)
                            If CurrentValue Then
                                m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {"0"})
                            Else
                                m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {"1"})
                            End If
                        Case MfgControl.AdvancedHMI.Controls.OutputType.WriteValue
                            m_ComComponent.BeginWrite(m_PLCAddressClick, 1, New String() {m_ValueToWrite})
                    End Select

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: BasicButton with context menu (multiple address access)
« Reply #3 on: May 05, 2023, 11:07:23 AM »
There is another thing that you could possibly do which is to filter out options by comparing the string "typ" to "MomentarySet" and "SetFalse" in this part of code:

Code: [Select]
        ElseIf e.Button = Windows.Forms.MouseButtons.Right AndAlso Me._itemsPLCAddressClick.Count > 0 Then
            Me.ContextMenuStrip = Me.context

            If Not Me.flagContextSet Then
                If m_QuickAccessOutputType Then
                    Dim names() As String = [Enum].GetNames(GetType(MfgControl.AdvancedHMI.Controls.OutputType))
                    For Each typ As String In names
                        contextSubMenu.DropDownItems.Add(typ, Nothing, AddressOf Me.contextSubMenu_ItemClicked)
                    Next
                    context.Items.Add(contextSubMenu)
                End If

                For Each str As String In Me._itemsPLCAddressClick
                    Dim menuItem = Me.context.Items.Add(str)
                Next
                Me.flagContextSet = True
            End If

It should be something like this:
Code: [Select]
                If m_QuickAccessOutputType Then
                    Dim names() As String = [Enum].GetNames(GetType(MfgControl.AdvancedHMI.Controls.OutputType))
                    For Each typ As String In names
                        If typ = "MomentarySet" OrElse typ = "SetFalse" Then
                            contextSubMenu.DropDownItems.Add(typ, Nothing, AddressOf Me.contextSubMenu_ItemClicked)
                        End If
                    Next
                    context.Items.Add(contextSubMenu)
                End If

If this doesn't work then check the following link for "String.Equals" examples:

   https://stackoverflow.com/questions/900927/comparing-strings-in-vb-net
« Last Edit: May 05, 2023, 06:05:52 PM by Godra »

des.subhasish

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: BasicButton with context menu (multiple address access)
« Reply #4 on: May 06, 2023, 01:20:32 AM »
Thanks a lot for the reply. It works like a charm.
« Last Edit: May 06, 2023, 01:27:02 AM by des.subhasish »