从Windows窗体应用程序发送SMS

时间:2018-03-16 22:18:42

标签: c# asp.net networking network-programming message

我想从我在Windows Forms应用程序上开发的应用程序发送短信,实现此任务的麻烦是获得端口号,我在一周内受到这个问题的困扰,请指导我,我&# 39;发送上传我的代码,更重要的是我在手机上使用Android操作系统安装了SIM卡,设备供应商是华为。非常感谢提前......

private void button1_Click(object sender, EventArgs e)
    {
        GsmCommMain comm;
        int portn = 0;
        System.IO.Ports.SerialPort _srp = new System.IO.Ports.SerialPort();
        try
        {
            Cursor.Current = Cursors.Cross;

            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_SerialPort");
            Cursor = Cursors.WaitCursor;
            foreach (System.Management.ManagementObject queryObj in searcher.Get())
            {
                Cursor = Cursors.Hand;

                StatusLabel.Text = "Just Enterd in foreach Block...";

                if (queryObj != null)
                {
                    Cursor = Cursors.UpArrow;

                    object captionObj = queryObj["DESCRIPTION"];//Model Name
                    object capdeviceid = queryObj["DEVICEID"];//Comm port
                    object MaxBaudRate = queryObj["MAXBAUDRATE"];
                    object connstatus = queryObj["STATUS"];
                    object ct = queryObj.ToString();
                    int timeoutsec = 300;
                    StatusLabel.Text = "USB Modem Condition Main Enter Na Ho Saki...";

                    if (captionObj.ToString().Contains("USB Modem"))
                    {
                        _srp.PortName = capdeviceid.ToString();
                        portn = Convert.ToInt32(capdeviceid.ToString().Substring(3));
                        label1.Text = _srp.PortName + " ,,, " + portn;
                        comm = new GsmComm.GsmCommunication.GsmCommMain(portn, Convert.ToInt32(MaxBaudRate), timeoutsec);
                        StatusLabel.Text = "USB Modem Condition Main Entry...";

                        comm.Open();
                        if (comm.IsOpen())
                            btnSMSConnect.BackColor = Color.Green;
                        MessageBox.Show("Not Opening..." );
                        StatusLabel.Text = "Not Opening...";


                    }
                }
            }
        }
        catch (Exception e15)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e15.Message);
            btnSMSConnect.BackColor = Color.Transparent;
            //comm.Close();
            _srp.Close();
        }
    }
}

}

0 个答案:

没有答案