📄 form1.cs
字号:
this.Button5.TabIndex = 8;
this.Button5.Text = "接收短信";
this.Button5.Click += new System.EventHandler(this.Button5_Click);
//
// jsnr
//
this.jsnr.Location = new System.Drawing.Point(112, 24);
this.jsnr.Multiline = true;
this.jsnr.Name = "jsnr";
this.jsnr.Size = new System.Drawing.Size(408, 56);
this.jsnr.TabIndex = 1;
this.jsnr.Text = "";
//
// Label6
//
this.Label6.Location = new System.Drawing.Point(24, 40);
this.Label6.Name = "Label6";
this.Label6.Size = new System.Drawing.Size(72, 23);
this.Label6.TabIndex = 0;
this.Label6.Text = "接收内容:";
//
// Button4
//
this.Button4.Location = new System.Drawing.Point(528, 504);
this.Button4.Name = "Button4";
this.Button4.TabIndex = 6;
this.Button4.Text = "退出";
this.Button4.Click += new System.EventHandler(this.Button4_Click);
//
// GroupBox2
//
this.GroupBox2.Controls.Add(this.sendState);
this.GroupBox2.Controls.Add(this.Label12);
this.GroupBox2.Controls.Add(this.Button3);
this.GroupBox2.Controls.Add(this.fsnr);
this.GroupBox2.Controls.Add(this.jshm);
this.GroupBox2.Controls.Add(this.Label5);
this.GroupBox2.Controls.Add(this.Label4);
this.GroupBox2.Location = new System.Drawing.Point(0, 192);
this.GroupBox2.Name = "GroupBox2";
this.GroupBox2.Size = new System.Drawing.Size(616, 144);
this.GroupBox2.TabIndex = 5;
this.GroupBox2.TabStop = false;
this.GroupBox2.Text = "发送短信测试";
//
// sendState
//
this.sendState.Checked = true;
this.sendState.CheckState = System.Windows.Forms.CheckState.Checked;
this.sendState.Location = new System.Drawing.Point(528, 56);
this.sendState.Name = "sendState";
this.sendState.Size = new System.Drawing.Size(80, 24);
this.sendState.TabIndex = 10;
this.sendState.Text = "状态报告";
//
// Label12
//
this.Label12.BackColor = System.Drawing.Color.Gainsboro;
this.Label12.Location = new System.Drawing.Point(24, 120);
this.Label12.Name = "Label12";
this.Label12.Size = new System.Drawing.Size(496, 16);
this.Label12.TabIndex = 7;
this.Label12.Text = "小灵通格式:本地:106+区号+号码;外地:106+0+区号+号码";
//
// Button3
//
this.Button3.Location = new System.Drawing.Point(528, 24);
this.Button3.Name = "Button3";
this.Button3.TabIndex = 5;
this.Button3.Text = "发送短信";
this.Button3.Click += new System.EventHandler(this.Button3_Click);
//
// fsnr
//
this.fsnr.Location = new System.Drawing.Point(112, 56);
this.fsnr.Multiline = true;
this.fsnr.Name = "fsnr";
this.fsnr.Size = new System.Drawing.Size(408, 56);
this.fsnr.TabIndex = 3;
this.fsnr.Text = "金仓短信标准接口(SDK2.x)让您在最短时间开发出短信应用,感谢您的选择!使用愉快!";
//
// jshm
//
this.jshm.Location = new System.Drawing.Point(112, 24);
this.jshm.Name = "jshm";
this.jshm.Size = new System.Drawing.Size(408, 21);
this.jshm.TabIndex = 2;
this.jshm.Text = "";
//
// Label5
//
this.Label5.Location = new System.Drawing.Point(24, 72);
this.Label5.Name = "Label5";
this.Label5.Size = new System.Drawing.Size(72, 32);
this.Label5.TabIndex = 1;
this.Label5.Text = "发送内容:";
//
// Label4
//
this.Label4.Location = new System.Drawing.Point(24, 32);
this.Label4.Name = "Label4";
this.Label4.Size = new System.Drawing.Size(72, 24);
this.Label4.TabIndex = 0;
this.Label4.Text = "接收号码:";
//
// pb1
//
this.pb1.Location = new System.Drawing.Point(112, 506);
this.pb1.Name = "pb1";
this.pb1.Size = new System.Drawing.Size(248, 16);
this.pb1.TabIndex = 11;
//
// status1
//
this.status1.BackColor = System.Drawing.SystemColors.ScrollBar;
this.status1.Location = new System.Drawing.Point(368, 504);
this.status1.Name = "status1";
this.status1.Size = new System.Drawing.Size(152, 21);
this.status1.TabIndex = 10;
this.status1.Text = "";
//
// Label13
//
this.Label13.Location = new System.Drawing.Point(16, 507);
this.Label13.Name = "Label13";
this.Label13.Size = new System.Drawing.Size(56, 16);
this.Label13.TabIndex = 9;
this.Label13.Text = "状态信息";
//
// TestGSM
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(624, 533);
this.Controls.Add(this.pb1);
this.Controls.Add(this.status1);
this.Controls.Add(this.Label13);
this.Controls.Add(this.GroupBox3);
this.Controls.Add(this.Button4);
this.Controls.Add(this.GroupBox2);
this.Controls.Add(this.GroupBox1);
this.Name = "TestGSM";
this.Text = "金仓短信标准接口(SDK2.x)——C#开发示例";
this.Closing += new System.ComponentModel.CancelEventHandler(this.TestGSM_Closing);
this.Load += new System.EventHandler(this.TestGSM_Load);
this.GroupBox1.ResumeLayout(false);
this.GroupBox3.ResumeLayout(false);
this.GroupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new TestGSM());
}
//接收短信
private void Button5_Click(object sender, System.EventArgs e)
{
//1)接收短信
status1.Text = "正在接收短信,请稍等 ......";
pb1.Value = 50;
if(isClear.Checked)
jsnr.Text = GSMModem.GSMModemSMSReadAll(Device.Text,0);
else
jsnr.Text = GSMModem.GSMModemSMSReadAll(Device.Text,1);
//2)显示信息
cwxx.Text = GSMModem.GSMModemGetErrorMsg(Device.Text);
status1.Text = "接收短信完毕!";
pb1.Value = 100;
}
//退出示例
private void Button4_Click(object sender, System.EventArgs e)
{
this.Close();
}
//发送短信
private void Button3_Click(object sender, System.EventArgs e)
{
//0) 格式检查
if(jshm.Text == "")
{
MessageBox.Show("手机号码不能为空!","提示", MessageBoxButtons.OK);
jshm.Focus();
return;
}
if(fsnr.Text == "")
{
MessageBox.Show("短信内容不能为空!", "提示", MessageBoxButtons.OK);
fsnr.Focus();
return;
}
//2) 发送短信
int smslen;
status1.Text = "正在发送短信,请稍等 ......";
pb1.Value = 50;
smslen = System.Text.Encoding.Default.GetByteCount(fsnr.Text);
if(GSMModem.GSMModemSMSsend(Device.Text,null, 8, fsnr.Text, smslen, jshm.Text, sendState.Checked) == true)
MessageBox.Show("GSMModemSMSsend: 短信发送成功!", "提示", MessageBoxButtons.OK);
else
MessageBox.Show("GSMModemSMSsend: 短信发送失败!" + GSMModem.GSMModemGetErrorMsg(Device.Text), "提示", MessageBoxButtons.OK);
//3) 显示错误信息
cwxx.Text = GSMModem.GSMModemGetErrorMsg(Device.Text);
status1.Text = "发送短信完毕!";
pb1.Value = 100;
}
private void TestGSM_Load(object sender, System.EventArgs e)
{
}
//连接设备
private void Button6_Click(object sender, System.EventArgs e)
{
//1)输入参数检查
if(Device.Text == "")
{
MessageBox.Show("请指定通讯端口!","提示", MessageBoxButtons.OK);
Device.Focus();
return;
}
if(Baud.Text == "")
{
MessageBox.Show("请指定通讯波特率!","提示", MessageBoxButtons.OK);
Baud.Focus();
return;
}
if(sqhm.Text == "")
{
MessageBox.Show("请输入授权号码!","提示", MessageBoxButtons.OK);
sqhm.Focus();
return;
}
//2)连接设备
status1.Text = "正在连接通讯设备,请稍等 ......";
pb1.Value = 50;
if(GSMModem.GSMModemInit(Device.Text, Baud.Text, null, null, false, sqhm.Text)==true)
MessageBox.Show("GSMModemInit: 连接成功!","提示", MessageBoxButtons.OK);
else
{
MessageBox.Show("GSMModemInit: 连接失败!" + GSMModem.GSMModemGetErrorMsg(Device.Text),"提示", MessageBoxButtons.OK);
return;
}
//3)显示信息
cwxx.Text = GSMModem.GSMModemGetErrorMsg(Device.Text);
status1.Text = "连接完毕!";
pb1.Value = 100;
}
private void TestGSM_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
//关闭设备连接
if(GSMModem.GSMModemIsConn(Device.Text))
GSMModem.GSMModemRelease(Device.Text);
}
private void Button2_Click(object sender, System.EventArgs e)
{
cwxx.Text = GSMModem.GSMModemGetErrorMsg(Device.Text);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -