c# - GsmCommMain - C# 中没有电话连接错误(使用宽带棒发送短信)

标签 c# android visual-studio-2012 sms

我想使用宽带棒并在 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/

相关文章:

android - 如何在位图上应用不同的图像效果(滤镜),如棕褐色、黑白、模糊等?

使用ant进行Android构建编译导致错误 "UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.ArrayIndexOutOfBoundsException"

c++ - 从 C 程序访问 C++ 函数时,收到错误消息 "Access violation reading location"

c# - 将 Linq 查询返回到 KeyValuePair 的列表中

c# - mongodb c#更新嵌入式文档

c# - 在拖放过程中重绘

visual-studio-2010 - 从 Visual Studio 连接到 tfs Azure

c# - 如何通过LINQ遍历xml中的属性

java - Android 错误检索父级

c++ - OpenCV 的 Visual Studio 错误?