PC机向手机发短信问题,急!!!
PC机向手机发送短信,通过PDU格式发送,代码如下:
frmMain.MSComm1.Output = "AT+CMGF=0 " + vbCr
frmMain.MSComm1.Output = "AT+CMGS= " & str(15 + length) + vbCr
frmMain.MSComm1.Output = pdu & Chr$(26)
Sleep (2000)
reco = frmMain.MSComm1.Input
If InStr(reco, "OK ") Then
Sendsms = True
End If
If InStr(reco, "ERROR ") Then
Sendsms = False
End If
这是我根据网上找的,可是为什么这个reco有时能收到有时为空?
这个问题该如何解决?
[解决办法]
下面提供一段基于TEXT模式的代码,供参考:
Option Explicit
Private Declare Sub Sleep Lib "kernel32 " (ByVal dwMilliseconds As Long)
Dim strTxt As String
Private Sub cmdSend_Click()
MSComm1.Output = strTxt
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1 "
MSComm2.CommPort = 2
MSComm2.Settings = "9600,N,8,1 "
MSComm1.PortOpen = True
MSComm2.PortOpen = True
MSComm2.RThreshold = 1
Text1 = "AT+CMGS= " + "vb编写串口通信程序,可以随便进行汉字、字母、符号的发送和接收. " + Chr(10) 'rs!tel
strTxt = Text1
End Sub
Private Sub MsComm2_OnComm()
Dim AscInput As String
Select Case Me.MSComm2.CommEvent
Case comEvReceive
Sleep (50) '延迟
'此处添加处理接收的代码
MSComm2.InputMode = comInputModeText 'Text接收
AscInput = MSComm2.Input
Text2 = AscInput
End Select
End Sub