Hello all,
I am a newbie and currently learning c#. i have adequate programming ability. I have to create a project in c#. Now I am searching for a topic for my project. I have plans in my mind to create a desktop application through which we can send and receive SMS using our mobile phone as a modem. I know this has been implemented earlier a lot of times. I need your suggestions about,
HOW SHOULD I START?
WHAT ALTERNATIVE OPTIONS ARE AVAILABLE?
WILL I GET APPROPRIATE HELP FROM INTERNET REGARDING THIS PROJECT?
WHAT MORE FUNCTIONALITY CAN BE ADDED TO THIS PROJECT?

I will be really thankful to any kind of help you can provide.

Dani AI

Generated

As reported, the CodeProject sample that mentioned is useful for sending SMS (so the physical link and basic AT path appear OK), but a “Phone reports generic communication error or syntax error” when reading usually means the modem rejected an AT command or there’s a format/storage mismatch rather than a pure COM-port failure.

Quick diagnostic checklist:

  • Verify AT-level behavior with a serial terminal (HyperTerminal/Windows PuTTY/Tera Term) on the same COM port. A minimal manual session looks like:
AT
OK

AT+CPMS?
+CPMS: "SM",1,25,"SM",1,25,"SM",1,25
OK

AT+CMGF=1
OK

AT+CMGL="ALL"
+CMGL: 1,"REC UNREAD","+1234567890",,"20/06/01,12:34:56+32"
Hello world
OK
  • Confirm message format: text mode (AT+CMGF=1) vs PDU mode (AT+CMGF=0) and make the library use the same mode.
  • Query and explicitly set preferred storage with AT+CPMS (SM = SIM, ME = phone memory, MT = SIM+ME). Some handsets only expose SIM storage via standard AT commands.

Deeper troubleshooting notes:

  • If manual AT commands succeed but the library call fails, capture the exact AT command sequence the library issues (enable any debug/log in the library or use a serial sniffer). The returned “syntax”/“generic” error will then point to the offending command.
  • Check serial parameters (baud, parity, flow control). Some phones require no hardware flow control or a specific baud rate.
  • Some manufacturers restrict reading phone memory via standard commands; in that case rely on SIM reads or use a USB GSM modem which implements the AT command set more predictably.

Useful project/architecture tips:

  • Abstract the modem into a communication layer, add persistent queues and retry logic, and log full AT exchanges to a file. Support both PDU and text decoding, Unicode handling, concatenated messages, delivery-receipts, and a fallback HTTP/SMPP gateway for bulk sending.
  • Test all destructive operations on a spare SIM/phone and log everything before deleting messages.

Recommended Answers

All 2 Replies

Take a look at some articles on the Internet (google it please). Have a look at code-project article.

yeah i have looked at the project and downloaded sample files from there. I tested the application by connecting it to my nokia mobile phone modem. I was able to send sms from that application. But the problem is when i try to read the messages from my sim card or phone... the following message occurs..

Phone reports genric communication error or syntax error

please help me to get out of this. I tried to google this problem but no satisfactory solution was found. Following is the source code for READ section of the application.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Data;

using GsmComm.PduConverter;
using GsmComm.GsmCommunication;

namespace SMS
{
	/// <summary>
	/// Summary description for Receive.
	/// </summary>
	public class Receive : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnReadMessage;
		private System.Windows.Forms.RadioButton rbMessagePhone;
		private System.Windows.Forms.RadioButton rbMessageSIM;
		private System.Windows.Forms.TextBox txtOutput;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.DataGrid dataGrid1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private DataTable dt=new DataTable();
		private delegate void SetTextCallback(string text);
        
