📄 duanxinmokuaidemo.cs
字号:
"115200",
"57600",
"4800"});
this.comboBox1.Location = new System.Drawing.Point(96, 3);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(72, 20);
this.comboBox1.TabIndex = 30;
this.comboBox1.Text = "comboBox1";
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 351);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.linkStat,
this.statusBarPanel3,
this.centerNo});
this.statusBar1.ShowPanels = true;
this.statusBar1.Size = new System.Drawing.Size(472, 22);
this.statusBar1.TabIndex = 31;
this.statusBar1.Text = "statusBar1";
//
// statusBarPanel1
//
this.statusBarPanel1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanel1.Name = "statusBarPanel1";
this.statusBarPanel1.Text = "连接状态:";
this.statusBarPanel1.Width = 65;
//
// linkStat
//
this.linkStat.Name = "linkStat";
//
// statusBarPanel3
//
this.statusBarPanel3.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanel3.Name = "statusBarPanel3";
this.statusBarPanel3.Text = "短信中心号:";
this.statusBarPanel3.Width = 75;
//
// centerNo
//
this.centerNo.Name = "centerNo";
this.centerNo.Width = 150;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 8);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 16);
this.label2.TabIndex = 32;
this.label2.Text = "串口波特率:";
//
// button11
//
this.button11.Location = new System.Drawing.Point(176, 4);
this.button11.Name = "button11";
this.button11.Size = new System.Drawing.Size(75, 23);
this.button11.TabIndex = 33;
this.button11.Text = "检测波特率";
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// ReportBox
//
this.ReportBox.AutoSize = true;
this.ReportBox.Location = new System.Drawing.Point(368, 132);
this.ReportBox.Name = "ReportBox";
this.ReportBox.Size = new System.Drawing.Size(72, 16);
this.ReportBox.TabIndex = 34;
this.ReportBox.Text = "状态报告";
this.ReportBox.UseVisualStyleBackColor = true;
this.ReportBox.CheckedChanged += new System.EventHandler(this.ReportBox_CheckedChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 373);
this.Controls.Add(this.ReportBox);
this.Controls.Add(this.button11);
this.Controls.Add(this.label2);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.numBox);
this.Controls.Add(this.label7);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.linkBtn);
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.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Closed += new System.EventHandler(this.Form1_Closed);
((System.ComponentModel.ISupportInitialize)(this.numBox)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.linkStat)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.centerNo)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#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.SetText("\r\n received:" + info.IndexNo.ToString() + "," + info.SaveAt + "\r\n");
this.SetText("短信内容:" + info.SMS.SMSText + "\r\n");
this.SetText("发送方号码:" + info.SMS.PhoneNumber + "\r\n");
this.SetText("服务时间:" + info.SMS.ServiceTime.ToString() + "\r\n");
this.SetText("短信中心号" + info.SMS.ServiceCenterNumber + "\r\n");
}
private void button5_Click(object sender, System.EventArgs e)
{
int i = int.Parse(this.indexBox.Text);
SmsClass 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.PhoneNumber + "\r\n";
this.backBox.Text += "时间:" + RecdSms.ServiceTime.ToString() + "\r\n";
this.backBox.Text += "中心:" + RecdSms.ServiceCenterNumber + "\r\n";
this.backBox.Text += "状态:";
switch (RecdSms.Status)
{
case SmsStatus.REC_READ:
this.backBox.Text += "已读的\r\n";
break;
case SmsStatus.REC_UNREAD:
this.backBox.Text += "未读的\r\n";
break;
case SmsStatus.STO_SEND:
this.backBox.Text += "草搞\r\n";
break;
case SmsStatus.STO_UNSEND:
this.backBox.Text += "已发送的\r\n";
break;
}
}
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.centerNo.Text = myModem.ServiceCenterNumber;
}
else
this.linkStat.Text = "连接失败";
}
}
private void Form1_Closed(object sender, System.EventArgs e)
{
if (myModem.IsConnected)
myModem.DisconnectModem();
}
private void button6_Click(object sender, System.EventArgs e)
{
myModem.SetComPortParameter(115200,8,0,1);
}
private void button7_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 myModem_OnCommandFinish(object sender, Sindasoft.GsmModem.GsmModemClass.CommandFinishEventArgs e)
{
GsmModemClass.CommandQueueItem cqi;
cqi = e.CmdItem;
if (this.exeCmdList.ContainsKey(cqi.CommandId))
this.exeCmdList.Remove(cqi.CommandId);
this.SetText("执行命令:" + cqi.CommandString + "......");
int sendres = cqi.ResultCode;
if (sendres == 0)
{
this.SetText("(执行成功)\r\n");
}
else if (sendres == 1)
{
this.SetText("(fall)\r\n");
}
else if (sendres == 2)
{
this.SetText("(Timeout)\r\n");
}
else if (sendres ==3)
{
this.SetText("(PortClosed)\r\n");
}
this.SetText("返回:" + cqi.CommandBackString);
}
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.backBox.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.backBox.Text += text;
}
}
private void button8_Click(object sender, System.EventArgs e)
{
GsmModemClass.CommandQueueItem cqi = myModem.SendSMS(this.phoneBox.Text,this.smsBox.Text);
this.exeCmdList.Add(cqi.CommandId,cqi);
}
private void button9_Click(object sender, System.EventArgs e)
{
GsmModemClass.CommandQueueItem cqi = myModem.SendSMS(int.Parse(this.indexBox.Text),this.phoneBox.Text);
this.exeCmdList.Add(cqi.CommandId,cqi);
}
private void button10_Click(object sender, System.EventArgs e)
{
PhoneBookForm pbf = new PhoneBookForm(this.myModem.PhoneBook);
pbf.Show();
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
myModem.SetComPortParameter(int.Parse(this.comboBox1.SelectedItem.ToString()),8,0,1);
}
private void button11_Click(object sender, System.EventArgs e)
{
int[] brs = myModem.CheckBaudRate(true);
this.comboBox1.Items.Clear();
foreach (int i in brs)
{
this.comboBox1.Items.Add(i.ToString());
}
if (this.comboBox1.Items.Count > 0)
this.comboBox1.SelectedIndex = 0;
}
private void ReportBox_CheckedChanged(object sender, EventArgs e)
{
this.myModem.SmsReportRecrived = this.ReportBox.Checked;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -