Hi
I am learning VB and tried to write a code to switch on the relay and switch off the relay using com port. Every thing went perfect and now i am stuck up in a event, by clicking OFF button the relay should go on/off every 3 sec, until i press ON button.
The sample code is
[CODE=vb]Public Sub RELAY_Timer_Cli ck(Index1 As Integer)
RELAY_Timer(Ind ex1).Enabled = False
If RELAY_Timer(Ind ex1).Caption = "ON" Then
RELAY_Timer(Ind ex1).Caption = "OFF"
RELAY_Timer(Ind ex1).Enabled = True
Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
Form1.MSComm1.O utput = Chr$(Index1) 'Turn Relay Off
Else
RELAY_Timer(Ind ex1).Caption = "ON"
RELAY_Timer(Ind ex1).Enabled = True
While True
Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
Form1.MSComm1.O utput = Chr$(Index1 + 8) 'Turn Relay Off
Sleep (3000)
Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
Form1.MSComm1.O utput = Chr$(Index1)
Sleep (3000)
If RELAY_Timer(Ind ex1).Caption = "ON" Then Exit Sub
Wend
End If
Form1.GetData
Form1.Read_All_ Click
End Sub[/CODE]
Please help in resolving the code
I am learning VB and tried to write a code to switch on the relay and switch off the relay using com port. Every thing went perfect and now i am stuck up in a event, by clicking OFF button the relay should go on/off every 3 sec, until i press ON button.
The sample code is
[CODE=vb]Public Sub RELAY_Timer_Cli ck(Index1 As Integer)
RELAY_Timer(Ind ex1).Enabled = False
If RELAY_Timer(Ind ex1).Caption = "ON" Then
RELAY_Timer(Ind ex1).Caption = "OFF"
RELAY_Timer(Ind ex1).Enabled = True
Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
Form1.MSComm1.O utput = Chr$(Index1) 'Turn Relay Off
Else
RELAY_Timer(Ind ex1).Caption = "ON"
RELAY_Timer(Ind ex1).Enabled = True
While True
Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
Form1.MSComm1.O utput = Chr$(Index1 + 8) 'Turn Relay Off
Sleep (3000)
Form1.MSComm1.O utput = Chr$(254) 'Enter Command Mode
Form1.MSComm1.O utput = Chr$(Index1)
Sleep (3000)
If RELAY_Timer(Ind ex1).Caption = "ON" Then Exit Sub
Wend
End If
Form1.GetData
Form1.Read_All_ Click
End Sub[/CODE]
Please help in resolving the code
Comment