Author Topic: Delay between individual addresses (Sequenz)?  (Read 1028 times)

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Delay between individual addresses (Sequenz)?
« on: February 11, 2017, 04:48:27 PM »
Hello,

The "BasicButtonMulti" is already very good :-) but can one insert a delay between the individual addresses in the list?
Or is there another way to incorporate a sequence with delay?
E.g. Key press -> send "1" to address1 -> delay -> send "1" to address2 -> delay -> send "1" to address3 -> etc.

best Regards
Steffen
« Last Edit: February 11, 2017, 05:11:05 PM by sts69 »

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Delay between individual addresses (Sequenz)?
« Reply #1 on: February 11, 2017, 07:14:39 PM »
I am not sure if this will work but for short delays, you might try adding this line just before the Private Sub MomentaryButton_MouseDown:

    Private QueueHoldRelease As New System.Threading.EventWaitHandle(False, Threading.EventResetMode.AutoReset)

-------------

Then inside the same sub, at the very end of the sub and just before the "Next" statement, add this line:

    QueueHoldRelease.WaitOne(5) 'this sets delay to 5 ms and can be changed

You should also add this line to the Private Sub MomentaryButton_MouseUp at the same location.

-------------

Either short or long delays might have odd effects, so if you experience them then remove these new lines.
« Last Edit: February 11, 2017, 07:20:01 PM by Godra »

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Delay between individual addresses (Sequenz)?
« Reply #2 on: February 12, 2017, 11:15:59 AM »
Thanks Godra, but I would have to do something like this:

Code: [Select]
After pressing a key
ModbusRTUCom1.Write("00070", "1")
delay(500ms)
ModbusRTUCom1.Write("00071", "1")
delay(500ms)
ModbusRTUCom1.Write("00072", "1")
delay(500ms)
ModbusRTUCom1.Write("00073", "1")
delay(500ms)
...etc.

This is to switch on the lambs one after the other, since otherwise the inrush current becomes too great.

Best Regards
Steffen

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Delay between individual addresses (Sequenz)?
« Reply #3 on: February 12, 2017, 11:49:05 AM »
Which is pretty much the same. You would still try using QueueHoldRelease variable.

If you are looking to use the BasicButtonMulti control then try the previous suggestion.

If you are looking to use the code then you can just use the standard button control, declare the QueueHoldRelease variable and use it in place of your delay(500ms), which would be QueueHoldRelease.WaitOne(500).

I am still not sure if this is going to work properly.

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Delay between individual addresses (Sequenz)?
« Reply #4 on: February 12, 2017, 11:52:54 AM »
Ok, I'll try that :-)

Godra

  • Hero Member
  • *****
  • Posts: 1438
    • View Profile
Re: Delay between individual addresses (Sequenz)?
« Reply #5 on: February 13, 2017, 09:34:28 AM »
It might be better if you don't modify the BasicButtonMulti control, since this modification would be applicable to all instances of this control that you might use in your solution.

The task of switching the lamps in sequence seems to be simple and could be achieved with a standard button and a timer control (with timer's interval set to 500 and Enabled property set as False), the code would be similar to this:

Code: [Select]
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Enabled = True
    End Sub

    Private i As Integer
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim st() As String = {"00070", "00071", "00072", "00073", "00074"}
        ModbusRTUCom1.Write(st(i), "1")
        i += 1
        If i = 4 Then '<-- This number is = (number of strings defined for st()) - 1
            i = 0
            Timer1.Enabled = False
        End If
    End Sub

The Write function has its own time out so don't be surprised if at any time you get some odd behavior.

sts69

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Delay between individual addresses (Sequenz)?
« Reply #6 on: February 15, 2017, 05:01:02 PM »
Thanks Godra,
With the Button I thought synonymous already, that would not be so good.
Meanwhile I have tested with DataSubscriber:

Code: [Select]
Private Sub DataSubscriber16_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber16.DataChanged
        'Zum Einschalten einer Gruppe. Coil 00080 (DO15) einlesen und dann "1" schreiben. Mit Pausen.
        Dim CurrentValue As String = ModbusRTUCom1.Read("00080")
        If CurrentValue = "True" Then
            ModbusRTUCom1.Write("00065", "1")
            ModbusRTUCom1.Write("00066", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00067", "1")
            ModbusRTUCom1.Write("00068", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00069", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00070", "1")
            ModbusRTUCom1.Write("00071", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00072", "1")
            ModbusRTUCom1.Write("00073", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00074", "1")
            ModbusRTUCom1.Write("00075", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00076", "1")
            ModbusRTUCom1.Write("00077", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00078", "1")
            Threading.Thread.Sleep(500) ' 0,5 sec warten
            ModbusRTUCom1.Write("00080", "0")
        End If
    End Sub

This has also worked with the BasicButton and is suitable for my purposes well.
I will also try your suggested code

Steffen
« Last Edit: February 15, 2017, 05:21:56 PM by sts69 »