Pages

Thursday, 5 March 2015

Integrating C#.NET with Embedded System:Chapter-6


FT245 RELAY CONTROLLER 

 Visit  http://researchdesignlab.com/usb-4-channel-relay-board.html to buy 4-channel relay  and visit http://researchdesignlab.com/usb-8-channel-relay-board.htmlto buy 8-channel relay.

A 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.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;



namespace ft245rlAPP

{

publicpartialclassForm1 : Form

    {

CommManager comMangr=newCommManager();

public Form1()

        {

            InitializeComponent();

        }



privatevoid Form1_Load(object sender, EventArgs e)

        {

try {

                     comMangr.SetPortNameValues(comPortCmb);





                     comMangr.BaudRate = "9600";

                     comMangr.DataBits = "8";

                     comMangr.Parity = "None";

                     //comMangr.DisplayWindow = terminalRichTextBox1

                     comPortCmb.SelectedIndex = 0;

                     comMangr.PortName = comPortCmb.Items[comPortCmb.SelectedIndex].ToString();

                     comMangr.StopBits = "One";

                     //comMangr.SignalStrengthBar = SigStrProgressBar1
                  // comMangr.SignalStrengthLbl = signaStrDb

                     comMangr.CurrentTransmissionType = CommManager.TransmissionType.Hex;

                     System.Diagnostics.Process.Start("C:\\\\ft245RL_Init.exe");



                     System.Threading.Thread.Sleep(5000);





              } catch (Exception ex) {

                     MessageBox.Show(ex.Message);



              }

              Button2.Enabled = false;

              Button3.Enabled = false;

              Button4.Enabled = false;

              Button5.Enabled = false;

              Button6.Enabled = false;

              Button7.Enabled = false;

              Button8.Enabled = false;

              Button9.Enabled = false;

              Button10.Enabled = false;





       }



       privatevoid Button1_Click(System.Object sender, System.EventArgs e)

       {

              comMangr.OpenPort();

              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;

       }



privatevoid Button1_Click_1(object sender, EventArgs e)

        {

            comMangr.OpenPort();

              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;

        }


privatevoid Button2_Click(object sender, EventArgs e)

        {

            comMangr.WriteData(TextBox1.Text);

        }



privatevoid Button3_Click(object sender, EventArgs e)

        {

            comMangr.WriteData("02");

        }



privatevoid Button4_Click(object sender, EventArgs e)

        {

            comMangr.WriteData("00");

        }



privatevoid Button6_Click(object sender, EventArgs e)

        {

            comMangr.WriteData("08");

        }



privatevoid Button5_Click(object sender, EventArgs e)

        {

            comMangr.WriteData("00");

        }



privatevoid Button10_Click(object sender, EventArgs e)

        {

            comMangr.WriteData("20");

        }



privatevoid Button9_Click(object sender, EventArgs e)

        {

        comMangr.WriteData("00");

        }



privatevoid Button8_Click(object sender, EventArgs e)

        {

            comMangr.WriteData("80");

        }



privatevoid Button7_Click(object sender, EventArgs e)

        {

        comMangr.WriteData("00");

        }



        }

    }

And create same commanger class as we discussed in RFID DATA READ FROM SERIAL PORT SECTION.


GSM INTERFACE

 


There are many different kinds of applications SMS applications in the market today, and many others are being developed. Applications in which SMS messaging can be utilized are virtually unlimited. Some common examples of these are given below:
 
  • Person-to-person text messaging is the most commonly used SMS application, and it is what the SMS technology was originally designed for.
  • Many content providers make use of SMS text messages to send information such as news, weather report, and financial data to their subscribers.
  • SMS messages can carry binary data, and so SMS can be used as the transport medium of wireless downloads. Objects such as ringtones, wallpapers, pictures, and operator logos can be encoded in SMS messages.
  • SMS is a very suitable technology for delivering alerts and notifications of important events.
  • SMS messaging can be used as a marketing tool.
In general, there are two ways to send SMS messages from a computer / PC to a mobile phone:
 
  1. Connect a mobile phone or GSM/GPRS modem to a computer / PC. Then use the computer / PC and AT commands to instruct the mobile phone or GSM/GPRS modem to send SMS messages.
  2.  Connect the computer / PC to the SMS center (SMSC) or SMS gateway of a wireless carrier or SMS service provider. Then send SMS messages using a protocol / interface supported by the SMSC or SMS gateway 

 

