Author Topic: Unable to auto write boolean to force bit in PLC.  (Read 2051 times)

Padex

  • Newbie
  • *
  • Posts: 11
    • View Profile
Unable to auto write boolean to force bit in PLC.
« on: January 18, 2017, 04:36:05 AM »

Hi Guys,

Another help needed, I'm trying to do set auto toggle button = true (If ResultLabel.Text = 10) to force bit in PLC tag, but did not function as what I need. Still need perform manual click. I'm blurr...Pls help...Me TQ


Below is Vb.. I just try to created..


Private Sub PurgeBsa1_OutputType(sender As Object, e As EventArgs) Handles PurgeBsa1.TextChanged, PurgeBsa2.TextChanged

        Dim PurgeBsa1 = False
        Dim PurgeBsa2 = False

        Try
            ResultLabel.Text = 0

        Catch ex As Exception
        End Try
        If ResultLabel.Text = 10 Then
            PurgeBsa1 = True
            PurgeBsa2 = True
        End If
        BSA1.Write("_EXT_PC_Purge_On", CInt(ResultLabel.Text))
        BSA2.Write("_EXT_PC_Purge_On", CInt(ResultLabel.Text))
    End Sub

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #1 on: January 18, 2017, 07:08:27 PM »
You need to post more information and pictures of your MainForm in Design Mode.

Padex

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #2 on: January 18, 2017, 07:49:24 PM »
This is details:

I made counter in PLC to count qty balance to go. For example:
1) TextBox1.Text = 1000 pcs
2) ResultLabel.Text = (CInt(TextBox1.Text) + CInt(TotalLabel.Text)) - (CInt(Built1Label.Text) + CInt(Built2Label.Text))
3) FYI.. Built1Lable.Text and Built2Label.Text is value read counter from PLC.

So from step 1,2,3 above. I need to do automate function to stop the machine if ResultLabel.Text = 10 to force as True. Mean to ON tag bit I'm assign.

Below is vb I modify just now... I test run but not function.

 Private Sub BasicLabel1_ValueChanged(sender As Object, e As EventArgs) Handles Built1Label.ValueChanged, Built2Label.ValueChanged, PurgeBsa1.TextChanged, PurgeBsa2.TextChanged
        Try
            ResultLabel.Text = (CInt(TextBox1.Text) + CInt(TotalLabel.Text)) - (CInt(Built1Label.Text) + CInt(Built2Label.Text))
        Catch ex As Exception
        End Try

        Try
            If Not ResultLabel.Text = CInt(10) Then
                PurgeBsa1.OutputType = AdvancedHMI.Controls.OutputType.SetFalse
                PurgeBsa2.OutputType = AdvancedHMI.Controls.OutputType.SetFalse
            End If

            If ResultLabel.Text = CInt(10) Then
                PurgeBsa1.OutputType = AdvancedHMI.Controls.OutputType.SetTrue
                PurgeBsa2.OutputType = AdvancedHMI.Controls.OutputType.SetTrue
            End If
        Catch ex As Exception
        End Try
    End Sub


Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #3 on: January 18, 2017, 08:11:57 PM »
From your first post, the buttons seem to be functional so your code should be similar to this:

Code: [Select]
    Private Sub BasicLabel1_ValueChanged(sender As Object, e As EventArgs) Handles Built1Label.ValueChanged, Built2Label.ValueChanged, TextBox1.TextChanged, TotalLabel.TextChanged
        Try
            ResultLabel.Text = (CInt(TextBox1.Text) + CInt(TotalLabel.Text)) - (CInt(Built1Label.Text) + CInt(Built2Label.Text))
            If CInt(ResultLabel.Text) = 10 Then
               PurgeBSA1.PerformClick()
               PurgeBSA2.PerformClick()
            End If
        Catch ex As Exception
        End Try
    End Sub

These 2 lines of code:

               PurgeBSA1.PerformClick()
               PurgeBSA2.PerformClick()

could possibly be replaced with code that you have in their Click events (or if these buttons are BasicButton controls then the driver .Write commands for the addresses you put in the PLCAddressClick property).
« Last Edit: January 18, 2017, 08:24:12 PM by Godra »

Padex

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #4 on: January 18, 2017, 08:58:16 PM »
Mean do like this?


Code: [Select]
If CInt(ResultLabel.Text) = 10 Then
                PurgeBsa1.PLCAddressClick = AdvancedHMI.Controls.OutputType.Toggle
                PurgeBsa2.PLCAddressClick = AdvancedHMI.Controls.OutputType.Toggle
            End If

Testing already but not working... If assign .PerformClick() the form will be hanging and require to end task the program.

I have no idea now...
« Last Edit: January 18, 2017, 09:02:32 PM by Padex »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #5 on: January 18, 2017, 09:07:17 PM »
No, it would be more like what you had in the first post:

Code: [Select]
             If CInt(ResultLabel.Text) = 10 Then
                BSA1.Write("_EXT_PC_Purge_On", True)
                BSA2.Write("_EXT_PC_Purge_On", True)
            End If

Padex

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #6 on: January 18, 2017, 10:40:32 PM »
Fyi info, currently the code is function as what I need. Thanks for your help Godra...

This I share the code as below:

Code: [Select]
Private Sub BasicLabel1_ValueChanged(sender As Object, e As EventArgs) Handles Built1Label.ValueChanged, Built2Label.ValueChanged, TextBox1.TextChanged, TotalLabel.TextChanged
        Try
            ResultLabel.Text = (CInt(TextBox1.Text) + CInt(TotalLabel.Text)) - (CInt(Built1Label.Text) + CInt(Built2Label.Text))
            If CInt(ResultLabel.Text) = 10 Then
                BSA1.Write("_EXT_PC_Purge_On", CInt(True))
                BSA2.Write("_EXT_PC_Purge_On", CInt(True))

            End If
        Catch ex As Exception
        End Try

    End Sub

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Unable to auto write boolean to force bit in PLC.
« Reply #7 on: January 18, 2017, 11:32:05 PM »
Good to hear that it works.

In your code, you could also try replacing CInt(True) with 1 or "1".