using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;
using System.Data;
using System.IO;
namespace Sim900
{
class Program
{
static void Main(string[] args)
{
int a, b;
int mSpeed = 1;
string msg;
//==================Config=====
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("1-Please Inter GSM Port Number:");
int port1 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("2-Please Inter System Port Number:");
int port2 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("2-Please Inter your Phone number:");
Int32 number = Convert.ToInt32(Console.ReadLine());
SerialPort gsm = new SerialPort("COM" + port1, 9600, Parity.None, 8, StopBits.One);
gsm.Open();
SerialPort system = new SerialPort("COM" + port2, 9600, Parity.None, 8, StopBits.One);
//=================
Console.Clear();
if (gsm.IsOpen == true)
//=============
while (true)
{
saeed:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("======= { SMS SERVER SIM900 DESIGNED BY S.SETAREH}======");
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("1- SMS MOD ");
Console.WriteLine("2- Dail ");
Console.WriteLine("3- EXIT ");
Console.WriteLine("===================================");
Console.WriteLine("Please choose the On Item:");
Console.ForegroundColor = ConsoleColor.Red;
a = Convert.ToInt16(Console.ReadLine());
////////--------------
if (a == 1)
{
sms:
Console.Clear();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("======== { SMS MOD}======");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("1- Send SMS ");
Console.WriteLine("2- Read SMS ");
Console.WriteLine("3- Delet All SMS");
Console.WriteLine("4- Balance ");
Console.WriteLine("5- Auto Controling ");
Console.WriteLine("6- Back ");
b = Convert.ToInt16(Console.ReadLine());
//////////////////////////////////////////////////////
if (b == 1)
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("Please write the massege");
msg = Convert.ToString(Console.ReadLine());
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write(msg + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
System.Threading.Thread.Sleep(200);
System.Threading.Thread.Sleep(mSpeed);
Console.WriteLine("Send Sucsess!");
System.Threading.Thread.Sleep(500);
Console.Clear();
goto sms;
}
/////////////////////////////////////////////////////////
if (b == 2)
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("INBOX :");
Console.ForegroundColor = ConsoleColor.Yellow;
gsm.Write("AT+CMGL=" + (char)34 + "ALL" + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(1000);
string t = gsm.ReadExisting();
Console.WriteLine(t);
}
if (b == 3)
{
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
Console.WriteLine("All SMS DELETED..!");
System.Threading.Thread.Sleep(500);
Console.Clear();
goto sms;
}
if (b == 4)
{
Console.Clear();
Console.WriteLine("Your Balance :");
Console.ForegroundColor = ConsoleColor.Yellow;
gsm.Write("ATD*140*1#" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(7000);
string o = gsm.ReadExisting();
Console.WriteLine(o);
}
if (b == 5)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Clear();
Console.WriteLine("SYSTEM IS ONLINE...");
Console.ForegroundColor = ConsoleColor.Green;
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
control:
string t = gsm.ReadExisting();
System.Threading.Thread.Sleep(200);
if (t.Contains("CMTI"))
{
Console.Write("On sms Recived ==> ");
gsm.Write("AT+CMGR=1" + Environment.NewLine);
System.Threading.Thread.Sleep(500);
string g = gsm.ReadExisting();
if (g.Contains("1-ON"))
{
system.WriteLine("1");
Console.WriteLine("Relay 1 Is On");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("Relay 1 Is On" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
if (g.Contains("1-OFF"))
{
system.WriteLine("2");
Console.WriteLine("Relay 1 Is off");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("Relay 1 Is off" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
if (g.Contains("2-ON"))
{
system.WriteLine("3");
Console.WriteLine("Relay 2 Is On");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("Relay 2 Is On" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
if (g.Contains("2-OFF"))
{
system.WriteLine("4");
Console.WriteLine("Relay 2 Is off");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("Relay 2 Is Off" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
if (g.Contains("3-ON"))
{
system.WriteLine("5");
Console.WriteLine("Relay 3 Is On");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("Relay 3 Is On" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
if (g.Contains("3-OFF"))
{
system.WriteLine("6");
Console.WriteLine("Relay 3 Is off");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("Relay 3 Is off" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
Console.WriteLine("Cod is Error");
gsm.Write("AT+CMGD=0,4" + ";" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGF=1" + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("AT+CMGS=" + (char)34 + number + (char)34 + Environment.NewLine);
System.Threading.Thread.Sleep(200);
gsm.Write("YOUR COD IS ERROR!" + Char.ConvertFromUtf32(26) + char.ConvertFromUtf32(13));
goto control;
}
goto control;
}
if (b == 6)
{
Console.Clear();
goto saeed;
}
}
if (a == 2)
{
gsm.Write("ATD" +number+ ";" + Environment.NewLine);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Dialing to Manager...");
Console.WriteLine("Press 1 Disconnect");
int s = Convert.ToInt16(Console.ReadLine());
if (s == 1)
{
gsm.Write("ATH" + Environment.NewLine);
Console.Clear();
goto saeed;
}
}
if (a == 3)
{
gsm.Close();
system.Close();
Environment.Exit(0);
}
}
}
}
}