📄 form1.cs
字号:
this.label6.TabIndex = 19;
this.label6.Text = "接收方号码:";
//
// phoneBox
//
this.phoneBox.Location = new System.Drawing.Point(24, 96);
this.phoneBox.Name = "phoneBox";
this.phoneBox.TabIndex = 20;
this.phoneBox.Text = "13935993594";
//
// cnLab
//
this.cnLab.Location = new System.Drawing.Point(248, 8);
this.cnLab.Name = "cnLab";
this.cnLab.Size = new System.Drawing.Size(200, 16);
this.cnLab.TabIndex = 21;
//
// linkBtn
//
this.linkBtn.Location = new System.Drawing.Point(168, 4);
this.linkBtn.Name = "linkBtn";
this.linkBtn.Size = new System.Drawing.Size(64, 23);
this.linkBtn.TabIndex = 22;
this.linkBtn.Text = "连接";
this.linkBtn.Click += new System.EventHandler(this.linkBtn_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(368, 56);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(64, 23);
this.button6.TabIndex = 23;
this.button6.Text = "异步执行";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// label7
//
this.label7.Location = new System.Drawing.Point(336, 40);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(56, 16);
this.label7.TabIndex = 24;
this.label7.Text = "执行次数";
//
// numBox
//
this.numBox.Location = new System.Drawing.Point(392, 32);
this.numBox.Maximum = new System.Decimal(new int[] {
1000,
0,
0,
0});
this.numBox.Minimum = new System.Decimal(new int[] {
1,
0,
0,
0});
this.numBox.Name = "numBox";
this.numBox.Size = new System.Drawing.Size(48, 21);
this.numBox.TabIndex = 25;
this.numBox.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
//
// button7
//
this.button7.Location = new System.Drawing.Point(368, 96);
this.button7.Name = "button7";
this.button7.Size = new System.Drawing.Size(64, 23);
this.button7.TabIndex = 26;
this.button7.Text = "异步发送";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 373);
this.Controls.Add(this.button7);
this.Controls.Add(this.numBox);
this.Controls.Add(this.label7);
this.Controls.Add(this.button6);
this.Controls.Add(this.linkBtn);
this.Controls.Add(this.cnLab);
this.Controls.Add(this.phoneBox);
this.Controls.Add(this.indexBox);
this.Controls.Add(this.smsBox);
this.Controls.Add(this.rChk);
this.Controls.Add(this.backBox);
this.Controls.Add(this.cmdBox);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.label4);
this.Controls.Add(this.eofChk);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.nChk);
this.Controls.Add(this.label3);
this.Controls.Add(this.linkStat);
this.Controls.Add(this.label2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.numBox)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
string cmdText = this.cmdBox.Text;
if (this.rChk.Checked)
cmdText += "\r";
if (this.nChk.Checked)
cmdText += "\n";
if (this.eofChk.Checked)
cmdText += (char)26;
string ret;
for (int i = 0 ; i < this.numBox.Value;i++)
{
int sendres = myModem.AtOnceATCommand(cmdText,out ret);
if (sendres == 0)
{
this.backBox.Text += "执行:" + this.cmdBox.Text + "...(执行成功)\r\n";
}
else if (sendres == 1)
{
this.backBox.Text += "执行:" + this.cmdBox.Text + "...(fall)\r\n";
}
else if (sendres == 2)
{
this.backBox.Text += "执行:" + this.cmdBox.Text + "...(Timeout)\r\n";
}
else if (sendres ==3)
{
this.backBox.Text += "执行:" + this.cmdBox.Text + "...(PortClosed)\r\n";
}
this.backBox.Text += "返回:" + ret;
}
}
private void button3_Click(object sender, System.EventArgs e)
{
this.backBox.Text = "";
}
private void button4_Click(object sender, System.EventArgs e)
{
int r =myModem.AtOnceSendSMS("13935993594",this.smsBox.Text);
if (r == 0)
{
this.backBox.Text += "短信发送成功。\r\n";
}
else
{
this.backBox.Text += "短信发送失败\r\n";
if (r == 1)
this.backBox.Text += "原因:设备返回错误信息。\r\n";
if (r == 2)
this.backBox.Text += "原因:超时。\r\n";
if (r == 3)
this.backBox.Text += "原因:串口没有打开。\r\n";
}
}
private void myModem_OnReceivedSms(object sender, GsmModemClass.NewSmsEventArgs info)
{
this.backBox.Text += "\r\n received:" + info.IndexNo.ToString() + "," + info.SaveAt + "\r\n";
}
private void button5_Click(object sender, System.EventArgs e)
{
int i = int.Parse(this.indexBox.Text);
GsmModemClass.ReceivedSmsClass RecdSms;
int r = myModem.ReadSMS(i,out RecdSms);
if (r == 0)
{
this.backBox.Text += "\r\n读取成功\r\n";
this.backBox.Text += "内容:" + RecdSms.SMSText + "\r\n";
this.backBox.Text += "号码:" + RecdSms.SourcePhoneNumber + "\r\n";
this.backBox.Text += "时间:" + RecdSms.ServiceTime.ToString() + "\r\n";
this.backBox.Text += "中心:" + RecdSms.ServiceCenterNumber + "\r\n";
}
else
this.backBox.Text += "\r\n读取失败\r\n";
}
private void button2_Click(object sender, System.EventArgs e)
{
int i = int.Parse(this.indexBox.Text);
if (myModem.RemoveSMS(i) == 0)
this.backBox.Text += "删除第" + i.ToString() + "条短信成功\r\n";
else
this.backBox.Text += "删除第" + i.ToString() + "条短信失败\r\n";
}
private void linkBtn_Click(object sender, System.EventArgs e)
{
if (myModem.IsConnected)
{
myModem.DisconnectModem();
this.linkBtn.Text = "连接";
this.linkStat.Text = "无连接";
}
else
{
int con = myModem.ConnectModem();
if (con == 0)
{
this.linkStat.Text = "已连接";
this.linkBtn.Text = "断开";
this.cnLab.Text = "短信中心号:" + myModem.ServiceCenterNumber;
}
else
this.linkStat.Text = "连接失败";
}
}
private void myModem_OnCommandFinish(object sender, Sindasoft.GsmModem.GsmModemClass.CommandFinishEventArgs e)
{
GsmModemClass.CommandQueueItem cqi;
cqi = e.CmdItem;
this.exeCmdList.Remove(cqi.CommandId);
this.backBox.Text += "执行命令:" + cqi.CommandString + "......";
int sendres = cqi.ResultCode;
if (sendres == 0)
{
this.backBox.Text += "(执行成功)\r\n";
}
else if (sendres == 1)
{
this.backBox.Text += "(fall)\r\n";
}
else if (sendres == 2)
{
this.backBox.Text += "(Timeout)\r\n";
}
else if (sendres ==3)
{
this.backBox.Text += "(PortClosed)\r\n";
}
this.backBox.Text += "返回:" + cqi.CommandBackString;
}
private void button6_Click(object sender, System.EventArgs e)
{
string cmdText = this.cmdBox.Text;
if (this.rChk.Checked)
cmdText += "\r";
if (this.nChk.Checked)
cmdText += "\n";
if (this.eofChk.Checked)
cmdText += (char)26;
GsmModemClass.CommandQueueItem cqi;
for (int i = 0 ; i < this.numBox.Value;i++)
{
cqi = myModem.SendATCommand(cmdText);
this.exeCmdList.Add(cqi.CommandId,cqi);
}
}
private void button7_Click(object sender, System.EventArgs e)
{
GsmModemClass.CommandQueueItem cqi = myModem.SendSMS(this.phoneBox.Text,this.smsBox.Text);
this.exeCmdList.Add(cqi.CommandId,cqi);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -