📄 commphone.vb
字号:
'//////////////////////////////////////////////////////////////////////////
'// Use at your own risk //
'// www.hesicong.net //
'// Copyright Dreamworld. You can use this program freely but no in //
'// commerial use without my permission. //
'// Authoer: hesicong //
'// Date: 2007-2-25 //
'//////////////////////////////////////////////////////////////////////////
Imports Dreamworld.Mobile.PhoneControllerSDK
Imports System.Text
Imports System.Text.Encoding
Imports System.Text.RegularExpressions
Imports System.Threading
Namespace Dreamworld.Mobile
Public Class CommPhone
Implements PhoneControllerSDK.IPhoneController
Implements IDisposable
Private mATCmd As ATCommandBase
Private myPhone As Mutex = New Mutex(False)
Private mTimeOut As Integer = 100 '100ms
#Region "Interface member"
Public Function AddPhonebookEntry(ByVal entry As PhoneControllerSDK.PhonebookEntry) As Boolean Implements PhoneControllerSDK.IPhoneController.AddPhonebookEntry
Throw New NotSupportedException
End Function
''' <summary>
''' Connect to phone
''' </summary>
''' <param name="Port">Port name like "COM1:"</param>
''' <param name="baudrate">Speed of connection. Default 19200</param>
''' <returns>True if successed;False if failed</returns>
''' <remarks></remarks>
Public Overloads Function Connect(ByVal Port As String, Optional ByVal baudrate As Integer = 19200, Optional ByVal timeOut As Integer = 20000) As Boolean Implements PhoneControllerSDK.IPhoneController.Connect
Try
mATCmd = New ATCommandBase(Port, baudrate, timeOut)
mTimeOut = timeOut
If ATCommandBase.CheckResponse(mATCmd.SendCommand("AT")) = True Then
Return True
Else
mATCmd.Close()
Return False
End If
Catch e As Exception
mATCmd.Close()
Throw e
End Try
End Function
Public Function DelPhonebookEntry(ByVal index As Integer) As Boolean Implements PhoneControllerSDK.IPhoneController.DelPhonebookEntry
Throw New NotSupportedException
End Function
Public Function DelSMS(ByVal index As Integer) As Boolean Implements PhoneControllerSDK.IPhoneController.DelSMS
Throw New NotSupportedException
End Function
Public Function Disconnect() As Boolean Implements PhoneControllerSDK.IPhoneController.Disconnect
mATCmd.Close()
Return True
End Function
Public Function GetBatteryCharge() As Integer Implements PhoneControllerSDK.IPhoneController.GetBatteryCharge
Throw New NotSupportedException
End Function
Public Function GetCapability() As PhoneControllerSDK.Capability Implements PhoneControllerSDK.IPhoneController.GetCapability
Throw New NotSupportedException
End Function
''' <summary>
''' Get IMSI
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetIMSI() As String Implements PhoneControllerSDK.IPhoneController.GetIMSI
Dim rst As String = mATCmd.SendCommand("AT+CIMI")
Dim regex As Regex = New Regex( _
"(?<IMSI>\d+)")
Dim m As Match = regex.Match(rst)
If m.Success Then
Return m.Groups("IMSI").Value
Else
Throw New ApplicationException("Can't get your IMSI")
End If
End Function
Public Function GetLastError() As String Implements PhoneControllerSDK.IPhoneController.GetLastError
Throw New NotSupportedException
End Function
''' <summary>
''' Get manufacture ID
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetManufactureID() As String Implements PhoneControllerSDK.IPhoneController.GetManufactureID
Dim rst As String = mATCmd.SendCommand("AT+CGMI")
Dim regex As Regex = New Regex( _
"(?<ID>\w+)")
Dim m As Match = regex.Match(rst)
If m.Success Then
Return m.Groups("ID").Value
Else
Throw New ApplicationException("Can't get your Manufacturer ID")
End If
End Function
''' <summary>
''' Get Model ID
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetModelID() As String Implements PhoneControllerSDK.IPhoneController.GetModelID
'Dim rst As String = mATCmd.SendCommand("AT+CGMM")
'Dim regex As Regex = New Regex( _
' "(?<ID>\(w|+)")
'Dim m As Match = regex.Match(rst)
'If m.Success Then
' Return m.Groups("ID").Value
'Else
' Throw New ApplicationException("Can't get your Model ID")
'End If
'####################################
'Simply split first line will OK!
'Regular expression is not needed.
'####################################
Dim rst As String = mATCmd.SendCommand("AT+CGMM")
Dim lines As String() = rst.Replace(vbCrLf, Chr(13)).Split(New Char() {Chr(13)}, StringSplitOptions.RemoveEmptyEntries)
Return lines(0)
End Function
Public Function GetOwnNumber() As String Implements PhoneControllerSDK.IPhoneController.GetOwnNumber
Throw New NotSupportedException
End Function
Public Function GetPhonebookStatus() As PhoneControllerSDK.PhonebookStatus Implements PhoneControllerSDK.IPhoneController.GetPhonebookStatus
Throw New NotSupportedException
End Function
Public Function GetQualityOfService() As Integer Implements PhoneControllerSDK.IPhoneController.GetQualityOfService
Throw New NotSupportedException
End Function
Public Event NewMessageArrived(ByVal index As Integer, ByVal content As String) Implements PhoneControllerSDK.IPhoneController.NewMessageArrived
Public Function ReadAllPhonebookEntry() As PhoneControllerSDK.PhonebookEntry() Implements PhoneControllerSDK.IPhoneController.ReadAllPhonebookEntry
Throw New NotSupportedException
End Function
Public Function ReadPhonebookEntry(ByVal index As Integer) As PhoneControllerSDK.PhonebookEntry Implements PhoneControllerSDK.IPhoneController.ReadPhonebookEntry
Throw New NotSupportedException
End Function
Public Function ReadSMSByIndex(ByVal index As Integer) As PhoneControllerSDK.SMSRead Implements PhoneControllerSDK.IPhoneController.ReadSMSByIndex
Throw New NotSupportedException
End Function
Public Function ReadSMSByStatus(ByVal status As PhoneControllerSDK.ATSMSStatus) As PhoneControllerSDK.SMSRead() Implements PhoneControllerSDK.IPhoneController.ReadSMSByStatus
Throw New NotSupportedException
End Function
Public Function SelectPhonebookType(ByVal phonebookType As PhoneControllerSDK.PhonebookType) As Boolean Implements PhoneControllerSDK.IPhoneController.SelectPhonebookType
Throw New NotSupportedException
End Function
Public Function SelectSMSStorage(ByVal mem1 As PhoneControllerSDK.SMSStorage, ByVal mem2 As PhoneControllerSDK.SMSStorage, ByVal mem3 As PhoneControllerSDK.SMSStorage) As Boolean Implements PhoneControllerSDK.IPhoneController.SelectSMSStorage
Throw New NotSupportedException
End Function
Public Function SendSMS(ByVal toSend As PhoneControllerSDK.SMSSend) As Integer() Implements PhoneControllerSDK.IPhoneController.SendSMS
Throw New NotSupportedException
End Function
Public Property ServiceCenterNumber() As String Implements PhoneControllerSDK.IPhoneController.ServiceCenterNumber
Get
Throw New NotSupportedException
End Get
Set(ByVal value As String)
Throw New NotSupportedException
End Set
End Property
Public Function GetServiceCenterNumber() As String Implements PhoneControllerSDK.IPhoneController.GetServiceCenterNumber
Throw New NotSupportedException
End Function
Public Function SetCharacterSet(ByVal characterSet As PhoneControllerSDK.CharactorSet) As Boolean Implements PhoneControllerSDK.IPhoneController.SetCharacterSet
Throw New NotSupportedException
End Function
Public Function SetNewMessageArriveReport(ByVal enabled As Boolean) As Boolean Implements PhoneControllerSDK.IPhoneController.SetNewMessageArriveReport
Throw New NotSupportedException
End Function
Public Function SetStandard() As Boolean Implements PhoneControllerSDK.IPhoneController.SetStandard
'mATCmd.SendCommand("ATE0") 'No echo
Return True
End Function
Public ReadOnly Property SupportedModel() As String() Implements PhoneControllerSDK.IPhoneController.SupportedModel
Get
'Support all model
Return New String() {String.Empty}
End Get
End Property
Public Function WriteSMS(ByVal status As PhoneControllerSDK.ATSMSStatus, ByVal toWrite As PhoneControllerSDK.SMSSend) As Integer() Implements PhoneControllerSDK.IPhoneController.WriteSMS
Throw New NotSupportedException
End Function
#End Region
Private disposedValue As Boolean = False ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free unmanaged resources when explicitly called
If myPhone Is Nothing = False Then
myPhone.Close()
End If
End If
' TODO: free shared unmanaged resources
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overrides Sub Finalize()
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(False)
MyBase.Finalize()
End Sub
#End Region
Public Function CancelCurrentAction() As Boolean Implements PhoneControllerSDK.IPhoneController.CancelCurrentAction
Return mATCmd.CancelCurrentAction()
End Function
Public ReadOnly Property TotalEntriesCount() As Integer Implements PhoneControllerSDK.IPhoneController.TotalEntriesCount
Get
End Get
End Property
Public ReadOnly Property TotalReadCount() As Integer Implements PhoneControllerSDK.IPhoneController.TotalReadCount
Get
End Get
End Property
Public Function GetSMSStorageStatus() As PhoneControllerSDK.SMSStorageStatus Implements PhoneControllerSDK.IPhoneController.GetSMSStorageStatus
End Function
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -