Hi,
I guess its possible to send/receive SMS with N6300, using DKU-5 cable.
My friend phuong oanh tested with N6100,6230,6020 with DKU-5 cable which convert USB to serial. You can try with that.
Hope it works , Good Luck.
Thanks,
Ranjan.D
Hi! I using Sony Erriccson w550i.
when I initialize modem after opening com port invoke method EnableMessageNotifications().
comm = new GsmCommMain(4, 9600, 600);
comm.Open();
comm.EnableMessageNotifications();
SmsSubmitPdu pdu;
byte dcs;
dcs = DataCodingScheme.NoClass_16Bit;
pdu = new SmsSubmitPdu(textBox2.Text, textBox1.Text, "", dcs);
comm.SendMessage(pdu);
but I do not receive report of delivery message. I don't know to do
Hi,
I am using Nokia N95 which connects to Computer using USB. Since this application requires a COM port, can anyone please let me know how to see USB connection as COM port.
Thanks in advance.
Regards
Braj
Hi,
You have to either use Virtual Com port driver in such case.
Virtual COM port (VCP) drivers cause the USB device to appear as an additional COM port available to the PC. Application software can access the USB device in the same way as it would access a standard COM port.
There;s one more option you can buy one USB to serial converter.
With N6100,6230,6020 you can use DKU-5 cable convert USB to serial.
Thanks,
Ranjan.D
Dear all,
I used your code to develop my window service . My service will send SMS automatically every 2 minutes (using 2 GSM Modem at the same time). It works so good about 10 messages , then the error ("Port is already open or No Phone Connected") often appears . I used an database to control "Sent Message"(MO table) and "Received Message"(MT table) . I don't know how to solve this issue . Please help me as soon as possible . My nickname in yahoo : eternal_loving190@yahoo.com.vn . Thanks a lot !!! This is a part of my code :
....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using GsmComm.GsmCommunication;
using System.Diagnostics;
using System.Web;
using System.Threading;
using GsmComm.PduConverter;
using System.IO;
namespace SSM2
{
class SSMProcessor
{
private static string ConnectionString = Properties.Settings.Default.ConnectionString;
private static string Header = Properties.Settings.Default.Header;
private static string Storage = Properties.Settings.Default.Storage;
private static string ServiceID = Properties.Settings.Default.ServiceID;
private static string Admin_Viettel = Properties.Settings.Default.Admin_Viettel;
private static string Admin_VinaPhone = Properties.Settings.Default.Admin_VinaPhone;
private static string Viettel_Number = Properties.Settings.Default.Viettel;
private static string VinaPhone_Number = Properties.Settings.Default.VinaPhone;
private static string VinaPhone_MNO = Properties.Settings.Default.VinaPhone_MNO;
private static string Viettel_MNO = Properties.Settings.Default.Viettel_MNO;
private static int Viettel_Port = Properties.Settings.Default.Viettel_Port;
private static int VinaPhone_Port = Properties.Settings.Default.VinaPhone_Port;
private static int BaudRate = Properties.Settings.Default.BaudRate;
private static int TimeOut = Properties.Settings.Default.TimeOut;
private static string strIndexTemp_Viettel = "";
private static string strIndexTemp_VinaPhone = "";
private static int port;
private static int baudRate;
private static int timeout;
public static void Process()
{
try
{
Process_Every_Port();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Process_Every_Port");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
}
private static void Process_Every_Port()
{
ViettelPort(Viettel_Port, BaudRate, TimeOut);
VinaPhonePort(VinaPhone_Port, BaudRate, TimeOut);
}
private static void ViettelPort(int _port, int _baudrate, int _timeout)
{
try
{
if (TestConnection_Viettel(_port, _baudrate, _timeout))
{
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, Storage);
foreach (DecodedShortMessage message in messages)
{
GetMessage(message.Data, Viettel_MNO);
}
}
string strIndex = "";
if (strIndexTemp_Viettel == "")
{
Insert_MNO(Viettel_MNO);
if (Select_Index(Viettel_MNO) != -1)
{
strIndex = Select_Index(Viettel_MNO).ToString();
SendMessage(strIndex, Viettel_MNO, Viettel_Number, ServiceID, DateTime.Now.ToString(), Admin_Viettel, ref strIndexTemp_Viettel);
}
else
{
WriteLog(Viettel_Number, "Error when accessing on DB", "", DateTime.Now.ToString(), "", Viettel_MNO);
}
}
else
{
if (Status(strIndexTemp_Viettel, Viettel_MNO, Viettel_Number, ServiceID) > 0 && Status(strIndexTemp_Viettel, Viettel_MNO, Viettel_Number, ServiceID) < 4)
{
SendMessage(strIndexTemp_Viettel, Viettel_MNO, Viettel_Number, ServiceID, DateTime.Now.ToString(), Admin_Viettel, ref strIndexTemp_Viettel);
}
else if (Status(strIndexTemp_Viettel, Viettel_MNO, Viettel_Number, ServiceID) == 4 || Status(strIndexTemp_Viettel, Viettel_MNO, Viettel_Number, ServiceID) == 5)
{
Insert_MNO(Viettel_MNO);
if (Select_Index(Viettel_MNO) != -1)
{
strIndex = Select_Index(Viettel_MNO).ToString();
SendMessage(strIndex, Viettel_MNO, Viettel_Number, ServiceID, DateTime.Now.ToString(), Admin_Viettel, ref strIndexTemp_Viettel);
}
else
{
WriteLog(Viettel_Number, "Error when accessing on DB", "", DateTime.Now.ToString(), "", Viettel_MNO);
}
}
}
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Viettel_Port");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
CommSetting.comm.Close();
}
private static void VinaPhonePort(int _port, int _baudrate, int _timeout)
{
try
{
if (TestConnection_VinaPhone(_port, _baudrate, _timeout))
{
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, Storage);
foreach (DecodedShortMessage message in messages)
{
GetMessage(message.Data, VinaPhone_MNO);
}
}
string strIndex = "";
if (strIndexTemp_VinaPhone == "")
{
Insert_MNO(VinaPhone_MNO);
if (Select_Index(VinaPhone_MNO) != -1)
{
strIndex = Select_Index(VinaPhone_MNO).ToString();
SendMessage(strIndex, VinaPhone_MNO, VinaPhone_Number, ServiceID, DateTime.Now.ToString(), Admin_VinaPhone, ref strIndexTemp_VinaPhone);
}
else
{
WriteLog(VinaPhone_Number, "Error when accessing on DB", "", DateTime.Now.ToString(), "", VinaPhone_MNO);
}
}
else
{
if (Status(strIndexTemp_VinaPhone, VinaPhone_MNO, VinaPhone_Number, ServiceID) > 0 && Status(strIndexTemp_VinaPhone, VinaPhone_MNO, VinaPhone_Number, ServiceID) < 4)
{
SendMessage(strIndexTemp_VinaPhone, VinaPhone_MNO, VinaPhone_Number, ServiceID, DateTime.Now.ToString(), Admin_VinaPhone, ref strIndexTemp_VinaPhone);
}
else if (Status(strIndexTemp_VinaPhone, VinaPhone_MNO, VinaPhone_Number, ServiceID) == 4 || Status(strIndexTemp_VinaPhone, VinaPhone_MNO, VinaPhone_Number, ServiceID) == 5)
{
Insert_MNO(VinaPhone_MNO);
if (Select_Index(VinaPhone_MNO) != -1)
{
strIndex = Select_Index(VinaPhone_MNO).ToString();
SendMessage(strIndex, VinaPhone_MNO, VinaPhone_Number, ServiceID, DateTime.Now.ToString(), Admin_VinaPhone, ref strIndexTemp_VinaPhone);
}
else
{
WriteLog(VinaPhone_Number, "Error when accessing on DB", "", DateTime.Now.ToString(), "", VinaPhone_MNO);
}
}
}
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "VinaPhone_Port");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
CommSetting.comm.Close();
}
private static bool EnterNewSettings(int newPort, int newBaudRate, int newTimeout)
{
int Port;
int BaudRate;
int Timeout;
try
{
Port = newPort;
}
catch (Exception)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "InvalidPort");
e.WriteEntry("Invalid port number", EventLogEntryType.Error);
e.Close();
return false;
}
try
{
BaudRate = newBaudRate;
}
catch (Exception)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "InvalidBaudRate");
e.WriteEntry("Invalid baud rate", EventLogEntryType.Error);
e.Close();
return false;
}
try
{
Timeout = newTimeout;
}
catch (Exception)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "InvalidTimeout");
e.WriteEntry("Invalid timeout value", EventLogEntryType.Error);
e.Close();
return false;
}
SetData(Port, BaudRate, Timeout);
return true;
}
public static void SetData(int _port, int _baudRate, int _timeout)
{
port = _port;
baudRate = _baudRate;
timeout = _timeout;
}
public static bool TestConnection_Viettel(int _port, int _baudrate, int _timeout)
{
if (!EnterNewSettings(_port, _baudrate, _timeout))
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_SetData_ViettelPort");
e.WriteEntry("Cannot set data on port", EventLogEntryType.Error);
e.Close();
return false;
}
CommSetting.Comm_Port = _port;
CommSetting.Comm_BaudRate = _baudrate;
CommSetting.Comm_TimeOut = _timeout;
CommSetting.comm = new GsmCommMain(_port, _baudrate, _timeout);
try
{
CommSetting.comm.Open();
while (!CommSetting.comm.IsConnected())
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_Connect_ViettelPort");
e.WriteEntry("No phone connected", EventLogEntryType.Error);
e.Close();
CommSetting.comm.Close();
return false;
}
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_OpenOrConnect_ViettelPort");
e.WriteEntry("Connection error: " + ex.Message, EventLogEntryType.Error);
e.Close();
return false;
}
return true;
}
public static bool TestConnection_VinaPhone(int _port, int _baudrate, int _timeout)
{
if (!EnterNewSettings(_port, _baudrate, _timeout))
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_SetData_VinaPort");
e.WriteEntry("Cannot set data on port", EventLogEntryType.Error);
e.Close();
return false;
}
CommSetting.Comm_Port = _port;
CommSetting.Comm_BaudRate = _baudrate;
CommSetting.Comm_TimeOut = _timeout;
CommSetting.comm = new GsmCommMain(_port, _baudrate, _timeout);
try
{
CommSetting.comm.Open();
while (!CommSetting.comm.IsConnected())
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_Connect_VinaPort");
e.WriteEntry("No phone connected", EventLogEntryType.Error);
e.Close();
CommSetting.comm.Close();
return false;
}
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_OpenOrConnect_VinaPort");
e.WriteEntry("Connection error: " + ex.Message, EventLogEntryType.Error);
e.Close();
return false;
}
return true;
}
private static void GetMessage(SmsPdu pdu, string _MNO)
{
if (pdu is SmsDeliverPdu)
{
// Received message
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
string UserID = data.OriginatingAddress;
string ReceiverID = "";
if (_MNO == Viettel_MNO)
ReceiverID = Viettel_Number;
else if (_MNO == VinaPhone_MNO)
ReceiverID = VinaPhone_Number;
string ResponseTime = data.SCTimestamp.ToString();
int index = ResponseTime.IndexOf("+");
ResponseTime = ResponseTime.Remove(index);
string Content = data.UserDataText;
if (Check_Exist_MT(ReceiverID, _MNO, Content) == 0 && UserID == ServiceID)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "Insert into MT_GSM (MNO,UserID,ReceiverID,ServiceID,Message,ResponseTime,ResponseTime_Server) values('" + _MNO + "','" + UserID + "','" + ReceiverID + "','" + ServiceID + "','" + Content + "','" + ResponseTime + "','"+ DateTime.Now.ToString() +"')";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
command.ExecuteNonQuery();
mycon.Close();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_InsertMT_GSM");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
}
return;
}
else if (pdu is SmsSubmitPdu)
{
// Sent message
SmsSubmitPdu sent_data = (SmsSubmitPdu)pdu;
string UserID_Sent = "";
string ReceiverID = sent_data.DestinationAddress;
if (_MNO == Viettel_MNO)
UserID_Sent = Viettel_Number;
else if (_MNO == VinaPhone_MNO)
UserID_Sent = VinaPhone_Number;
string RequestTime = sent_data.GetTimestamp().ToString();
int index2 = RequestTime.IndexOf("+");
RequestTime = RequestTime.Remove(index2);
string Content_Sent = sent_data.UserDataText;
if (ReceiverID == ServiceID)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "Insert into SENT_GSM (MNO,UserID,ReceiverID,Message,RequestTime) values('" + _MNO + "','" + UserID_Sent + "','" + ReceiverID + "','" + Content_Sent + "','" + RequestTime + "')";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
command.ExecuteNonQuery();
mycon.Close();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_InsertSENT_GSM");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
}
return;
}
else
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_UnknownMessageType");
e.WriteEntry("Unknown message type: " + pdu.GetType().ToString(), EventLogEntryType.Error);
e.Close();
}
}
public static int Status(string _index, string _MNO, string _UserID, string _ServiceID)
{
int status = 0;
if (Check_Exist_MT(_UserID, _MNO, _index) == 0 && Check_Exist_MO(_UserID, _MNO, _index) == 1)
{
status = 1;
}
if (Check_Exist_MT(_UserID, _MNO, _index) == 0 && Check_Exist_MO(_UserID, _MNO, _index) == 2)
{
status = 2;
}
if (Check_Exist_MT(_UserID, _MNO, _index) == 1 && Check_Exist_MO(_UserID, _MNO, _index) == 2)
{
status = 3;
}
if (Check_Exist_MT(_UserID, _MNO, _index) == Check_Exist_MO(_UserID, _MNO, _index) && Check_Exist_MT(_UserID, _MNO, _index) != 0 && Check_Exist_MO(_UserID, _MNO, _index) != 0)
{
status = 4;
}
if (Check_Exist_MO(_UserID, _MNO, _index) == 3)
{
status = 5;
}
return status;
}
public static void SendMessage(string _index, string _MNO, string _UserID, string _ServiceID, string _RequestTime, string _Admin, ref string _indexTemp)
{
if (Check_Exist_MT(_UserID, _MNO, _index) == 0 && Check_Exist_MO(_UserID, _MNO, _index) == 0)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "Insert into MO_GSM ([Index],MNO,UserID,ServiceID,Message,RequestTime,Count) values('" + _index + "','" + _MNO + "','" + _UserID + "','" + _ServiceID + "','" + Header + " " + _index + "','" + _RequestTime + "',1)";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
command.ExecuteNonQuery();
mycon.Close();
SmsSubmitPdu pdu = new SmsSubmitPdu(Header + " " + _index, ServiceID, "");
CommSetting.comm.SendMessage(pdu);
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_SendSMSFirst");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
WriteLog(_UserID, _index, "Can not send message first", _RequestTime.ToString(), "", _MNO);
}
_indexTemp = _index;
return;
}
if (Check_Exist_MT(_UserID, _MNO, _index) == 0 && Check_Exist_MO(_UserID, _MNO, _index) == 1)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "Insert into MO_GSM ([Index],MNO,UserID,ServiceID,Message,RequestTime,Count) values('" + _index + "','" + _MNO + "','" + _UserID + "','" + _ServiceID + "','" + Header + " " + _index + "','" + _RequestTime + "',2)";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
command.ExecuteNonQuery();
mycon.Close();
SmsSubmitPdu pdu = new SmsSubmitPdu(Header + " " + _index, ServiceID, "");
CommSetting.comm.SendMessage(pdu);
mycon.Open();
string strCommand1 = "select * from MO_GSM where [Index]='" + _index + "' and MNO='" + _MNO + "' and UserID='" + _UserID + "' and Count=1";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(strCommand1, mycon);
da.Fill(dt);
mycon.Close();
string MNO = "";
string UserID = "";
string RequestTime = "";
string index = "";
foreach (DataRow row in dt.Rows)
{
MNO = Convert.ToString(row["MNO"]);
UserID = Convert.ToString(row["UserID"]);
RequestTime = Convert.ToString(row["RequestTime"]);
index = Convert.ToString(row["Index"]);
}
WriteLog(UserID, index, "Pending", RequestTime, "", MNO);
WriteLog(_UserID, _index, "Send again", _RequestTime.ToString(), "", _MNO);
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_SendSMSAgain");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
WriteLog(_UserID, _index, "Can not send message again", _RequestTime.ToString(), "", _MNO);
}
_indexTemp = _index;
return;
}
if (Check_Exist_MT(_UserID, _MNO, _index) == 0 && Check_Exist_MO(_UserID, _MNO, _index) == 2)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "";
if (_MNO == Viettel_MNO)
{
strCommand = "Insert into MO_GSM ([Index],MNO,UserID,ServiceID,Message,RequestTime,Count) values('" + _index + "','" + _MNO + "','" + _UserID + "','" + Admin_Viettel + "','Please be informed that can not send " + _index + "','" + _RequestTime + "',3)";
}
else if (_MNO == VinaPhone_MNO)
{
strCommand = "Insert into MO_GSM ([Index],MNO,UserID,ServiceID,Message,RequestTime,Count) values('" + _index + "','" + _MNO + "','" + _UserID + "','" + Admin_VinaPhone + "','Please be informed that can not send " + _index + "','" + _RequestTime + "',3)";
}
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
command.ExecuteNonQuery();
mycon.Close();
SmsSubmitPdu pdu = new SmsSubmitPdu("Please be informed that can't send " + _index, _Admin, "");
CommSetting.comm.SendMessage(pdu);
WriteLog(_UserID, _index, "Sent alert to " + _Admin, _RequestTime.ToString(), "", _MNO);
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_SendSMSAlert");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
WriteLog(_UserID, _index, "Can not send message to " + _Admin, _RequestTime.ToString(), "", _MNO);
}
_indexTemp = _index;
return;
}
if (Check_Exist_MT(_UserID, _MNO, _index) == 1 && Check_Exist_MO(_UserID, _MNO, _index) == 2)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand1 = "select * from MO_GSM where [Index]='" + _index + "' and MNO='" + _MNO + "' and UserID='" + _UserID + "' and Count=2";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(strCommand1, mycon);
da.Fill(dt);
mycon.Close();
string MNO = "";
string UserID = "";
string RequestTime = "";
string index = "";
foreach (DataRow row in dt.Rows)
{
MNO = Convert.ToString(row["MNO"]);
UserID = Convert.ToString(row["UserID"]);
RequestTime = Convert.ToString(row["RequestTime"]);
index = Convert.ToString(row["Index"]);
}
WriteLog(UserID, index, "Sent 2 messages and received only one message", RequestTime.ToString(), "", MNO);
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_LogFileOnly");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
_indexTemp = _index;
return;
}
}
public static void WriteLog(string _UserID, string _index, string _status, string _RequestTime, string _ResponseTime, string _MNO)
{
try
{
string path = @"E:\Working\SSM2\SSM2\LOG\";
path = Path.Combine(path, string.Format("{0:MMddyyyy}.txt", DateTime.Now));
StringBuilder content = new StringBuilder(string.Format("{0:ddMMyyyy HH:mm:ss}", _UserID) + "\t");
content.Append(_index + "\t");
content.Append(_RequestTime + "\t");
content.Append(_status + "\t");
content.Append(_ResponseTime + "\t");
content.Append(_MNO + "\t");
content.AppendLine();
if (!File.Exists(path))
{
FileStream stream = File.Create(path);
stream.Close();
}
File.AppendAllText(path, content.ToString());
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_WriteLogFile");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
}
public static int Check_Exist_MT(string _UserID, string _MNO, string _index)
{
int count = -1;
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "select count(*) from MT_GSM where Message='" + _index + "' and MNO ='" + _MNO + "' and ReceiverID='" + _UserID + "' and ServiceID='" + ServiceID + "'";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
count = (int)command.ExecuteScalar();
mycon.Close();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_CheckExistMT");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
return count;
}
public static int Check_Exist_MO(string _UserID, string _MNO, string _index)
{
int count = -1;
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "select count(*) from MO_GSM where [Index]='" + _index + "' and MNO ='" + _MNO + "' and UserID='" + _UserID + "' and ServiceID='" + ServiceID + "'";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
count = (int)command.ExecuteScalar();
mycon.Close();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_CheckExistMO");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
return count;
}
public static int Select_Index(string _MNO)
{
int count = -1;
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "select max(IndexID) from INDEX_GSM where MNO ='" + _MNO + "'";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
count = (int)command.ExecuteScalar();
mycon.Close();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_Select_Index");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
return count;
}
public static void Insert_MNO(string _MNO)
{
try
{
SqlConnection mycon = new SqlConnection(ConnectionString);
mycon.Open();
string strCommand = "Insert into INDEX_GSM (MNO) values('" + _MNO + "')";
SqlCommand command = new SqlCommand();
command.Connection = mycon;
command.CommandText = strCommand;
command.ExecuteNonQuery();
mycon.Close();
}
catch (Exception ex)
{
EventLog e = new EventLog("Application", System.Environment.MachineName, "Error_Insert_MNO");
e.WriteEntry(ex.Message, EventLogEntryType.Error);
e.Close();
}
return;
}
}
}
.....
modified on Friday, January 9, 2009 2:00 AM
Hi,
Please try one thing
1) Open and Close the Com port immediately after the use.
You told your service will send SMS automatically every 2 minutes , then do open the connection send SMS and then close it.
Thanks,
Ranjan.D
Hi,
I can send message and it works fine but when i try to read message, it gives me following error:
"Phone reports generic communication error or syntax error"
Can you please let me know how to fix it.
Regards,
Braj
Just would like to add one more point...I am using Nokia N95 phone as GSM modem connected to computer using bluetooth.
Regards,
Braj
Hi,
This article project sample wont work with bluetooth.
It works with GSM modem / GSM phone connected to your system through Serial cable. Try connecting GSM modem/phone with serial cable. You will get USB to Serial Cable through which you can connect your phone and try.
If any issues , you are pleased to send me a query.
Thanks,
Ranjan.D
Thank you so very much Ranjan. I have E71 phone which I connect through USB port of my laptop. I do not know how to make it COM port which I need to use in order to run your application. Bluetooth port appears as COM so it works.
Any idea how can i make my USB connection to phone as COM port??
Regards,
Braj
Sorry Ranjan for bothering you for small issue as before...It was nonsense mistake from my and no I can connect my E71 phone to COM port using USB cable. I am able to send message but when i read message, it gives me error dialog box saying "Phone reports generic communication error or syntax error".
Any idea how to fix it?
Regards,
Braj
Hi,
Try whether you can read SMS using AT commands with Windows - Hypertermial software.
If there;s no issue in reading SMS with hyper terminal then will see what next to do.
Thanks,
Ranjan.D
Hi
I also get the "Phone reports generic communication error or syntax error" messages when I try to read messages from the phone. How do I try AT command??
Kind regards
Ruben
Hi,
Below mentioned steps will give you an idea How you can use Windows -> HyperTerminal + use of AT Commands.
For your Reference : http://www.developershome.com/sms/howToUseHyperTerminal.asp [^ ]
1)You can check whether its possible to connect to your mobile through Windows->HyperTerminal communication program.
if connection is sucessfull then follow the below steps
1) To Check whether your phone understands AT Commands
the below command you need to specify in Hyperterminal , if your phone supports AT COmmands then it should respond properly
To test the communication between PC to GSM modem whether it’s for Sending / Receiving SMS you can use the use the command AT, inturn the GSM modem should respond with OK
command: AT
response: OK
Read SMS based on status
AT+CMGL="REC UNREAD"
The GSM/GPRS modem or mobile phone should return something like this:
+CMGL: 1,"REC UNREAD","+919900227451",,"07/02/18,00:05:10+32"
Reading text messages is easy.
+CMGL: 2,"REC UNREAD","+919900227451",,"07/02/18,00:07:22+32"
A simple demo of SMS text messaging.
OK
Please let me know if you have any doubts.
Thanks,
Ranjan.D
Hi,
Finally got HyperTerminal installed on Vista!
AT Works partly. Got the following responses:
AT
OK
AT+CMGL="REC UNREAD"
ERROR
AT
OK
AT+CPIN?
+CPIN: READY
OK
AT+CMGL
ERROR
Any suggestions?
Best wishes
Ruben
Hi
I try to use a Nokia E65. This phone seams to have AT problems!
I shift to a Nokia 6230i. There it works.
Best wishes
Ruben
<blockquote class="FQ"><div class="FQA">acg023 wrote:</div>Hi
I try to use a Nokia E65. This phone seams to have AT problems!
I shift to a Nokia 6230i. There it works.
Best wishes
Ruben</blockquote>
Hi i am using a Nokia N95 and i am unable to recv messages using the .net application. The application throws an exception at comm.EnableMessageNotifications().
Does anyone has a solution for this?
hi..
i want c# with asp.net application code using send sms to gsm modem. so plz send the project in my mail
Hi,
You can modify this article code for asp.net application to send/receive SMS. I left my previous company where I used GSM modem to send/receive SMS ,so now am unable to test. any ways when I was in my previous company I created a Webservice to send SMS. Dont worry a small modifications u have to do, sure it will work.
Thanks,
Ranjan.D
Hi,
I need C# source code for sending and receiving SMS using GSM Modem.
and necessary things.It's urgent for me.
send to my mail id : ravi_pinnoju@yahoo.co.in
Regards,
Ravi
Hello,
The given code is sending the SMS perfectly but when i read the sms its not showing any sms and show "0 messages read." either its not showing any message when sms received. however sim shows the messages when i use AT commands on Hyperterminal. i am using a GSM Modem with serial port.
can you please resolve this issue. i'll b really thankful to you.
Zeeshan Saeed.
Hi,
Try to find out what all things happens inside
with GSMComm's logging mechanism by handling LoglineAdded event. I posted a snippet in this forum messages.
Thanks,
Ranjan.D
Hello,
The aim of my project is to actually create a sms service whereby people can send in their sms for eg. <wakeup> to +123456789 and it will automatically send a sms to the person from a database at the destinated time, which is like an automated service. Right now, I am having problems with the sms library. I could only send sms text messages manually and I am unable to read sms-es stored in my mobile phone. Im using a nokia N80 currently as my gsm modem. I sincerely hope you can help me out with this project.You can contact me back at shinnching@gmail.com / munkit13@hotmail.com / xiaochanel@yahoo.com.
Thank you
everything is fine. i am able to send as well as receive message.
I am really thankful to both Ranjan and Stefan Mayr
i am using visual studio 2005 version 8.0.50727.42
.NET framework version 2.0.50727
when i modified ranjans source code, i am getting an FileNotFoundException saying
Couldnot load file or assembly 'RS232,Version=1.24.0.0,Culture=neutral,PublickeyToken=515d87df384dc81 or one of its dependencies.The system cannot find the file specified.