General Category > Additional Components
BasicButton with context menu (multiple address access)
(1/1)
Godra:
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.
des.subhasish:
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:
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: ---#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
--- End code ---
Godra:
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: --- 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
--- End code ---
It should be something like this:
--- Code: --- 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
--- End code ---
If this doesn't work then check the following link for "String.Equals" examples:
https://stackoverflow.com/questions/900927/comparing-strings-in-vb-net
des.subhasish:
Thanks a lot for the reply. It works like a charm.
Navigation
[0] Message Index
Go to full version