|
-
Aug 7th, 2008, 09:58 AM
#1
Thread Starter
New Member
[2008] Multiple On/Off Timers
Hi Everyone.
I am putting together a relay timing program that is going to control 16 different relays, with at least 2 (maybe 3) on/off points each daily.
This program is going to run 24/7. Each on/off point is going to be user selected by the DateTimePicker (time only. no date). I want to set the timer intervals that trigger my relay on/off commands to only fire when needed, if possible. That way it dosent tie up the network.
I started making a program but with 32+ timers it was getting a little confusing. Can this all be done with only a few timers? Also the network was very busy. and i could not override the relay unless I disabled the timer first because it kept sending the on or off command at 1 second intervals.
I did a search but couldnt find anything that was very helpful to me.
If you cant tell, I am a noob. Any help/info would be much appreciated.
-Steve
-
Aug 7th, 2008, 10:24 AM
#2
Re: [2008] Multiple On/Off Timers
Have a single timer that fires every minute (more or less depending on what granularity you need) and in the fire event, determine what relays need to be turned on/off.
-
Aug 7th, 2008, 10:29 AM
#3
Re: [2008] Multiple On/Off Timers
what resolution is needed for the timers? if the resolution is not small (ms.) then you could use one timer, with a three arrays. arrayID would contain the relay id, arrayDT would contain time of next state change and arrayONOFF would contain off/on.
edit - btw - how are you controlling the relays?
Last edited by dbasnett; Aug 7th, 2008 at 10:40 AM.
-
Aug 7th, 2008, 10:31 AM
#4
Re: [2008] Multiple On/Off Timers
you could use timespans, then you'd only need 1 timer
vb.net Code:
Public Class Form1
Dim t1 As New TimeSpan(0, 0, 0)
Dim t2 As New TimeSpan(8, 0, 0)
Dim t3 As New TimeSpan(16, 0, 0)
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim timeNow As New TimeSpan(Now.Hour, Now.Minute, Now.Second)
If timeNow > t1 And timeNow < t2 Then
'do something
ElseIf timeNow > t2 And timeNow < t3 Then
'do something
ElseIf timeNow > t3 And timeNow < New TimeSpan(24, 0, 0) Then
'do something
End If
End Sub
end class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Aug 7th, 2008, 10:55 AM
#5
Re: [2008] Multiple On/Off Timers
Code:
Const numRelay As Integer = 32
Dim relayID(numRelay - 1) As String 'relay id's
Dim dateIsValid(numRelay - 1) As Boolean 'set to true when time is set, cleared when acted on
Dim dateNextChange(numRelay - 1) As DateTime
Dim OnOff(numRelay - 1) As Boolean
relayID(0) = "Relay1" : dateIsValid(0) = True : dateNextChange(0) = DateTime.Now : OnOff(0) = True
For x As Integer = 0 To numRelay - 1
If dateIsValid(x) Then
If dateNextChange(x).ToString("HH:mm") = DateTime.Now.ToString("HH:mm") Then
dateIsValid(x) = False
End If
End If
Next
-
Aug 7th, 2008, 02:36 PM
#6
Thread Starter
New Member
Re: [2008] Multiple On/Off Timers
Thanks for the quick responses everyone.
Ok, after speaking with the customer in detail, I think I've got everything figured out on what they want.
This is what I have so far. It's basically just all of the main funtions of the form. You can get an idea of how these relays are controlled.
NOTE: keep in mind that this is very new to me so it may look a bit primative.
Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
NcdProXR1.OpenPort() 'Opens Port
NcdProXR1.SelectBank(1) 'Selects Bank 1
NcdProXR2.OpenPort()
NcdProXR2.SelectBank(1)
NcdProXR3.OpenPort()
NcdProXR3.SelectBank(1)
NcdProXR4.OpenPort()
NcdProXR4.SelectBank(1)
NcdProXR5.OpenPort()
NcdProXR5.SelectBank(1)
NcdProXR6.OpenPort()
NcdProXR6.SelectBank(1)
NcdProXR7.OpenPort()
NcdProXR7.SelectBank(1)
NcdProXR8.OpenPort()
NcdProXR8.SelectBank(1)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim t As Date
t = Date.Now
If t > DateTimePicker1.Value Then
NcdProXR1.TurnOffAllRelays() 'turns off all relays on board 1
NcdProXR2.TurnOffAllRelays()
NcdProXR3.TurnOffAllRelays()
NcdProXR4.TurnOffAllRelays()
NcdProXR5.TurnOffAllRelays()
NcdProXR6.TurnOffAllRelays()
NcdProXR7.TurnOffAllRelays()
NcdProXR8.TurnOffAllRelays()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
NcdProXR1.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR2.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR3.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR4.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR5.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR6.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR7.TurnOnRelay(2) 'turns on relay number 2 (HWH)
NcdProXR8.TurnOnRelay(2) 'turns on relay number 2 (HWH)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
NcdProXR1.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR2.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR3.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR4.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR5.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR6.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR7.TurnOffRelay(2) 'turns off relay number 2 (HWH)
NcdProXR8.TurnOffRelay(2) 'turns off relay number 2 (HWH)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
NcdProXR1.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR2.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR3.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR4.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR5.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR6.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR7.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
NcdProXR8.TurnOnRelay(1) 'turns on relay number 1 (HVAC)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
NcdProXR1.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR2.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR3.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR4.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR5.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR6.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR7.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
NcdProXR8.TurnOffRelay(1) 'turns off relay number 1 (HVAC)
End Sub
End Class
Here is a picture of the layout:

It looks like i will need 5 timers if I do it the way I was going to. 2 on/off controls for the HWH and 2 on/off triggers for the HVAC. And one for an "all off" date. I will just need to select (check) each building to be controlled by the corrosponding timer.
I did the code for the "all off" date to show how I was engauging the relays. My problem with how I did it is that it constantly sends a turn off relay command on every tick a long as it's activated. The timers would confilict with eachother.
Sorry for the confusion before.
-Steve
I guess I just would like to know the best way to do this. I'm open to any other suggestions as well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|