|
Hi,
I am really Sorry for my late reply.
If you are using GSM phone then you have to buy USB serial cable or adapter,
Else If you are using GSM modems like WaveCom ( good modem ) you can use USB serial convertor which will convert USB to Serial.
You can ask near by shops for USB to Serial cable for your mobile.
If you have any doubts or queries feel free to any with me .
Thanks,
Ranjan.D
modified on Thursday, January 29, 2009 10:15 AM
|
|
|
|
|
ok,this evening i borrowed a sony erricson k530i and connected it with a data cable and ran ur application.i'am able to send sms.read messages from sim but 2 problems
1.when i select the delete option ..no grid is displayed.
2.if i recieve a message...it is not displaying as recieved messages in the main window..
|
|
|
|
|
HI,
Lot of peoples are facing same problem they tell with me they can send SMS but not in case of receive.
Will you try one thing Please connect your Phone with Windows HyperTerminal.
I already mentioned in this forum how to connect and check with AT commands
to check whether you can read SMS.
You can check for subject : Re: Problem in receiving message.. in this forum
I replayed.
I suggest you can go for WaveCom modem, You will have a lot of control over you GSM modem
This is my friends reply , she used GSM phone:
if you want test this project with GSM phone, please ensure you use cable can convert to serial. With Nokia 3500 have used DKE-2 cable which is UBS straight usb, differ with DKU-5 cable.
You can change phone which use DKU-5 serial port or USB port.Then test with this project.
Thanks,
Ranjan.D
|
|
|
|
|
Hi,
U can solve problem when show data on textbox and Receive SMS too. Grid will make ur project hard and some error.
Thanks,
|
|
|
|
|
my project idea is this:
student has to send a preformatted sms (like ATTEND name)to my number and he'll get a sms about his attendence details.but before that he has to come to my portal and register.this is all.if the basic function,that is READING AN SMS,PROCESSING IT,AND SENDING SMS.works the whole application can be done easily..
so pls give me guidence in the sms communication module,cuz i'm new to this ..and i'm a bit scarry hearing all sourts of words like AT commands,Windows Hyperterminal.etc...
pls help...
|
|
|
|
|
hi,
i saw ur article and want to implement it as my final year project with a lot of alterations.can i implement the same thing in creating a web based application?
one more thing i want to know is : which will be less complicated to use ? a gsm modem or a cell phone?
i connected my phone with a bluetooth and sucessfully sent msgs from my mobile..and i know it wont work with reading msgs...
i'll be really helpful if u reply me soon as ,i have to buy either a gsm modem or a mobile(cuz my mobile supports only bluetooth(nokia 2760))
regards
john.
|
|
|
|
|
Hi,
Is there any licensing involved in using GSM gateway & programming AT?
|
|
|
|
|
Hi,
GSM gateway can be easily done by integrating hardware components. Say if you want to make one GSM modem to send/receive SMS you can get ready made chips etc and it can be done and its your own product.
When you use GSM modems like WaveComm, you are just purchasing the modem and its licensed to WaveComm.
AT Command is Implemented by GSM modem manufactures. All license goes to them.
With the help of AT commands only its possible to send/receive SMS problematically.
You no need to bother , you can just use it.
Thanks,
Ranjan.D
|
|
|
|
|
Thanks for your reply. Is there any INdian Mobile Service provider who provide GSM modem like Airtel? Will it be Windows based/ web based?
|
|
|
|
|
Hi Vidhya,
I dont know in specific about your requirement , can you please tell me more about what exactly you want.
I dont know exactly if Airtel manufactures GSM modem , but the one which I know and used is WaveComm. The GSM modem is similar to our phone (GSM/CDMA) the only difference is it dont have Keypad interface, all you have to do is programatically you can control modem.
There are private SMS gateways which you provide service like Webserive or Web based application software using which you can send SMS directly through their SMSC Servers. You no need to bother how SMS is send.
Some companies provide u API's using which you can connect your GSM modem and can send/receive SMS easily.
The one which I used is WaveCom it can send 8 to 10 SMS with in min thats limitation. If you want to send SMS i.e bulk then you go for Bulk service providers
or with IP gateways, these gateways directly connect to Short Message Service Center (SMSC) of the SMS service providers using one of the following protocols: SMPP, UCP/EMI, CIMD2
Thanks,
Ranjan.D
|
|
|
|
|
does GSM library support tools for USB port??
i m connecting my GSM phone through USB.. but in the application u have used the serial port... so i need to buy USB to serial port converter...
is ther ne other option???
|
|
|
|
|
like to ask one more thing...
will nokia 6300 be able to send message as well as receiver message???
please reply asap....
i want to start creating my site as soon as possible..
so pls reply fast...
|
|
|
|
|
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
|
|
|
|
|