AT Commands

AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. Every command line starts with "AT" or "at". That's why modem commands are called AT commands. There are two types of AT commands:
  1.     Basic commands are AT commands that do not start with a "+". For example, D (Dial), A (Answer), H (Hook control), and O (Return to online data state) are the basic commands.
  2. Extended commands are AT commands that start with a "+". All GSM AT commands are extended commands. For example, +CMGS (Send SMS message), +CMGL (List SMS messages), and +CMGR (Read SMS messages) are extended commands

The FORM DESIGN as show below, Here we using combo box for port selection  and textbox for entering mobile number to send sms,and message field to type message and send button.

The complete code as given below, Here we have to create two class 1)sms , 2)program.


The class sms will set all pre-requirements in order to send sms,and port values and program class will load the forms and this will initiate the application.

Form1.cs:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO.Ports;



namespace SendSMS

{

publicpartialclassForm1 : Form

    {

public Form1()

        {

            InitializeComponent();

            loadPorts();

        }



privatevoid btnSend_Click(object sender, EventArgs e)

        {

SMS sm = newSMS(cboPorts.Text);

            sm.Opens();

            sm.sendSMS(txtPhone.Text, txtMessage.Text);

            sm.Closes();

MessageBox.Show("Message Sent!");

        }

privatevoid loadPorts()

        {

string[] ports = SerialPort.GetPortNames();

foreach (string port in ports)

            {

                cboPorts.Items.Add(port);

            }





        }

    }

}



Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Windows.Forms;

namespace SendSMS

{

staticclassProgram

    {

///<summary>

/// The main entry point for the application.

///</summary>

        [STAThread]

staticvoid Main()

        {

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(newForm1());

        }

    }

}

Sms.cs
using System;

using System.Collections.Generic;

using System.Text;

using System.Threading;

using System.IO.Ports;

using System.Windows.Forms;

namespace SendSMS

{

classSMS

    {

SerialPort serialPort;

public SMS(string comPort)

        {

this.serialPort = newSerialPort();

this.serialPort.PortName = comPort;

this.serialPort.BaudRate = 9600;

this.serialPort.Parity = Parity.None;

this.serialPort.DataBits = 8;

this.serialPort.StopBits = StopBits.One;

this.serialPort.Handshake = Handshake.RequestToSend;

this.serialPort.DtrEnable = true;

this.serialPort.RtsEnable = true;

this.serialPort.NewLine = System.Environment.NewLine;

        }

publicbool sendSMS(string cellNo, string sms)

        {

string messages = null;

            messages = sms;

if (this.serialPort.IsOpen == true)

            {

try

                {

this.serialPort.WriteLine("AT" + (char)(13));

Thread.Sleep(4);

this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));

Thread.Sleep(5);

this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");

Thread.Sleep(10);

this.serialPort.WriteLine(">" + messages + (char)(26));

                }

catch (Exception ex)

                {

MessageBox.Show(ex.Source);

                }

returntrue;

            }

else

returnfalse;

        }





publicvoid Opens()

        {

if (this.serialPort.IsOpen == false)

            {

this.serialPort.Open();

            }

        }



publicvoid Closes()

        {

if (this.serialPort.IsOpen == true)

            {

this.serialPort.Close();

            }

        }

    }

}
 



 




 

 


Wednesday, 4 March 2015

ATMEGA Mini Development Board

OVERVIEW:

If you are learning microcontrollers or want to quickly develop embedded solution based on standard AVR core, this board will help you quick start with the application by giving you access to everything required to run the Atmega16 microcontroller.With this board you can develop and prototype with any of Microchip's 40 pin AVR microcontrollers. . The board have User button and status LED.


FEATURES OF PRODUCT:
  • Quartz crystall 16Mhz.
  • The DIP40 locking device, easy to remove the ATMEGA microcontroller for reuse.
  • Reset button.
  • Power Indicating LED.
  • External TX,RX, GND
  • On board ISP programmer connector.
  • High quality PCB FR4 Grade with FPT Certified.

For More Sample Codes and Schematic: CLICK HERE