通过C#的GSMCOMM库发送短信 [英] Sending SMS Through GSMCOMM library of C#

查看:117
本文介绍了通过C#的GSMCOMM库发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了使用C#的GSMCOMM库发送短信的ac#应用程序,但是我面临的问题是三天是当我尝试使用gsmcomm objects.send message methode发送消息时,有时会给出异常该电话未连接,有时会给异常端口未打开. 我在下面共享我的代码: 用于将PC连接到电话gsm调制解调器的代码.有时,它发送消息时不会给出任何异常.
将电话连接到PC的代码.

I have develpoed a c# application for sending sms using GSMCOMM library of C# .But the problem which i am facing for three days is that when i tried to send the message using the gsmcomm objects.send message methode .Sometimes it gives exception that phone is not connected and sometimes it gives exception port not open. I am sharing my code below: Code for connecting pc to phone gsm modem.And sometime it send the message without giving any exception.
Code for connecting phone to pc.

private bool ConnectPhone() 
    {
        string conectionStr = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
        clsFileLogger.VerifyLogFileDirectory();
        clsFileLogger.WriteToLog("DB Connection: " + conectionStr);
        conn = new SqlConnection(@conectionStr);
        int port = Convert.ToInt32(ConfigurationSettings.AppSettings["port"]);
        int baudRate = Convert.ToInt32(ConfigurationSettings.AppSettings["baudRate"]);
        int timeout = Convert.ToInt32(ConfigurationSettings.AppSettings["timeout"]);
        gsmComm = new GsmCommMain(port, baudRate, timeout);
        try
        {
            Isconnected = false;
            if (gsmComm.IsConnected() == false)
            {
                gsmComm.Open();
            }

            Isconnected = gsmComm.IsConnected();

            clsFileLogger.WriteToLog("\nConnected with GSM Modam");
        }
        catch (Exception)
        {
            clsFileLogger.WriteToLog("\nUnable to open the port.");
        }
        return Isconnected;
    }


以及发送短信的代码


And code for sending SMS

  if (gsmComm.IsConnected() == false)
                    {
                        this.ConnectPhone();
                    }

                    pdu = new SmsSubmitPdu(strSMS, cellNO, "");
                    gsmComm.SendMessage(pdu);

 catch (Exception ex)
                {

                    throw ex;
                }

推荐答案

尝试以下指南(对我有所帮助): http://www.codeproject.com/Articles/325731/Bulk-SMS-Sender http://www.codeproject .com/Articles/20420/如何使用GSM调制解调器发送和接收短信

Try these guides (it was helpful for me): http://www.codeproject.com/Articles/325731/Bulk-SMS-Sender http://www.codeproject.com/Articles/20420/How-To-Send-and-Receive-SMS-using-GSM-Modem

但是似乎您的COM端口打开问题不在您的代码中.尝试使用Teraterm应用之类的工具测试您的端口.并且请确保在您开始运行应用程序时端口未打开(在先前启动后端口可能仍处于打开状态).

But it seems that your problem with com-port opening isn't in your code. Try to test your port using something like Teraterm app. And be sure the port isn't open when you start to run your app (it may be still open after previous launching).

这篇关于通过C#的GSMCOMM库发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