sp.DtrEnable=true; sp.RtsEnable=true; sp.NewLine=Environment.NewLine; sp.Open(); int-mSpeed=1; sp.Write(“AT+CMGF=1”+Environment.NewLine); 系统线程线程睡眠(200); sp.Write(“AT+CSCS=GSM”+Environment.NewLine); 系统线程线程睡眠(200); sp.Write(“AT+CMGS=”+(char)34+“+91”+MobNo +(char)34+环境(新行); 系统线程线程睡眠(200); sp.Write(Msg+(char)26); 系统线程线程睡眠(mSpeed); IsSendEndIndex=真;R } catchstring Msg=MessageBody.Substring(StartIndex,EndIndex); SerialPort sp=新的SerialPort(); 对于(int q=0;q>@斯波克探员请学习如何格式化您的代码,以便您以外的任何人都能理解。不要只是复制粘贴。请格式化代码好吗?我必须从我的c#应用程序发送短信,我真的需要代码。>>@Agent_Spock/**像这样访问上面的类**/string[]ports=SerialPort.GetPortNames();foreach(端口中的字符串端口){SMS sm=new SMS(端口);sm.Opens();sm.sendSMS(,);sm.Closes();}/**像这样访问上面的类**/string[]ports=SerialPort.GetPortNames();foreach(端口中的字符串端口){SMS sm=new SMS(端口);sm.Opens();sm.sendSMS(,);sm.Closes();} using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.IO.Ports; namespace WindowsFormsApplication1 { public class SMS { SerialPort serialPort; //Initialize the Port public SMS(string comPort) { this.serialPort = new SerialPort(); this.serialPort.PortName = comPort; this.serialPort.BaudRate = 9600; this.serialPort.Parity = Parity.None; this.serialPort.DataBits = 8; this.serialPort.StopBits = StopBits.One; this.serialPort.Handshake = Handshake.RequestToSend; this.serialPort.DtrEnable = true; this.serialPort.RtsEnable = true; this.serialPort.NewLine = System.Environment.NewLine; } //create and send SMS public bool sendSMS(string cellNo, string sms) { string messages = null; messages = sms; if (this.serialPort.IsOpen == true) { try { this.serialPort.WriteLine("AT" + (char)(13)); Thread.Sleep(4); this.serialPort.WriteLine("AT+CMGF=1" + (char)(13)); Thread.Sleep(5); this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\""); Thread.Sleep(10); this.serialPort.WriteLine("" + messages + (char)(26)); } catch (Exception ex) { ex.ToString(); } return true; } else return false; } public void Opens() { try { if (this.serialPort.IsOpen == false) { this.serialPort.Open(); } } catch (Exception ex) { ex.ToString(); } } using System.IO.Ports; using System.Threading; private SerialPort _serialPort; _serialPort = new SerialPort(comboBoxEdit3.Text, 115200); Thread.Sleep(100); _serialPort.Open(); Thread.Sleep(100); _serialPort.Write("AT+CMGF=1\r"); Thread.Sleep(100); _serialPort.Write("AT+CMGS=\"" + number + "\"\r\n"); Thread.Sleep(100); _serialPort.Write(messages + "\x1A"); Thread.Sleep(300); MessageBox.Show("Password Sent on your Mobile !!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); _serialPort.Close();
//使用以下方法sp.DtrEnable=true; sp.RtsEnable=true; sp.NewLine=Environment.NewLine; sp.Open(); int-mSpeed=1; sp.Write(“AT+CMGF=1”+Environment.NewLine); 系统线程线程睡眠(200); sp.Write(“AT+CSCS=GSM”+Environment.NewLine); 系统线程线程睡眠(200); sp.Write(“AT+CMGS=”+(char)34+“+91”+MobNo +(char)34+环境(新行); 系统线程线程睡眠(200); sp.Write(Msg+(char)26); 系统线程线程睡眠(mSpeed); IsSendEndIndex=真;R } catchstring Msg=MessageBody.Substring(StartIndex,EndIndex); SerialPort sp=新的SerialPort(); 对于(int q=0;q>@斯波克探员请学习如何格式化您的代码,以便您以外的任何人都能理解。不要只是复制粘贴。请格式化代码好吗?我必须从我的c#应用程序发送短信,我真的需要代码。>>@Agent_Spock/**像这样访问上面的类**/string[]ports=SerialPort.GetPortNames();foreach(端口中的字符串端口){SMS sm=new SMS(端口);sm.Opens();sm.sendSMS(,);sm.Closes();}/**像这样访问上面的类**/string[]ports=SerialPort.GetPortNames();foreach(端口中的字符串端口){SMS sm=new SMS(端口);sm.Opens();sm.sendSMS(,);sm.Closes();} using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.IO.Ports; namespace WindowsFormsApplication1 { public class SMS { SerialPort serialPort; //Initialize the Port public SMS(string comPort) { this.serialPort = new SerialPort(); this.serialPort.PortName = comPort; this.serialPort.BaudRate = 9600; this.serialPort.Parity = Parity.None; this.serialPort.DataBits = 8; this.serialPort.StopBits = StopBits.One; this.serialPort.Handshake = Handshake.RequestToSend; this.serialPort.DtrEnable = true; this.serialPort.RtsEnable = true; this.serialPort.NewLine = System.Environment.NewLine; } //create and send SMS public bool sendSMS(string cellNo, string sms) { string messages = null; messages = sms; if (this.serialPort.IsOpen == true) { try { this.serialPort.WriteLine("AT" + (char)(13)); Thread.Sleep(4); this.serialPort.WriteLine("AT+CMGF=1" + (char)(13)); Thread.Sleep(5); this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\""); Thread.Sleep(10); this.serialPort.WriteLine("" + messages + (char)(26)); } catch (Exception ex) { ex.ToString(); } return true; } else return false; } public void Opens() { try { if (this.serialPort.IsOpen == false) { this.serialPort.Open(); } } catch (Exception ex) { ex.ToString(); } } using System.IO.Ports; using System.Threading; private SerialPort _serialPort; _serialPort = new SerialPort(comboBoxEdit3.Text, 115200); Thread.Sleep(100); _serialPort.Open(); Thread.Sleep(100); _serialPort.Write("AT+CMGF=1\r"); Thread.Sleep(100); _serialPort.Write("AT+CMGS=\"" + number + "\"\r\n"); Thread.Sleep(100); _serialPort.Write(messages + "\x1A"); Thread.Sleep(300); MessageBox.Show("Password Sent on your Mobile !!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); _serialPort.Close();,c#,asp.net,sms,C#,Asp.net,Sms,//使用以下方法 using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.IO.Ports; namespace WindowsFormsApplication1 { public class SMS { SerialPort serialPort; //Initialize the Port public SMS(s
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public class SMS
{
SerialPort serialPort;
//Initialize the Port
public SMS(string comPort)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = comPort;
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;
this.serialPort.DtrEnable = true;
this.serialPort.RtsEnable = true;
this.serialPort.NewLine = System.Environment.NewLine;
}
//create and send SMS
public bool sendSMS(string cellNo, string sms)
{
string messages = null;
messages = sms;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT" + (char)(13));
Thread.Sleep(4);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(5);
this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
Thread.Sleep(10);
this.serialPort.WriteLine("" + messages + (char)(26));
}
catch (Exception ex)
{
ex.ToString();
}
return true;
}
else return false;
}
public void Opens()
{
try
{
if (this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
catch (Exception ex)
{
ex.ToString();
}
}
//使用以下方法
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public class SMS
{
SerialPort serialPort;
//Initialize the Port
public SMS(string comPort)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = comPort;
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;
this.serialPort.DtrEnable = true;
this.serialPort.RtsEnable = true;
this.serialPort.NewLine = System.Environment.NewLine;
}
//create and send SMS
public bool sendSMS(string cellNo, string sms)
{
string messages = null;
messages = sms;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT" + (char)(13));
Thread.Sleep(4);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(5);
this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
Thread.Sleep(10);
this.serialPort.WriteLine("" + messages + (char)(26));
}
catch (Exception ex)
{
ex.ToString();
}
return true;
}
else return false;
}
public void Opens()
{
try
{
if (this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
catch (Exception ex)
{
ex.ToString();
}
}
尝试发送ATI和reading response以验证通信发送ATI和reading response以验证通信请学习设置代码格式,以便您以外的任何人都能理解。不要只是复制粘贴。请格式化代码好吗?我必须从我的c#应用程序发送短信,我真的需要代码。>>@斯波克探员请学习如何格式化您的代码,以便您以外的任何人都能理解。不要只是复制粘贴。请格式化代码好吗?我必须从我的c#应用程序发送短信,我真的需要代码。>>@Agent_Spock/**像这样访问上面的类**/string[]ports=SerialPort.GetPortNames();foreach(端口中的字符串端口){SMS sm=new SMS(端口);sm.Opens();sm.sendSMS(,);sm.Closes();}/**像这样访问上面的类**/string[]ports=SerialPort.GetPortNames();foreach(端口中的字符串端口){SMS sm=new SMS(端口);sm.Opens();sm.sendSMS(,);sm.Closes();}
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;
namespace WindowsFormsApplication1
{
public class SMS
{
SerialPort serialPort;
//Initialize the Port
public SMS(string comPort)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = comPort;
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;
this.serialPort.DtrEnable = true;
this.serialPort.RtsEnable = true;
this.serialPort.NewLine = System.Environment.NewLine;
}
//create and send SMS
public bool sendSMS(string cellNo, string sms)
{
string messages = null;
messages = sms;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT" + (char)(13));
Thread.Sleep(4);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(5);
this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
Thread.Sleep(10);
this.serialPort.WriteLine("" + messages + (char)(26));
}
catch (Exception ex)
{
ex.ToString();
}
return true;
}
else return false;
}
public void Opens()
{
try
{
if (this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
catch (Exception ex)
{
ex.ToString();
}
}
using System.IO.Ports;
using System.Threading;
private SerialPort _serialPort;
_serialPort = new SerialPort(comboBoxEdit3.Text, 115200);
Thread.Sleep(100);
_serialPort.Open();
Thread.Sleep(100);
_serialPort.Write("AT+CMGF=1\r");
Thread.Sleep(100);
_serialPort.Write("AT+CMGS=\"" + number + "\"\r\n");
Thread.Sleep(100);
_serialPort.Write(messages + "\x1A");
Thread.Sleep(300);
MessageBox.Show("Password Sent on your Mobile !!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
_serialPort.Close();