热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何通过Windows应用程序发送短信-HowtoSendSMSviaWindowsapplication

IwanttosendSMSbywindowsapplication.IranthecodebutIgotanerror.Thisis我想通过windows应用程

I want to send SMS by windows application. I ran the code but I got an error. This is

我想通过windows应用程序发送SMS。我运行了代码,但是我有一个错误。这是

AT

OK AT+CMGF=1

OK AT+CSCA="+9460921985"

OK AT+CMGS="+9660775564"

    this is new message

+CMS ERROR: 500

I am using this code.

我正在使用这段代码。

Public Class Form2 
  Dim number As String = "+9660775564"
  ''# Dim message As String = TextBox1.Text 
  Dim serialport As New IO.Ports.SerialPort 

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Try With serialport 
      .PortName = "COM5" ''# "COM24" 
      .BaudRate = "9600" 
      .Parity = IO.Ports.Parity.None 
      .DataBits = 8 
      .StopBits = IO.Ports.StopBits.One
      .Handshake = IO.Ports.Handshake.RequestToSend 
      .DtrEnable = True .RtsEnable = True 
    End With

    serialport.Open()
    ''# checks phone status
    serialport.WriteLine("AT" & vbCrLf)
    ''# Configures message as SMS
    serialport.WriteLine("AT+CMGF=1" & vbCrLf)
    ''# Sets message center number
    ''# serialport.WriteLine("AT+CSCA=""+447785016005""" & vbCrLf)
    serialport.WriteLine("AT+CSCA=""+9460921985""" & vbCrLf)
    ''# Sets destination number
    serialport.WriteLine("AT+CMGS=""" & number & """" & vbCrLf)
    ''# Specifies message and sends Ctrl+z
    serialport.WriteLine(TextBox1.Text & Chr(26))
    ''# Displays buffer containing output messages
    System.Threading.Thread.Sleep(2000) ''# CurrentThread.Sleep(2000)
    MsgBox(serialport.ReadExisting)
    serialport.Close()
    MessageBox.Show("OK")

  Catch ex As Exception
    MessageBox.Show(ex.Message)
  End Try
End Sub

Thanks in advance for your help.

谢谢你的帮助。

3 个解决方案

#1


2  

I have no experience of writing SMS at all, but you appear to be calling serialPort.WriteLine as well as appending vbCrLf on the end of the line.

我完全没有写短信的经验,但你似乎在呼叫serialPort。写和附加vbCrLf在线的末端。

Secondly, are you sure it is vbCrLf you want - some things I have seen simply refer to 'Carriage return' - which would be vbCr.

第二,你确定vbcrllf是你想要的吗?我看到的一些东西只是指“回车”,也就是vbCr。

#2


1  

I stumbled across Microsoft SMS Sender awhile ago and it may help you out. I never got around to using it though...

我在一段时间之前偶然发现了微软的短信发送器,它可能会帮到你。我从来都没想过要用它……

#3


0  

+CMS ERROR 500 is (normally) expanded as an "Unknown Error". From the GSM modem AT command documentation:

+CMS错误500(通常)扩展为“未知错误”。来自GSM调制解调器的命令文档:


If sending fails, for example, if a message is too long, the result code depends on the current setting of the AT^SM20 command:

如果发送失败,例如,如果一个消息太长,结果代码取决于当前的设置在^ SM20命令:

If the AT^SM20 equals 1 (factory default) any failure to send a message is responded with "OK". Users should be aware, that despite the "OK" response, the message will not be sent to the subscriber.

如果在^ SM20 = 1(出厂默认值)任何未能发送消息“OK”。用户应该知道,尽管“OK”响应,消息不会被发送到订阅服务器。

If the AT^SM20 equals 0 any failure to send a message is responded with "ERROR". • If sending fails due to timeout, then AT^SM20 =1 causes "+CMS ERROR: Unknown error" to be returned;
AT^SM20 =0 causes "+CMS ERROR: timer expired" to be returned.

如果在^ SM20 = 0任何未能发送消息是“错误”。•如果发送失败由于超时,然后在^ SM20 = 1会导致“+ CMS错误:未知错误”返回;在^ SM20 = 0的原因“+ CMS错误:计时器过期”回来了。


Possibly you might be having timeout/connection problems. Maybe check that your modem/phone has registered successfully with the service i.e. check the response to the AT+COPS? and AT+CREG? commands.

可能会出现超时/连接问题。也许检查一下你的调制解调器/手机是否已经成功地注册了服务,比如检查对AT+ cop的响应?在+ CREG ?命令。


推荐阅读
author-avatar
fo切為祢
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有