使用AT命令通过Nokia Mobile发送短信 [英] Send SMS via Nokia Mobile Using AT Commands
问题描述
我正在尝试使用AT Commands通过诺基亚手机(C1-01)发送短信,并且可以使用此vb.net代码成功发送短信.
I'm trying to send sms with my Nokia cell phone (C1-01) using AT Commands and I can successfully send SMS with this vb.net code.
Button_Send_Click:
Dim SMSPort = New SerialPort
With SMSPort
.PortName = "COM2"
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.None
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
SMSPort.Open()
SMSPort.Write("AT+CMGF=1" & vbCrLf)
Threading.Thread.Sleep(200)
SMSPort.Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf) 'TextBox1.text = Recipient mobile number and chr(34) = "
Threading.Thread.Sleep(200)
SMSPort.Write("TEST MESSAGE" & Chr(26)) 'chr(26) = →
Threading.Thread.Sleep(200)
MsgBox(SMSPort.ReadExisting())
SMSPort.Close()
第一次工作正常,在触发此代码后,当我第二次按发送按钮时,我在手机上收到短信TEST MESSAGE
(精妙)但我在手机上收到短信,其中包含:
AT+CMGF=1
AT+CMGS=+92XXYYYYYY
TEST MESSAGE
It's working fine for the 1st time, after fire this code I received SMS on my cell phone TEST MESSAGE
(Brilliant) BUT when I press send button in second time I received SMS on my cell phone which contains:
AT+CMGF=1
AT+CMGS=+92XXYYYYYY
TEST MESSAGE
为什么第二次在SMS中包含"AT命令,即AT + CMGF等"?
如何从中删除不需要的文本?
在打开和关闭串行端口(SMSPort)之后,我也尝试过SMSPort.DiscardInBuffer()
和SMSPort.DiscardOutBuffer()
属性,但是我的问题无法解决.
我已经在Google上搜索了很多,但都徒劳无功,请帮助我解决此问题.
Why in second time it's including "AT Commands i.e AT+CMGF etc.." in SMS?
How can I remove unwanted text from this?
I have also try SMSPort.DiscardInBuffer()
and SMSPort.DiscardOutBuffer()
Properties after opening and before closing my serial port (SMSPort) but my issue is not resolving.
I have googled alot but all is vain, Please help me to resolve this issue.
平台:带有.NET 2.0的Microsoft Visual Basic 2010
Platform: Microsoft Visual Basic 2010 with .NET 2.0
推荐答案
首先,您必须认真地将AT命令处理重做为
First of all, you must seriously redo your AT command handling to
- 读取并解析从调制解调器返回的每个响应行,直到获得最终结果代码.这适用于每个命令行调用,没有任何异常.有关更多详细信息,请参见此答案.
- 永远不要在处理AT命令的任何代码中调用
Threading.Thread.Sleep
.请参阅此答案以了解有关中止下一条命令的风险的更多详细信息. - 对于
AT+CMGS
,具体来说,您还必须在发送数据之前等待"\ n \ r>"响应,请参见
- Read and parse the every single response line given back from the modem until you get a final result code. This applies for every single command line invocation, no exceptions whatsoever. See this answer for more details.
- Never ever call
Threading.Thread.Sleep
in any code that handles AT commands. See this answer for more details about the risk of aborting the next command. - For
AT+CMGS
specifically you also MUST wait for the "\n\r> " response before sending data, see this answer (again) for more details.
在解决这些基本问题之前,您无法期望任何成功的行为.
Before fixing these fundamental issues you cannot expect any successful behaviour.
这篇关于使用AT命令通过Nokia Mobile发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!