Author Topic: TempController - how to modify up/down buttons for SP increase/decrease  (Read 3012 times)

DBTechServ

  • Newbie
  • *
  • Posts: 12
    • View Profile
I am trying to use the up/down buttons on TempController.vb to raise/lower the property "PLCAddressValueSP" value without having to create plc tags and logic for increase and decrease which would then be associated with "PLCAddressClick3" and "PLCAddressClick4" properties. Is there an easy way to do this in the TempControl.vb code?
Maybe by using an inc/dec value set in the properties?


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #1 on: September 18, 2014, 05:42:21 PM »
One way to do it is to handle the MouseDown events for the buttons:
Code: [Select]
    Private Sub TempController1_Button4MouseDown(sender As System.Object, e As System.EventArgs) Handles TempController1.Button4MouseDown
        Dim Value As String
        Try
            Value = ModbusRTUCom1.Read("40001", 1)(0)

            Try
                Value += 1
                ModbusRTUCom1.Write("40001", Value)
            Catch ex As Exception
                MsgBox("Failed to write")
            End Try
        Catch ex As Exception
            MsgBox("Failed to read - " & ex.Message)
        End Try
    End Sub

DBTechServ

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #2 on: September 19, 2014, 07:54:51 AM »
Thanks Archie. I'll give it a try.
I am assuming that I would use my CompactLogix tag reference instead of the ModbusRTUCom1.read as shown in your example.

FYI, your solution for the digital panel meter limits was perfect. Simple paste and run. THANK YOU :)
 

DBTechServ

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #3 on: September 19, 2014, 09:15:47 AM »
with this modified code, I get the 'failed to write' error - (the original code is commented out)

    Private Sub TC_Seal_Button4MouseDown(sender As System.Object, e As System.EventArgs) Handles TC_Seal.Button4MouseDown
        Dim Value As String
        Try
            'Value = ModbusRTUCom1.Read("40001", 1)(0)
            Value = TC_Seal.PLCAddressValueSP
            Try
                'Value += 1
                Value = Value + 1
                'ModbusRTUCom1.Write("40001", Value)
                TC_Seal.PLCAddressValueSP = Value
            Catch ex As Exception
                MsgBox("Failed to write")
            End Try
        Catch ex As Exception
            MsgBox("Failed to read - " & ex.Message)
        End Try
    End Sub

I tried the " value +=1 " first with same result and then commented out to try current version

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #4 on: September 19, 2014, 09:42:22 AM »
Add this to get more details:

Code: [Select]
           Catch ex As Exception
                MsgBox("Failed to write - " & Value & ". " & ex.message)
            End Try

DBTechServ

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #5 on: September 19, 2014, 10:32:03 AM »
The error is a conversion issue -
msg - Conversion from string "HMI_SealTemp" to type 'Double' is not valid


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #6 on: September 19, 2014, 10:34:58 AM »
I completely over looked this. You don't want to get the tag name and try to increment it, but to get the Value:

Value = TC_Seal.ValueSP

DBTechServ

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #7 on: September 19, 2014, 10:54:06 AM »
Ok the display increments on each click but then reverts to original value of TC_Seal.PLCAddressValueSP

this is current code -
       Private Sub TC_Seal_Button4MouseDown(sender As System.Object, e As System.EventArgs) Handles TC_Seal.Button4MouseDown
        Dim Value As String
        Try
            'Value = ModbusRTUCom1.Read("40001", 1)(0)
            Value = TC_Seal.ValueSP
            Try
                'Value += 1
                Value = Value + 1
                'ModbusRTUCom1.Write("40001", Value)
                TC_Seal.ValueSP = Value
            Catch ex As Exception
                'MsgBox("Failed to write")
                MsgBox("Failed to write - " & Value & ". " & ex.Message)
            End Try
        Catch ex As Exception
            MsgBox("Failed to read - " & ex.Message)
        End Try
    End Sub


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #8 on: September 19, 2014, 10:56:31 AM »
    Private Sub TC_Seal_Button4MouseDown(sender As System.Object, e As System.EventArgs) Handles TC_Seal.Button4MouseDown
        Dim Value As String
        Try
            Value = TC_Seal.ValueSP+1
            Try
                EthernetIPForCLXCom1.Write(TC_Seal.PLCAddressValueSP ,Value)
            Catch ex As Exception
                MsgBox("Failed to write - " & Value & ". " & ex.Message)
            End Try
        Catch ex As Exception
            MsgBox("Failed to read - " & ex.Message)
        End Try
    End Sub

DBTechServ

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: TempController - how to modify up/down buttons for SP increase/decrease
« Reply #9 on: September 19, 2014, 11:04:55 AM »
A very big thank you.