通过串行端口通过诺基亚手机发送短信

Sms via a nokia phone over a serial port(通过串行端口通过诺基亚手机发送短信)
本文介绍了通过串行端口通过诺基亚手机发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过诺基亚手机通过串口发送短信,这很容易通过腻子.nokia 文档 中的命令运行良好.

I'm trying to send a sms via a Nokia phone over serial which is easy enough via putty. The commands from the nokia documentation works fine.

但是,尝试从 c# 应用程序发送相同的命令失败了.我已经运行了 Sysinternals PortMon 并且可以看到命令通过正常,我可以看到的唯一区别是它的连接方式,但我很难找到可以消除这些差异的命令.

However, trying to send the same commands from a c# application fails miserably. I've run Sysinternals PortMon and can see the commands come through OK, the only difference I can see is in the way it connects but I am having trouble finding the commands that would iron out those differences.

我运行的代码有点像这样

The code I'm running looks a little bit like this

using (SerialPort port = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One))
            {
                port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
                port.ErrorReceived += new SerialErrorReceivedEventHandler(port_ErrorReceived);

                //port.ReceivedBytesThreshold = 1;
                port.DtrEnable = true;
                port.RtsEnable = true;
                port.ReadTimeout = 1;
                port.Handshake = Handshake.XOnXOff;


                try
                {
                    port.Open();

                    port.WriteLine("AT");

                    port.WriteLine("AT+CMGF=1");

                    port.WriteLine("AT+CMGS="" + number + """);

                    port.WriteLine(message);

                    port.Write(new byte[] { (byte)26 }, 0, 1);
                }
                finally
                {
                    if (port.IsOpen)
                    {
                        port.Close();
                    }
                }

我在串行端口的跟踪中看到的差异是

The differences I'm seeing in the trace from the serial port are

一开始

0.00001844  aspnet_wp.exe   IOCTL_SERIAL_SET_HANDFLOW   USBSER001   SUCCESS Shake:1 Replace:43 XonLimit:4096 XoffLimit:4096 

最后

0.00061153  aspnet_wp.exe   IOCTL_SERIAL_PURGE  USBSER001   SUCCESS Purge: RXABORT RXCLEAR  
0.00004442  aspnet_wp.exe   IOCTL_SERIAL_PURGE  USBSER001   SUCCESS Purge: TXABORT TXCLEAR 

有没有人知道如何解决这些问题?我还注意到,当我发出命令时,手机没有以任何确认响应应用程序,所以我怀疑问题出在连接上,而不是最后的那些消息.

Has anyone got any tips on how to iron out these issues? I also notice that the phone is not responding back to the application with any acknowledgement when I issue a command so I suspect the problem is with the connection, not those messages at the end.

推荐答案

在写出消息之前,您需要等待>".此外,不要使用 CR/LF (WriteLine) 终止消息.

You need to wait for the ">" before writing out the message. Also, don't terminate the message with a CR/LF (WriteLine).

这篇关于通过串行端口通过诺基亚手机发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)