		public Receive()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnReadMessage = new System.Windows.Forms.Button();
			this.rbMessagePhone = new System.Windows.Forms.RadioButton();
			this.rbMessageSIM = new System.Windows.Forms.RadioButton();
			this.txtOutput = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// btnReadMessage
			// 
			this.btnReadMessage.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnReadMessage.Location = new System.Drawing.Point(192, 80);
			this.btnReadMessage.Name = "btnReadMessage";
			this.btnReadMessage.Size = new System.Drawing.Size(112, 24);
			this.btnReadMessage.TabIndex = 17;
			this.btnReadMessage.Text = "Read All Messages";
			this.btnReadMessage.Click += new System.EventHandler(this.btnReadMessage_Click);
			// 
			// rbMessagePhone
			// 
			this.rbMessagePhone.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.rbMessagePhone.Location = new System.Drawing.Point(16, 56);
			this.rbMessagePhone.Name = "rbMessagePhone";
			this.rbMessagePhone.Size = new System.Drawing.Size(64, 24);
			this.rbMessagePhone.TabIndex = 25;
			this.rbMessagePhone.Text = "Phone";
			// 
			// rbMessageSIM
			// 
			this.rbMessageSIM.Checked = true;
			this.rbMessageSIM.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.rbMessageSIM.Location = new System.Drawing.Point(16, 24);
			this.rbMessageSIM.Name = "rbMessageSIM";
			this.rbMessageSIM.Size = new System.Drawing.Size(64, 24);
			this.rbMessageSIM.TabIndex = 24;
			this.rbMessageSIM.TabStop = true;
			this.rbMessageSIM.Text = "SIM";
			// 
			// txtOutput
			// 
			this.txtOutput.Location = new System.Drawing.Point(8, 304);
			this.txtOutput.Multiline = true;
			this.txtOutput.Name = "txtOutput";
			this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtOutput.Size = new System.Drawing.Size(448, 144);
			this.txtOutput.TabIndex = 57;
			this.txtOutput.Text = "";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.rbMessageSIM);
			this.groupBox1.Controls.Add(this.rbMessagePhone);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(176, 96);
			this.groupBox1.TabIndex = 58;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Message Storage";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(8, 120);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(448, 176);
			this.dataGrid1.TabIndex = 59;
			// 
			// Receive
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(464, 454);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.txtOutput);
			this.Controls.Add(this.btnReadMessage);
			this.Name = "Receive";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Read Messages";
			this.Load += new System.EventHandler(this.Receive_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void btnReadMessage_Click(object sender, System.EventArgs e)
		{
			Cursor.Current = Cursors.WaitCursor;
			string storage = GetMessageStorage();

			try
			{
				// Read all SMS messages from the storage
								
				DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage);
				foreach(DecodedShortMessage message in messages)
				{
					Output(string.Format("Message status = {0}, Location = {1}/{2}",
						StatusToString(message.Status),	message.Storage, message.Index));
					ShowMessage(message.Data);
					Output("");				
				}
				Output(string.Format("{0,9} messages read.", messages.Length.ToString()));
				Output("");				
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}

			Cursor.Current = Cursors.Default;		
		}
		

		private void BindGrid(SmsPdu pdu)
		{

			DataRow dr=dt.NewRow();
			SmsDeliverPdu data = (SmsDeliverPdu)pdu;
			            
			dr[0]=data.OriginatingAddress.ToString();
			dr[1]=data.SCTimestamp.ToString();
			dr[2]=data.UserDataText;
			dt.Rows.Add(dr);
            
			dataGrid1.DataSource=dt;
		}

		private void ShowMessage(SmsPdu pdu)
		{
			if (pdu is SmsSubmitPdu)
			{
				// Stored (sent/unsent) message
				SmsSubmitPdu data = (SmsSubmitPdu)pdu;
				Output("SENT/UNSENT MESSAGE");
				Output("Recipient: " + data.DestinationAddress);
				Output("Message text: " + data.UserDataText);
				Output("-------------------------------------------------------------------");
				return;
			}
			if (pdu is SmsDeliverPdu)
			{
				// Received message
				SmsDeliverPdu data = (SmsDeliverPdu)pdu;
				Output("RECEIVED MESSAGE");
				Output("Sender: " + data.OriginatingAddress);
				Output("Sent: " + data.SCTimestamp.ToString());
				Output("Message text: " + data.UserDataText);
				Output("-------------------------------------------------------------------");

				BindGrid(pdu);

				return;
			}
			if (pdu is SmsStatusReportPdu)
			{
				// Status report
				SmsStatusReportPdu data = (SmsStatusReportPdu)pdu;
				Output("STATUS REPORT");
				Output("Recipient: " + data.RecipientAddress);
				Output("Status: " + data.Status.ToString());
				Output("Timestamp: " + data.DischargeTime.ToString());
				Output("Message ref: " + data.MessageReference.ToString());
				Output("-------------------------------------------------------------------");
				return;
			}
			Output("Unknown message type: " + pdu.GetType().ToString());
		}


		private string StatusToString(PhoneMessageStatus status)
		{
			// Map a message status to a string
			string ret;
			switch(status)
			{
				case PhoneMessageStatus.All:
					ret = "All";
					break;
				case PhoneMessageStatus.ReceivedRead:
					ret = "Read";
					break;
				case PhoneMessageStatus.ReceivedUnread:
					ret = "Unread";
					break;
				case PhoneMessageStatus.StoredSent:
					ret = "Sent";
					break;
				case PhoneMessageStatus.StoredUnsent:
					ret = "Unsent";
					break;
				default:
					ret = "Unknown (" + status.ToString() + ")";
					break;
			}
			return ret;
		}


		private string GetMessageStorage()
		{
			string storage = string.Empty;
			if (rbMessageSIM.Checked)
				storage = PhoneStorageType.Sim;
			if (rbMessagePhone.Checked)
				storage = PhoneStorageType.Phone;
			if (storage.Length == 0)
				throw new ApplicationException("Unknown message storage.");
			else
				return storage;
		}


		private void Output(string text)
		{
			if (this.txtOutput.InvokeRequired)
			{
				SetTextCallback stc = new SetTextCallback(Output);
				this.Invoke(stc, new object[] { text });
			}
			else
			{
				txtOutput.AppendText(text);
				txtOutput.AppendText("\r\n");
			}
		}


		private void Receive_Load(object sender, System.EventArgs e)
		{
			dt.Columns.Add("Sender",typeof(string));
			dt.Columns.Add("Time",typeof(string));
			dt.Columns.Add("Message",typeof(string));			
		}

		private void Output(string text, params object[] args)
		{
			string msg = string.Format(text, args);
			Output(msg);
		}

	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.