Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const LVSCW_AUTOSIZE_USEHEADER As Long = -2
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Private m_Buffer As String
Private mLogFile As String
Private mReadDelete As String
Private mWriteSend As String
Private mReceived As String
Private mReceivedUsed As Long
Private mReceivedCapacity As Long
Private mReadDeleteUsed As Long
Private mReadDeleteCapacity As Long
Private mWriteSendUsed As String
Private mWriteSendCapacity As String
Private mpbMemory As String
Private mpbCapacity As Long
Private mpbUsed As Long
Private resultPos As Long
'>>>>>>>>>>> obtained from planet source code to receive
'>>>>>>>>>>> pdu messages
Private mvarnoSCA As String
Private mvarnoOA As String
Private mvarFO As String
Private mvarDCS As String
Private mvarSCTS_Tgl As String
Private mvarSCTS_Jam As String
Private mvarSCTS_Tgl_A As String
Private mvarSCTS_Jam_A As String
Private mvarIndexSend As String
Private mvarUDL As String
'>>>>>>>>>>>>>
Public Enum FindWhere
Search_Text = 0
Search_SubItem = 1
Search_Tag = 2
End Enum
Public Enum SearchType
Search_Partial = 1
Search_Whole = 0
End Enum
Public Enum SmsMemoryStorageEnum
SimMemory = 0
MobileEquipmentMemory = 1
BothMemories = 2
ReadMemorySetting = 3
BroadcastMessageStorage = 4
StatusReportStorage = 5
TerminalAdapterStorage = 6
End Enum
Public Enum MessageFormatEnum
TextFormat = 1
PDUFormat = 0
ReadFormat = 2
End Enum
Public Enum EchoEnum
EchoOff = 0
EchoOn = 1
End Enum
Public Enum PhoneBookMemoryStorageEnum
SimPhoneBook = 0
MobileEquipmentPhoneBook = 1
BothPhoneBooks = 2
ReadPhoneBookSetting = 3
SupportedMemory = 4
End Enum
Public Enum CentreNumberEnum
SetCentreNumber = 0
ReadCentreNumber = 1
End Enum
Public Enum SmsTypesEnum
RecRead = 0
RecUnread = 1
Rec = 2
StoSent = 3
StoUnsent = 4
All = 5
End Enum
Public Enum PDUFlashMessageTypeEnum
' flash = 00, non flash = F0
NonFlash = 0
Flash = 1
End Enum
Public Enum PDUDisplayReportSMSEnum
' yes = 31, no = 11
YesReport = 1
NoReport = 0
End Enum
Public Enum PDULimitPeriodOfDeliveryEnum
' 1=1hour,2=12hour,3=1day(default),4=2day,5=1week
OneHour = 1
TwelveHours = 2
OneDay = 3
TwoDays = 4
OneWeek = 5
End Enum
Public Enum PhoneBookMemoryToFormatEnum
SimPhoneBookFormat = 0
MobileEquipmentPhoneBookFormat = 1
End Enum
Public Enum WriteLocationEnum
WriteRecRead = 0
WriteRecUnread = 1
WriteStoSent = 3
WriteStoUnsent = 4
End Enum
Public Enum ModemTypeEnum
DataCard = 0
Cellphone = 1
End Enum
Private nModemType As ModemTypeEnum
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Property Get CommPort() As Integer
On Error Resume Next
' get the port used by the modem
CommPort = mCommPort
Err.Clear
End Property
Public Property Let CommPort(nCommPort As Integer)
On Error Resume Next
' set the port to use for the modem connection
MSComm.CommPort = nCommPort
mCommPort = nCommPort
PropertyChanged "CommPort"
Err.Clear
End Property
Public Property Get ModemType() As ModemTypeEnum
On Error Resume Next
' get the modem type
ModemType = nModemType
Err.Clear
End Property
Public Property Let ModemType(newModemType As ModemTypeEnum)
On Error Resume Next
' set the modem type
nModemType = newModemType
If nModemType = Cellphone Then
resultPos = 3
ElseIf nModemType = DataCard Then
resultPos = 2
End If
PropertyChanged "ModemType"
Err.Clear
End Property
Private Function FixSmsDate(sDate As String) As String
On Error Resume Next
Dim syyyy As String
Dim smm As String
Dim sdd As String
syyyy = MvField(sDate, 1, "/")
smm = MvField(sDate, 2, "/")
sdd = MvField(sDate, 3, "/")
sdd = sdd & "/" & smm & "/" & syyyy
FixSmsDate = Format$(sdd, "dd/mm/yyyy")
Err.Clear
End Function
Public Property Get LogFile() As String
On Error Resume Next
' get the path of the log file
LogFile = mLogFile
Err.Clear
End Property
Public Property Let LogFile(nLogFile As String)
On Error Resume Next
' set the path of the log file
mLogFile = nLogFile
PropertyChanged "LogFile"
Err.Clear
End Property
Public Property Get Settings() As String
On Error Resume Next
' get the settings of the modem
Settings = MSComm.Settings
Err.Clear
End Property
Public Property Get VM() As String
On Error Resume Next
' value delimiter
VM = Chr$(253)
Err.Clear
End Property
Public Property Get FM() As String
On Error Resume Next
' value delimiter
FM = Chr$(254)
Err.Clear
End Property
Public Property Get Quote() As String
On Error Resume Next
' value double quote
Quote = Chr$(34)
Err.Clear
End Property
Public Property Get Speed() As String
On Error Resume Next
' get the speed of the modem
Speed = mSpeed
Err.Clear
End Property
Public Property Let Speed(nSpeed As String)
On Error Resume Next
' set the speed of the modem, this will change settings
mSpeed = nSpeed
MSComm.Settings = nSpeed & ",n,8,1"
PropertyChanged "Speed"
PropertyChanged "Settings"
Err.Clear
End Property
Public Property Get PortOpen() As Boolean
On Error Resume Next
' get the status of the port
PortOpen = mPortOpen
Err.Clear
End Property
Public Property Let PortOpen(nPortOpen As Boolean)
On Error GoTo ErrMsg
' set the status of the port
MSComm.PortOpen = nPortOpen
mPortOpen = nPortOpen
PropertyChanged "PortOpen"
Err.Clear
Exit Property
ErrMsg:
RaiseEvent Response(Err.Description)
Err.Clear
End Property
Private Sub MSComm_OnComm()
On Error Resume Next
' read contents of the data sent by modem
Select Case MSComm.CommEvent
Case comEvReceive
m_Buffer = MSComm.Input
End Select
Err.Clear
End Sub
Public Function Connect(MyPort As String, MySpeed As String) As String
On Error Resume Next
' connect to the gsm modem by specifying the port number and speed of the modem
If MSComm.PortOpen = True Then MSComm.PortOpen = False
Me.CommPort = Val(MyPort)
Me.Speed = MySpeed
MSComm.DTREnable = True
MSComm.RTSEnable = True
MSComm.RThreshold = 1
MSComm.InBufferSize = 1024
Me.PortOpen = True
Me.Echo EchoOn
Connect = IIf(Me.PortOpen = True, "OK", "ERROR")
Err.Clear
End Function
Public Property Get ManufacturerIdentification() As String
Public Function Echo(EchoStatus As EchoEnum) As Boolean
On Error Resume Next
' turn echo off/on, off results in less traffic
' echo off returns the command with the result
Dim mAnswer As String
Select Case EchoStatus
Case EchoOff
mAnswer = Request("ATE0", , resultPos, vbCrLf)
Case EchoOn
mAnswer = Request("ATE1", , resultPos, vbCrLf)
End Select
If mAnswer = "OK" Then
Echo = True
Else
Echo = False
End If
RaiseEvent Response(Echo)
Err.Clear
End Function
Public Function Request(ByVal strCommand As String, Optional ByVal ExpectedResult As String = "", Optional Position As Long = -1, Optional ControlChars As String = vbCrLf) As String
On Error GoTo ErrMsg
' send a request to the comm port and wait for the result
' the result will be delimited by chr(253)
Dim sResult As String
If Len(LogFile) > 0 Then
FileUpdate LogFile, Now() & ", request received " & strCommand, "a"
End If
MSComm.Output = strCommand & ControlChars
sResult = WaitReply(10, ExpectedResult)
sResult = Replace$(sResult, vbNewLine, VM)
If Len(LogFile) > 0 Then
FileUpdate LogFile, Now() & ", response received " & sResult, "a"
End If
If Position > 0 Then
sResult = MvField(sResult, Position, VM)
Else
sResult = sResult
End If
Request = DescriptiveError(sResult)
Err.Clear
Exit Function
ErrMsg:
RaiseEvent Response(Err.Description)
Err.Clear
End Function
Private Function WaitReply(lDelay As Long, WaitString As String) As String
On Error Resume Next
' wait process for a data request from the
' ms comm port to be finalized
Dim x As Long
Dim bOK As Boolean
DoEvents
If WaitString = "" Then
bOK = True
For x = 1 To lDelay
Sleep 500
DoEvents
Next
Else
bOK = False
For x = 1 To lDelay
DoEvents
If InStr(m_Buffer, WaitString) Then
bOK = True
Exit For
Else
DoEvents
Sleep 500
DoEvents
End If
Next
End If
If Len(m_Buffer) > 0 Then
DoEvents
End If
WaitReply = m_Buffer
Err.Clear
End Function
Private Function MvField(ByVal strValue As String, Optional ByVal PartPosition As Long = 1, Optional ByVal Delimiter As String = ",", Optional TrimValue As Boolean = True) As String
On Error Resume Next
' return a substring of a string delimited by a string specified
Dim xResult As String
Dim xArray() As String
Dim xSize As Long
If Len(strValue) = 0 Then Exit Function
If InStr(1, strValue, Delimiter) = 0 Then
MvField = strValue
Err.Clear
Exit Function
End If
xArray = Split(strValue, Delimiter)
Select Case PartPosition
Case -1
PartPosition = UBound(xArray) + 1
Case 0
PartPosition = 1
End Select
xSize = UBound(xArray)
If xSize = 0 Then
MvField = ""
Else
xResult = xArray(PartPosition - 1)
If TrimValue = True Then
xResult = Trim$(xResult)
End If
MvField = xResult
End If
Err.Clear
End Function
Public Sub FileUpdate(ByVal filName As String, ByVal filLines As String, Optional ByVal Wora As String = "write")
On Error Resume Next
' update contents of a file by either appending / creating a new entry
Dim iFileNum As Long
Dim cDir As String
cDir = FileToken(filName, "p")
CreateNestedDirectory cDir
iFileNum = FreeFile
Select Case LCase$(Left$(Wora, 1))
Case "w"
Open filName For Output As #iFileNum
Case "a"
Open filName For Append As #iFileNum
End Select
Print #iFileNum, filLines
Close #iFileNum
Err.Clear
End Sub
Private Function DescriptiveError(ByVal sResult As String) As String
On Error Resume Next
' return descriptive phone error code
Select Case sResult
Case "+CME ERROR: 0": DescriptiveError = "Phone failure"
Case "+CME ERROR: 1": DescriptiveError = "No connection to phone"
Case "+CME ERROR: 2": DescriptiveError = "Phone adapter link reserved"
Case "+CME ERROR: 3": DescriptiveError = "Operation not allowed"
Case "+CME ERROR: 4": DescriptiveError = "Operation not supported"
Case "+CME ERROR: 5": DescriptiveError = "PH_SIM PIN required"
Case "+CME ERROR: 6": DescriptiveError = "PH_FSIM PIN required"
Case "+CME ERROR: 7": DescriptiveError = "PH_FSIM PUK required"
Case "+CME ERROR: 10": DescriptiveError = "SIM not inserted"
Case "+CME ERROR: 11": DescriptiveError = "SIM PIN required"
Case "+CME ERROR: 12": DescriptiveError = "SIM PUK required"
Case "+CME ERROR: 13": DescriptiveError = "SIM failure"
Case "+CME ERROR: 14": DescriptiveError = "SIM busy"
Case "+CME ERROR: 15": DescriptiveError = "SIM wrong"
Case "+CME ERROR: 16": DescriptiveError = "Incorrect password"
Case "+CME ERROR: 17": DescriptiveError = "SIM PIN2 required"
Case "+CME ERROR: 18": DescriptiveError = "SIM PUK2 required"
Case "+CME ERROR: 20": DescriptiveError = "Memory full"
Case "+CME ERROR: 21": DescriptiveError = "Invalid index"
Case "+CME ERROR: 22": DescriptiveError = "Not found"
Case "+CME ERROR: 23": DescriptiveError = "Memory failure"
Case "+CME ERROR: 24": DescriptiveError = "Text string too long"
Case "+CME ERROR: 25": DescriptiveError = "Invalid characters in text string"
Case "+CME ERROR: 26": DescriptiveError = "Dial string too long"
Case "+CME ERROR: 27": DescriptiveError = "Invalid characters in dial string"
Case "+CME ERROR: 30": DescriptiveError = "No network service"
Case "+CME ERROR: 31": DescriptiveError = "Network timeout"
Case "+CME ERROR: 32": DescriptiveError = "Network not allowed, emergency calls only"
Case "+CME ERROR: 40": DescriptiveError = "Network personalization PIN required"
Case "+CME ERROR: 41": DescriptiveError = "Network personalization PUK required"
msgContents = Replace$(msgContents, VM & VM & "OK" & VM, "")
msgContents = RemAllVM(msgContents)
mAnswer = msgIndex & FM & MsgType & FM & msgFrom & FM & msgDate & " " & msgTime & FM & msgContents
End Select
SMS_ReadMessageEntry = mAnswer
RaiseEvent Response(SMS_ReadMessageEntry)
Err.Clear
End Function
Public Sub SMS_ListView(progBar As Variant, LstView As Variant, Optional mIcon As String = "", Optional mSmallIcon As String = "", Optional MsgType As SmsTypesEnum)
On Error Resume Next
' load contents of the selected message store messages