我开发了一个 asp.net 应用程序,根据浏览器中的 URL 从 gsm 调制解调器向目标发送短信我使用了由 codeproject http://www.codeproject.com/articles/20420/how-to-send-and开发的库-receive-sms-using-gsm-modem
但是当我同时请求两个浏览器时遇到问题,我想让我的代码检测到调制解调器当时被另一个进程使用这是我的代码:
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);
}
}
这是 SendSms 类:
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");
}
}
}