本文介绍了如何通过PC将短信发送到移动设备以连接移动设备到GSM调制解调器的PC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#工作,我想通过手机从我的应用程序发送消息到移动设备请帮助我

I m working in C# and I want to send Message to Mobile from My Application through my mobile Please Help me

推荐答案

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using MySql.Data.Types;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
    
     SerialPort _serialPort;
     StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
    _serialPort = new SerialPort();
     _serialPort.PortName = textBox2.Text;
     _serialPort.BaudRate = 2400;
     _serialPort.Parity = Parity.None;
     _serialPort.DataBits = 8;
     _serialPort.StopBits = StopBits.One;
     _serialPort.Handshake = Handshake.RequestToSend;
     string b;
     b = textBox1.Text;
     if (b.Length <= 158)
     {
         try
         {
             MySqlConnection con = new MySqlConnection();
             // SqlCommand com = new SqlCommand( "select * from p_sms",con);
             con.ConnectionString = "server=localhost;Database=sms;uid=root;pwd=root";
             con.Open();
             MySqlDataReader myReader = null;
             MySqlCommand myCommand = new MySqlCommand("select * from p_sms", con);
             myReader = myCommand.ExecuteReader();
             _serialPort.Open();
             while (myReader.Read())
             {
                 Thread.Sleep(5000);
                 string ph;
                 ph = myReader[0].ToString();
                MessageBox.Show(ph);
                
                 _serialPort.Write("at" + (char)13 + (char)13);
                 _serialPort.Write("at+cmgf=1" + (char)13 + (char)13);
                 _serialPort.Write("at+cmgs=\"" + ph + "\"" + (char)13 +(char)13);

                 _serialPort.Write(b + (char)26 + (char)26 + (char)13);
                // _serialPort.Write("");
             
             }
             _serialPort.Close();

             con.Close();
             textBox1.Text = "";
         }
         catch (Exception ex)
         {
             MessageBox.Show("chk out the hardware connected ");
         }
     }
     else
     {
         MessageBox.Show("text out of length.please enter a msg less then 160 characters");
     }
        
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //Form1.ActiveForm.Hide();
            new phone_no_table().Show();

        }
    }
}


这篇关于如何通过PC将短信发送到移动设备以连接移动设备到GSM调制解调器的PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 14:38