|
-
Sep 11th, 2008, 12:38 PM
#1
Thread Starter
New Member
[2008] COM ports, timers and relays HELP!
I am putting together a relay timing program that is going to control 16 different relays, with at least 2 on/off points each daily.
This program is going to run 24/7. Each on/off point is going to be user selected by a 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 because when you try to manually activate the relay with a on/off button, the relay command associated with the timer is still active and firing every timer interval, thus making the button useless. It also ties up the network with "useless" traffic.
I started making a program but with 32+ timers it was getting a little confusing and the network was very busy. Can this be done with only a couple of timers? ...And if so can they only fire when needed so I can have an On/Off button option?
BTW, I'm shooting for a timer interval of 1-2 seconds (5 seconds if need be)
Here is a basic timing program I made with 2 on/off timers and an on and an off button
If someone can show me this in detail (and i mean in great detail because what you see below is nearly the extent of my VB skills...I mean like edit a copy of my code and post it. lol ) I would greatly appreciate it.
Code:
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim t As Date 'timer 1 ON/OFF
t = Date.Now
If t > DateTimePicker1.Value And t < DateTimePicker2.Value Then
TurnOnRelay()
Else
TurnOffRelay()
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim t As Date 'timer 2 ON/OFF
t = Date.Now
If t > DateTimePicker4.Value And t < DateTimePicker3.Value Then
TurnOnRelay()
Else
TurnOffRelay()
End If
End Sub
Private Sub TurnOnRelay() 'Relay 1 ON command
Dim data(0 To 3) As Byte
data(0) = 254
data(1) = 108
data(2) = 1
SerialPort1.Write(data, 0, 3)
End Sub
Private Sub TurnOffRelay() 'Relay 1 OFF command
Dim data(0 To 3) As Byte
data(0) = 254
data(1) = 100
data(2) = 1
SerialPort1.Write(data, 0, 3)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TurnOnRelay() ' On Button
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TurnOffRelay() 'Off Button
End Sub
End Class
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
|