مقدمة:
هناك العديد من تطبيقات SMS المختلفة في السوق اليوم, والاكثر قيد التطوير حالياً.
قم بتحميل الملفات مفتوحة المصدر للبرنامج والذي سوف نستخدمه في مقالتنا اليوم
سوف نضرب لكم بعض الامثلة:
- تلك التقنية تمكن شخصين مختلفين من ارسال الرسائل فيما بينهم وهي صنعت من اجل ذلك
- العديد من المؤسسات تستخدم رسائل ال sms لأرسال الاخبار او تقارير الطقس او البيانات الاقتصادية.
- يمكن لرسائل SMS حمل البيانات الثنائية Binary Data ولذلك يمكننا ارسال الصور والمقاطع القابلة للتحميل او الشعارات وغيرها.
- تقنية SMS مناسبة جداً كأداة للتسويق او ارسال التنبيهات والاشعارات حول الاحداث الهامة والعاجلة.
بشكل عام هناك وسيلتين لأرسال رسائل ال sms من خلال برنامج علي الحاسوب:
- عبر اوامر AT والتي تعمل علي اجهزة المودم GSM /GPRS .
- من خلال موفر خدمة ال sms والمعروفة SMSC او SMS Center.
ولكننا سوف نستعمل الطريقة الاولي في هذه المقالة نظراً لسهولتها في التعامل ومجانيتها فكل ما تحتاجه هو رصيد في شريحة ال Modem.
قبل ذلك علينا التنويه بنبذة بسيطة عن اوامر AT:
ان اوامر ال AT هي جمل برمجية تستخدم للتحكم في المودم.
ال AT اختصار إلي : ATtention.
كل امر برمجي يبدأ ب "AT" او "at" لهذا سميت ب AT Command.
عليك العلم بأن هناك نوعين من شفرات واوامر ال AT:
- الاوامر الاساسية "Basic Command" وهي التي لا تبدأ ب "+".
- الاوامر الطويلة "Extended commands" وهي التي تبدأ ب "+".
اوضاع التشغيل "Operating Modes
"
"
يمكن تقسيم اوضاع التشغيل ال SMS الي نوعين وهما
- GPS/GPRS Modem
- Mobile Phone
والوضع الاول يستخدم SMS text
اما الوضع الثاني يستخدم SMS PDU
كيفية اختبار اتصال ال GSM Modem ؟
- اولاً عليك بأيجاد المودم المناسب لأحتيجاتك في المقالة سوف تكون الاختبارات علي مودم FASTRACK M1206.
- فهم ماهية وتفاصيل ال AT Command والتي من خلالها سوف يتم التواصل مع المودم.
- قم بتوصل المودم بالحاسوب بالتأكيد هناك دفتر للأرشادات عن كيفية التوصيل مع المدوم لديك.
- قم بوضع شريحة SIM المناسبة في المودم.
- قم بفتح ال HyperTerminal لأجراء الاتصال
- Start -> Programs -> Accessories -> Communications -> HyperTerminal.
- اكمل بقية اجرائات الاتصال حتي يظهر لديك connected successfully
public SerialPort OpenPort(string p_strPortName,
int p_uBaudRate, int p_uDataBits,
int p_uReadTimeout, int p_uWriteTimeout)
{
receiveNow = new AutoResetEvent(false);
SerialPort port = new SerialPort();
try
{
port.PortName = p_strPortName; //COM1
port.BaudRate = p_uBaudRate; //9600
port.DataBits = p_uDataBits; //8
port.StopBits = StopBits.One; //1
port.Parity = Parity.None; //None
port.ReadTimeout = p_uReadTimeout; //300
port.WriteTimeout = p_uWriteTimeout; //300
port.Encoding = Encoding.GetEncoding("iso-8859-1");
port.DataReceived += new SerialDataReceivedEventHandler
(port_DataReceived);
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
}
catch (Exception ex)
{
throw ex;
}
return port;
}
هنا نقوم بأرسال رسالة SMS
public bool sendMsg(SerialPort port, string PhoneNo, string Message)
{
bool isSend = false;
try
{
string recievedData = ExecCommand(port,"AT", 300, "No phone connected");
recievedData = ExecCommand(port,"AT+CMGF=1", 300,
"Failed to set message format.");
String command = "AT+CMGS=\"" + PhoneNo + "\"";
recievedData = ExecCommand(port,command, 300,
"Failed to accept phoneNo");
command = Message + char.ConvertFromUtf32(26) + "\r";
recievedData = ExecCommand(port,command, 3000,
"Failed to send message"); //3 seconds
if (recievedData.EndsWith("\r\nOK\r\n"))
{
isSend = true;
}
else if (recievedData.Contains("ERROR"))
{
isSend = false;
}
return isSend;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
هنا نقوم بقرائة رسائل SMS
public ShortMessageCollection ReadSMS(SerialPort port)
{
// Set up the phone and read the messages
ShortMessageCollection messages = null;
try
{
#region Execute Command
// Check connection
ExecCommand(port,"AT", 300, "No phone connected");
// Use message format "Text mode"
ExecCommand(port,"AT+CMGF=1", 300, "Failed to set message format.");
// Use character set "PCCP437"
ExecCommand(port,"AT+CSCS=\"PCCP437\"", 300,
"Failed to set character set.");
// Select SIM storage
ExecCommand(port,"AT+CPMS=\"SM\"", 300,
"Failed to select message storage.");
// Read the messages
string input = ExecCommand(port,"AT+CMGL=\"ALL\"", 5000,
"Failed to read the messages.");
#endregion
#region Parse messages
messages = ParseMessages(input);
#endregion
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
if (messages != null)
return messages;
else
return null;
}
هنا نقوم بحذف الرسائل
public bool DeleteMsg(SerialPort port , string p_strCommand)
{
bool isDeleted = false;
try
{
#region Execute Command
string recievedData = ExecCommand(port,"AT", 300, "No phone connected");
recievedData = ExecCommand(port,"AT+CMGF=1", 300,
"Failed to set message format.");
String command = p_strCommand;
recievedData = ExecCommand(port,command, 300, "Failed to delete message");
#endregion
if (recievedData.EndsWith("\r\nOK\r\n"))
{
isDeleted = true;
}
if (recievedData.Contains("ERROR"))
{
isDeleted = false;
}
return isDeleted;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
0 تعليق على موضوع "كيفية ارسال رسائل SMS او قرائتها عبر اوامر AT بواسطة لغة السي شارب"
الإبتساماتإخفاء