我想使用宽带棒并在 VB.net 2012 中创建一个 C# 应用程序,它可以向单个/多个手机发送 SMS 消息。我目前已连接到 COM 端口,但无法发送任何消息。这是我的全部代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
using GsmComm.Server;
using GsmComm.Interfaces;
namespace myTEXT
{
public partial class Form1 : Form
{
private GsmCommMain comm;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void cmdSend_Click(object sender, EventArgs e)
{
SmsSubmitPdu pdu;
byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
pdu = new SmsSubmitPdu(txtMessage.Text, txtPhoneNumber.Text, dcs);
comm.SendMessage(pdu);
}
private void cmdConnect_Click(object sender, EventArgs e)
{
if (txtCommPort.Text == "")
{
MessageBox.Show("Invalid Port Number!");
}
else
{
comm = new GsmCommMain(txtCommPort.Text, 9600, 150);
Cursor.Current = Cursors.Default;
Cursor.Current = Cursors.WaitCursor;
comm.Open();
Cursor.Current = Cursors.Default;
MessageBox.Show("Connected!");
}
}
}
}
当我运行我的程序时,我可以连接到某个端口(对于我来说是 COM22)。但是当我尝试发送消息时,出现错误
CommException was unhandled
No phone connected.
怎么办?
感谢您的帮助! 快乐编码^_^
最佳答案
打开端口后,还要确保您已连接到将发送 SMS 的设备。这是代码...
private void cmdConnect_Click(object sender, EventArgs e)
{
if (txtCommPort.Text == "")
{
MessageBox.Show("Invalid Port Number!");
}
else
{
comm = new GsmCommMain(txtCommPort.Text, 9600, 150);
Cursor.Current = Cursors.Default;
Cursor.Current = Cursors.WaitCursor;
comm.Open();
Cursor.Current = Cursors.Default;
if (!comm.IsConnected())
{
MessageBox.Show("No phone connected.");
}
else
{
MessageBox.Show("Connected!");
}
}
}
关于c# - GsmCommMain - C# 中没有电话连接错误(使用宽带棒发送短信),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43339749/