Pages

Thursday 9 July 2015

INTEGRATED EMBEDDED SYSTEM WITH Vb.Net- Chapter 3



FT245 RELAY CONTROLLER








relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate a switch, but other operating principles are also used, such as solid-state relays. Relays are used where it is necessary to control a circuit by a low-power signal (with complete electrical isolation between control and controlled circuits), or where several circuits must be controlled by one signal. The first relays were used in long distance telegraph circuits as amplifiers: they repeated the signal coming in from one circuit and re-transmitted it on another circuit. Relays were used extensively in telephone exchanges and early computers to perform logical operations.

Here we are making use of 4 channel relay to controlling it, The following picture show the design part of it, in this we have used one combo box for reading com port and open button to open the selected port, and DATA text box, this is for entering manually which relay should turn on suppose if you enter ‘ff’ it will turn on relay1.


The complete source code for controlling 4/8 channel relay.
Imports System.Data.SqlClient
Imports System.Net.Sockets
Imports System.Text

Public Class Form1

Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label11.Text = "Hi" + " " + Form2.TextBox1.Text + " , " + "Welcome you to PSA"
        user = Form2.TextBox1.Text


        total = 0
        k = 0
        If SerialPort1.IsOpen Then
            SerialPort1.Close()
        End If
        Try
            With SerialPort1
                .PortName = "COM5"
                .BaudRate = 9600
                .Parity = IO.Ports.Parity.None
                .DataBits = 8
                .StopBits = IO.Ports.StopBits.One
                .Handshake = IO.Ports.Handshake.None
            End With
            SerialPort1.Open()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try


    End Sub         


       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                      If SerialPort1.IsOpen Then
            SerialPort1.Close()
        End If
            SerialPort1.Open()


              Button2.Enabled = true
              Button3.Enabled = true
              Button4.Enabled = true
              Button5.Enabled = true
              Button6.Enabled = true
              Button7.Enabled = true
              Button8.Enabled = true
              Button9.Enabled = true
              Button10.Enabled = true
       End Sub


Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button1.Click       
         
SerialPort1.WriteLine(TextBox1.Text);
       
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button1.Click       
            SerialPort1.WriteLine ("02");
       
End Sub

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button1.Click       
           SerialPort1.WriteLine ("00");
        End Sub


Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button1.Click 
          SerialPort1.WriteLine ("08");
        End Sub


Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button1.Click       
            SerialPort1.WriteLine ("00");
        End Sub


Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button1.Click       
            SerialPort1.WriteLine ("20");
        End Sub


Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button1.Click       
        SerialPort1.WriteLine ("00");
        End Sub



Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button1.Click
       
SerialPort1.WriteLine ("80");
        End Sub


Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button1.Click       
SerialPort1.WriteLine ("00");
        End Sub

    End Class