使用gsm调制解调器发送msm [英] send msm using a gsm modem

查看:101
本文介绍了使用gsm调制解调器发送msm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理消息传递应用程序

我有一个gsm调制解调器和设备usb rs232

我想通过我写的表单向您的手机发送私信

以下是我的代码

但它不起作用。

我的手机没有收到任何消息

I'm working on a messaging application
I have a gsm modem and device usb rs232
I want a private message to your phone from a form that I write
below is my code
but it don't work.
My phone does not receive any messages

namespace WindowsFormsApplication1
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void Form5_Load(object sender, EventArgs e)
        {
            _serialPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
            //_serialPort.Open();
            _response = string.Empty;
            _serialPort.RtsEnable = true;
            _serialPort.DataReceived += SerialPortDataReceived;

        }
        private static SerialPort _serialPort;
        private string _response;
        void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (e.EventType == SerialData.Chars)
            {
                _response += _serialPort.ReadLine();
            }
        }
        public bool IsReady()
        {
            try
            {
                if (!_serialPort.IsOpen)
                    _serialPort.Open();

                _serialPort.Write("AT\r");
                Thread.Sleep(3000);
            }
            catch
            {
                return false;
            }

            return _response.Contains("OK");
        }
        public static bool SendSms(string phoneNumber, string message)
        {
            try
            {
                if (!_serialPort.IsOpen)
                    _serialPort.Open();

                // Send
                _serialPort.Write("AT+CMGF=1\r");
                _serialPort.Write("AT+CMGS=\"" + phoneNumber + "\"\r\n");
                _serialPort.Write(message + "\x1A");
                return true;
            }
            catch
            {
                return false;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendSms(textBox1 .Text , textBox2 .Text );
        }

    }
}



非常感谢


thanks a lot

推荐答案

所以使用调试器,看看究竟发生了什么。

首先检查你的应用程序外部:使用终端程序连接到COM4,然后手动发送你正在尝试的内容从您的应用程序传输。



它有用吗?如果没有,那么你需要查看硬件/消息字符串。

如果是这样,请使用调试器来确切了解您的应用程序发送的内容以及您从移动设备获得的响应。 br $> b $ b

我们不能为您做到这一点:我们无法从这里访问您的手机!

但是...那是一些糟糕的代码:你永远不会看到调制解调器是否响应,以及它是否正在向你发送回来。



我很想开始在文本框中显示传入的数据,以便我可以查看它,看看是否有任何错误,至少在开始时。
So use the debugger, and see exactly what is going on.
Start by checking outside your app: use a terminal program to connect to COM4, and manually send exactly what you are trying to transmit from your app.

Does it work? If not, then you need to look at hardware / the message strings.
When it does, use the debugger to see exactly what your app is sending, and what responses you are getting from the mobile.

We can't do that for you: we aren't able to access your phone from here!
But...that's some poor code: you never look to see if the modem is responding at all, and if it is what it is sending you back.

I'd be tempted to start with displaying the incoming data in a textbox so I could review it and see if there were any errors, at least in the beginning.


这篇关于使用gsm调制解调器发送msm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