I devloped an asp.net application to send sms from gsm modem to destination base on URL from the browser I used a library that developed by codeproject http://www.codeproject.com/articles/20420/how-to-send-and-receive-sms-using-gsm-modem
but I get problem when I request form two browsers at same time and I want to make the my code detect that the modem is use by another process at the time
here is my code:
DeviceConnection deviceConnection = new DeviceConnection();
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Request.QueryString["destination"] != null && Request.QueryString["text"] != null)
{
deviceConnection.setBaudRate(9600);
deviceConnection.setPort(12);
deviceConnection.setTimeout(200);
SendSms sendSms = new SendSms(deviceConnection);
if (deviceConnection.getConnectionStatus())
{
sendSms.strReciverNo = Request.QueryString["destination"];
sendSms.strTextMessage = Request.QueryString["text"];
if (sendSms.sendSms())
{
Response.Write("Mesage successfuly sent to " + Request.QueryString["destination"]);
}
else
{
Response.Write("Message was not sent");
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Index "+ex.StackTrace);
}
}
This is SendSms class:
class SendSms
{
DeviceConnection deviceConnection;
public SendSms(DeviceConnection deviceConnection)
{
this.deviceConnection = deviceConnection;
}
private string reciverNo;
private string textMessage;
private delegate void SetTextCallback(string text);
public string strReciverNo
{
set
{
this.reciverNo = value;
}
get
{
return this.reciverNo;
}
}
public string strTextMessage
{
set
{
this.textMessage = value;
}
get
{
return this.textMessage;
}
}
public bool sendSms()
{
try
{
CommSetting.Comm_Port = deviceConnection.getPort();//GsmCommMain.DefaultPortNumber;
CommSetting.Comm_BaudRate = deviceConnection.getBaudRate();
CommSetting.Comm_TimeOut = deviceConnection.getTimeout();//GsmCommMain.DefaultTimeout;
CommSetting.comm = new GsmCommMain(deviceConnection.getPort()
, deviceConnection.getBaudRate(), deviceConnection.getTimeout());
// CommSetting.comm.PhoneConnected += new EventHandler(comm_PhoneConnected);
if (!CommSetting.comm.IsOpen())
{
CommSetting.comm.Open();
}
SmsSubmitPdu smsSubmitPdu = new SmsSubmitPdu(strTextMessage, strReciverNo, "");
smsSubmitPdu.RequestStatusReport = true;
CommSetting.comm.SendMessage(smsSubmitPdu);
CommSetting.comm.Close();
return true;
}
catch (Exception exception)
{
Console.WriteLine("sendSms " + exception.StackTrace);
CommSetting.comm.Close();
return false;
}
}
public void recive(object sender, EventArgs e)
{
Console.WriteLine("Message received successfuly");
}
}
}