使用和Wavecom Fastrack M1306B USB GSM MODEM发送短信 [英] Send SMS using and Wavecom Fastrack M1306B USB GSM MODEM
问题描述
大家好,
我整个星期都做了很多研究,尝试了谷歌,雅虎的所有不同代码。代码项目。等等
到目前为止,我尝试了以下主要链接:
http://code.msdn.microsoft.com/wpapps/Sending-SMS-Using-PC-COM-3d79e1d7 [ ^ ]
http://www.daniweb.com/software-development/vbnet/threads/9537/sending-sms-using-vb.net [ ^ ]
使用.NET发送短信 [ ^ ]
我的实际代码在这里:
适用于SMSCOMMS课程
< span class =code-keyword> Imports 系统
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports
公开 类 SMSCOMMS
私有 WithEvents SMSPort As SerialPort
私有 SMSThread 作为线程
私有 ReadThread 作为线程
共享 _Continue 作为 布尔 = 错误
共享 _ContSMS 作为 布尔 = False
私有 _Wait As 布尔 = 错误
共享 _ReadPort 作为 布尔 = 错误
公开 活动发送( ByVal 完成作为 布尔)
公开 事件 DataReceived( ByVal 消息 As String )
公开 Sub 新( ByRef COMMPORT 作为 字符串)
SMSPort = 新 SerialPort
使用 SMSPort
.PortName = COMMPORT
。 BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
结束 使用
ReadThread = 新主题( AddressOf ReadPort)
结束 Sub
公共 功能 SendSMS( ByVal CellNumber 作为 字符串, ByVal SMSMessage 作为 字符串) As 布尔
Dim MyMessage 作为 字符串 = 没什么
' 检查消息长度< = 160
如果 SMSMessage.Length< = 160 然后
MyMessage = SMSMessage
其他
MyMessage = Mid(SMSMessage, 1 , 160 )
结束 如果
如果 IsOpen = True 然后
SMSPort.WriteLine( AT + CMGS =& CellNumber& vbCr)
_ContSMS = False
SMSPort.WriteLine(MyMessage& vbCrLf& Chr( 26) ))
_Continue = False
RaiseEvent 发送( False )
结束 如果
结束 功能
私人 Sub ReadPort()
Dim SerialIn 作为 字符串 = 没什么
Dim RXBuffer(SMSPort.ReadBufferSize)作为 字节
Dim SMSMessage As String = Nothing
Dim Strpos As 整数 = 0
Dim TmpStr 作为 字符串 = 没什么
while SMSPort.IsOpen = True
如果(SMSPort.BytesToRead<> 0 )和(SMSPort.IsOpen = True )然后
SMSPort.BytesToRead<> 0
SMSPort.Read(RXBuffer, 0 ,SMSPort.ReadBufferSize)
SerialIn = SerialIn& System.Text.Encoding.ASCII.GetString(RXBuffer)
如果 SerialIn.Contains( >)= True 然后
_ContSMS = True
结束 如果
如果 SerialIn.Contains( + CMGS:)= True 然后
_Continue = True
RaiseEvent 发送( True )
_Wait = False
SerialIn = String .Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
结束 如果
结束 while
RaiseEvent DataReceived(SerialIn)
SerialIn = 字符串 .Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
结束 如果
结束 while
结束 Sub
公开 ReadOnly 属性 IsOpen()作为 布尔
获取
如果 SMSPort.IsOpen = True 然后
IsOpen = True
否则
IsOpen = 错误
结束 如果
结束 获取
结束 属性
公开 Sub 打开()
如果 IsOpen = 错误 然后
SMSPort.Open()
ReadThread.Start()
结束 < span class =code-keyword>如果
结束 Sub
公开 Sub 关闭()
如果 IsOpen = True 那么
SMSPort.Close()
结束 如果
结束 Sub
结束 类
For Form1
选项显式在
公共类Form1
私有子Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理Button1.Click
Dim SMSEngine As SMSCOMMS
SMSEngine = New SMSCOMMS(COM5)
SMSEngine.Open()
SMSEngine.SendSMS(9234996080 ,短信测试)
SMSEngine.Close()
结束次级
结束班级
仍然根本不工作。我确信Comp端口号是5,因为我尝试从smscaster.com下载短信并试用他们的试用API。
我也试过这个
[ ^ ]
但是这个比我想象的要复杂得多,它有许可费用。
你好,你可以尝试使用.BaudRate = 115200 for fastrack wavecom modem
我也发现了这个问题。将BaudRate更改为115200解决了这个问题。感谢。
Hi Guys,
I have done so many research the whole week and tried all different codes from google, yahoo. code projects. etc.
So far i have tried major links below:
http://code.msdn.microsoft.com/wpapps/Sending-SMS-Using-PC-COM-3d79e1d7[^]
http://www.daniweb.com/software-development/vbnet/threads/9537/sending-sms-using-vb.net[^]
Sending SMS using .NET[^]
My Actual Code is here:
For SMSCOMMS Class
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)
Public Sub New(ByRef COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
ReadThread = New Thread(AddressOf ReadPort)
End Sub
Public Function SendSMS(ByVal CellNumber As String,ByVal SMSMessage As String) As Boolean
Dim MyMessage As String = Nothing
'Check if Message Length <= 160
If SMSMessage.Length <= 160 Then
MyMessage = SMSMessage
Else
MyMessage = Mid(SMSMessage, 1, 160)
End If
If IsOpen = True Then
SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCr)
_ContSMS = False
SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
_Continue = False
RaiseEvent Sending(False)
End If
End Function
Private Sub ReadPort()
Dim SerialIn As String = Nothing
Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
Dim SMSMessage As String = Nothing
Dim Strpos As Integer = 0
Dim TmpStr As String = Nothing
While SMSPort.IsOpen = True
If (SMSPort.BytesToRead <> 0) And (SMSPort.IsOpen = True) Then
While SMSPort.BytesToRead <> 0
SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize)
SerialIn = SerialIn & System.Text.Encoding.ASCII.GetString(RXBuffer)
If SerialIn.Contains(">") = True Then
_ContSMS = True
End If
If SerialIn.Contains("+CMGS:") = True Then
_Continue = True
RaiseEvent Sending(True)
_Wait = False
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
RaiseEvent DataReceived(SerialIn)
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
End Sub
Public ReadOnly Property IsOpen() As Boolean
Get
If SMSPort.IsOpen = True Then
IsOpen = True
Else
IsOpen = False
End If
End Get
End Property
Public Sub Open()
If IsOpen = False Then
SMSPort.Open()
ReadThread.Start()
End If
End Sub
Public Sub Close()
If IsOpen = True Then
SMSPort.Close()
End If
End Sub
End Class
For Form1
Option Explicit On Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim SMSEngine As SMSCOMMS SMSEngine = New SMSCOMMS("COM5") SMSEngine.Open() SMSEngine.SendSMS("9234996080", "SMS Testing") SMSEngine.Close() End Sub End Class
Still do not work at all. i am sure that Comp port number is 5 since i tried downloading SMS cast from smscaster.com and tried their trial API.
Also i have tried this
[^]
but this one is more complicated than i have imagine and it has a cost for license.
hello, you can try to use .BaudRate = 115200 for fastrack wavecom modem
I also found that problem. Changing BaudRate to 115200 solved the problem. Thanks.
这篇关于使用和Wavecom Fastrack M1306B USB GSM MODEM发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!