我正在尝试通过诺基亚手机通过串口发送短信,这通过腻子很容易。诺基亚文档中的命令运行良好。
但是,尝试从 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
有没有人对如何解决这些问题有任何提示?我还注意到,当我发出命令时,手机没有以任何确认响应应用程序,所以我怀疑问题出在连接上,而不是最后的那些消息。