Sms via a nokia phone over a serial port

ぃ、小莉子 提交于 2019-12-04 14:33:35

问题


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.

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

At the start

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

And at the very end

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.


回答1:


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




回答2:


Try to see if you can read out the serial communication from the phone. After you send 'AT', the phone should respond with 'OK'. It might be a good idea to verify that the serial communication is working before taking on the SMS bit.

From what I remember, I think that after AT+CMGS the message should be entered and followed by ctrl-z, and no newline is needed. Could you try changing the WriteLine(message) to Write(message)?

Hope this helps!



来源:https://stackoverflow.com/questions/984631/sms-via-a-nokia-phone-over-a-serial-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!