Author Topic: Timer reset  (Read 1187 times)

mboisse@acp99.com

  • Newbie
  • *
  • Posts: 2
    • View Profile
Timer reset
« on: August 14, 2018, 11:16:55 AM »

I would like to now if it possible to reset a timer to 0 when I arrived at a certain number let say that timer2 is set to timer2 = 60
 then heureminutes = heeminute + 1 and the timer2 reset to 0 to made a another cylce




ublic Class MainForm
    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Dim TempMinutes As Integer = 0
    Dim HeureMinutes As Integer = 0
    Dim jourMinutes As Integer = 0
    Dim seconderh As Integer = 0
    Dim minutesrh As Integer = 0
    Dim heuresrh As Integer = 0
    Dim joursrh As Integer = 0
    Dim minjag As Integer = 0
    Dim secjag As Integer = 0
    Dim hrjag As Integer = 0
    Dim jourjag As Integer = 0
    Private NotFirstShow As Boolean

    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    '***************************************************************
    '* .NET does not close hidden forms, so do it here
    '* to make sure forms are disposed and drivers close
    '***************************************************************
    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim index As Integer
        While index < My.Application.OpenForms.Count
            If My.Application.OpenForms(index) IsNot Me Then
                My.Application.OpenForms(index).Close()
            End If
            index += 1
        End While
    End Sub
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles TimerPoly1M.Tick
        If DataSubscriber1.Value <= 10 Then
            TempMinutes = TempMinutes + 1   '* compteur de seconde quand la 18 est arreter
            Label3.Text = TempMinutes        '* compteur de seconde quand la 18 est arreter
        End If
    End Sub

    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles TimerPoly2H.Tick
        If TempMinutes = 60 Then
            HeureMinutes = HeureMinutes + 1 '* Poly 18
            Label4.Text = HeureMinutes
        End If
    End Sub
    Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timerpoly3J.Tick
        If HeureMinutes = 24 Then
            jourMinutes = jourMinutes + 1 '* Poly 18
            Label5.Text = jourMinutes
        End If
    End Sub

    Private Sub secondesrh_Tick(sender As Object, e As EventArgs) Handles secondesrh.Tick
        If DataSubscriber2.Value <= 0 Then
            seconderh = seconderh + 1
            Label10.Text = seconderh

        End If
    End Sub

bachphi

  • Hero Member
  • *****
  • Posts: 671
    • View Profile
Re: Timer reset
« Reply #1 on: August 14, 2018, 03:37:44 PM »
try timer.stop then timer.start
===================================================
This is NOT alt.read.my.mind.
No such thing is sh^t-for-brains unless you are posting to alt.read.my.mind.
===================================================

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Timer reset
« Reply #2 on: August 14, 2018, 11:39:28 PM »
You should try to explain the whole process since I am not really sure what your DataSubscriber1.Value and DataSubscriber2.Value are (but they do seem to control all the updating somehow individually).

You should either use only 1 timer and update all the variables and labels within its tick event or use events of your DataSubscribers.


mboisse@acp99.com

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Timer reset
« Reply #3 on: August 15, 2018, 08:16:57 AM »
OK

The DataSubscriber1.Value <=10 is to check the speed of one machine , if the speed is lower then 10  the TempMinutes start to count ( seconde ) when it arrived at 60 the variable HeureMinutes got + 1 and TempMinutes must reset to 0 and we got the same process for hrs and day , the ress of it is for 3 machine


TY for your help

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Timer reset
« Reply #4 on: August 16, 2018, 12:05:21 AM »
You could try using the DataReturned event of your DataSubscriber1 and the HourMeter control from this topic:

https://www.advancedhmi.com/forum/index.php?topic=1295.msg12468#msg12468

The HourMeter control would replace all your labels.

The code would be similar to this:

Code: [Select]
    Private Sub DataSubscriber1_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataReturned
        If e.Values(0) <= 10 Then
            '* Start the HourMeter
            Me.HourMeter1._Stop = False
            Me.HourMeter1._Start = True
        Else
            '* Stop the HourMeter
            Me.HourMeter1._Start = False
            Me.HourMeter1._Stop = True
        End If
    End Sub

You would need to add the code for any other conditions.
« Last Edit: August 16, 2018, 12:15:09 AM by Godra »