2

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

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

我正在运行的代码看起来有点像这样

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();
                    }
                }

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

在开始时

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 

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

4

2 回答 2

1

试试看能不能读出手机上的串口通讯。发送“AT”后,手机应回复“OK”。在接收 SMS 位之前验证串行通信是否正常工作可能是个好主意。

根据我的记忆,我认为在AT+CMGS之后应该输入消息并跟随ctrl-z,并且不需要换行符。您可以尝试将 WriteLine(message) 更改为 Write(message) 吗?

希望这可以帮助!

于 2009-06-12T08:51:24.840 回答
0

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

于 2009-12-23T23:39:45.620 回答