首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

用VB6 mscomm写的短信收发,无法收短信,该怎么解决

2012-03-06 
用VB6 mscomm写的短信收发,无法收短信各位大虾:因为最近看了很多短信收发的编写,从网上下载了一下短个收发

用VB6 mscomm写的短信收发,无法收短信
各位大虾:
  因为最近看了很多短信收发的编写,从网上下载了一下短个收发源代码,问题是可以发送,但无法收短信!请各位检查检查,指导下!谢谢!
具体代码如下:

Dim SendSuccessCount As Integer
Dim SendFailedCount As Integer
Dim ReceiveCount As Integer
Dim WorkFlag As Boolean
Dim ReceiveData As String
Dim SendSuccess As Integer '-1等待;0失败;1成功
Dim ReceiveSuccess As Integer '-1等待;0失败;1成功

Private Sub Command1_Click()
  RequestRecMsg MsgIndex.Text
End Sub

Private Sub Form_Load()

  SmsInit 6, "9600,n,8,1"

End Sub
Private Function SmsInit(Port As Integer, setstr As String) As Boolean
  SmsInit = False
  If SmsOpen(Port, setstr) = False Then Exit Function
  WorkFlag = True
  SendSuccessCount = 0
  SendFailedCount = 0
  ReceiveCount = 0
  ReceiveData = ""
  SendSuccess = 0
  ReceiveSuccess = 0
  SmsInit = True
End Function
Private Function SmsSend(MoblieID As String, TxtMessage As String) As Boolean '被timer1_timer调用
  Dim TxtMsg As String

  SmsSend = False
  If WorkFlag = False Or SendSuccess = -1 Then Exit Function
  '编码
  TxtMsg = Encode(TxtMessage)
  If MSComm1.PortOpen Then
  MSComm1.Output = "AT+CMGS=" + Chr(34) + MoblieID + Chr(34) + Chr(13) '送出短信目的号码
  MSComm1.Output = TxtMsg + Chr(26) '送出已编码后的短信内容
  SendSuccess = -1
  SmsSend = True
  End If
End Function

Function SmsOpen(Port As Integer, Setings As String) As Integer '被opensms_click 调用
'打开端口号码
On Error GoTo ErrHandle
  SmsOpen = False
  If MSComm1.PortOpen Then MSComm1.PortOpen = False
  MSComm1.CommPort = Port
  MSComm1.Settings = Setings
  MSComm1.PortOpen = True
   
  If MSComm1.PortOpen Then
  SmsOpen = True
  MSComm1.Output = "ATE0" + Chr(13) + Chr(10)
  MSComm1.RThreshold = 1
  MSComm1.Output = "AT+CMGF=1" + Chr(13) + Chr(10)
  MSComm1.Output = "AT+CSMP=4,167,0,8" + Chr(13) + Chr(10)
'上边两行语句作为联机是初始化用的命令
  End If
   
Exit Function
ErrHandle:
  MsgBox "错误: " + Str(Err.Number) + Chr(13) + Chr(10) + Err.Description, _
  vbOKOnly + vbCritical, App.Title
End Function



[解决办法]
你的代码可以接收数据的。你应该检查AT指令是否正确。

热点排行