Sei sulla pagina 1di 28

Imports System

Imports GsmComm.GsmCommunication

Namespace SMS
Public Class CommSetting
Public Shared Comm_Port As Integer = 0
Public Shared Comm_BaudRate As Int64 = 0
Public Shared Comm_TimeOut As Int64 = 0
Public Shared comm As GsmCommMain

Public Sub New()


End Sub
End Class
End Namespace
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports GsmComm.PduConverter
Imports GsmComm.GsmCommunication

Namespace SMS
Public Class Delete
Inherits System.Windows.Forms.Form

Private dataGrid1 As System.Windows.Forms.DataGrid


Private components As System.ComponentModel.Container = Nothing
Private btn_delete As System.Windows.Forms.Button
Private btn_delete_all As System.Windows.Forms.Button
Private txt_message_index As System.Windows.Forms.TextBox
Private dt As DataTable = New DataTable()
Private Delegate Sub SetTextCallback(ByVal text As String)

Public Sub New()


InitializeComponent()
End Sub

Protected Overrides Sub Dispose(ByVal disposing As Boolean)


If disposing Then

If components IsNot Nothing Then


components.Dispose()
End If
End If

MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()


Me.dataGrid1 = New System.Windows.Forms.DataGrid()
Me.btn_delete = New System.Windows.Forms.Button()
Me.btn_delete_all = New System.Windows.Forms.Button()
Me.txt_message_index = New System.Windows.Forms.TextBox()
(CType((Me.dataGrid1), System.ComponentModel.ISupportInitialize)).BeginInit()
Me.SuspendLayout()
Me.dataGrid1.DataMember = ""
Me.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dataGrid1.Location = New System.Drawing.Point(8, 40)
Me.dataGrid1.Name = "dataGrid1"
Me.dataGrid1.Size = New System.Drawing.Size(472, 264)
Me.dataGrid1.TabIndex = 60
Me.dataGrid1.MouseDown += New
System.Windows.Forms.MouseEventHandler(AddressOf Me.dataGrid1_MouseDown)
Me.btn_delete.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btn_delete.Location = New System.Drawing.Point(56, 8)
Me.btn_delete.Name = "btn_delete"
Me.btn_delete.TabIndex = 62
Me.btn_delete.Text = "Delete"
AddHandler Me.btn_delete.Click, New System.EventHandler(AddressOf
Me.btn_delete_Click)
Me.btn_delete_all.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btn_delete_all.Location = New System.Drawing.Point(136, 8)
Me.btn_delete_all.Name = "btn_delete_all"
Me.btn_delete_all.TabIndex = 63
Me.btn_delete_all.Text = "Delete All"
AddHandler Me.btn_delete_all.Click, New System.EventHandler(AddressOf
Me.btn_delete_all_Click)
Me.txt_message_index.Location = New System.Drawing.Point(8, 8)
Me.txt_message_index.Name = "txt_message_index"
Me.txt_message_index.Size = New System.Drawing.Size(40, 20)
Me.txt_message_index.TabIndex = 64
Me.txt_message_index.Text = ""
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(488, 310)
Me.Controls.Add(Me.txt_message_index)
Me.Controls.Add(Me.btn_delete_all)
Me.Controls.Add(Me.btn_delete)
Me.Controls.Add(Me.dataGrid1)
Me.Name = "Delete"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Delete"
AddHandler Me.Load, New System.EventHandler(AddressOf Me.Delete_Load)
(CType((Me.dataGrid1), System.ComponentModel.ISupportInitialize)).EndInit()
Me.ResumeLayout(False)
End Sub

Private Sub Delete_Load(ByVal sender As Object, ByVal e As System.EventArgs)


dataGrid1.PreferredColumnWidth = 100
dt.Columns.Add("Index", GetType(Integer))
dt.Columns.Add("Sender", GetType(String))
dt.Columns.Add("Time", GetType(String))
dt.Columns.Add("Message", GetType(String))
ReadMessage()
End Sub

Private Sub ReadMessage()


Cursor.Current = Cursors.WaitCursor
Dim storage As String = GetMessageStorage()

Try
Dim messages As DecodedShortMessage() =
CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage)

For Each message As DecodedShortMessage In messages


ShowMessage(message.Data, message.Index)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Cursor.Current = Cursors.[Default]
End Sub

Private Sub BindGrid(ByVal pdu As SmsPdu, ByVal index As Integer)


Dim dr As DataRow = dt.NewRow()
Dim data As SmsDeliverPdu = CType(pdu, SmsDeliverPdu)
dr(0) = index.ToString()
dr(1) = data.OriginatingAddress.ToString()
dr(2) = data.SCTimestamp.ToString()
dr(3) = data.UserDataText
dt.Rows.Add(dr)
dataGrid1.DataSource = dt
End Sub

Private Sub ShowMessage(ByVal pdu As SmsPdu, ByVal index As Integer)


If TypeOf pdu Is SmsSubmitPdu Then
Dim data As SmsSubmitPdu = CType(pdu, SmsSubmitPdu)
Return
End If

If TypeOf pdu Is SmsDeliverPdu Then


Dim data As SmsDeliverPdu = CType(pdu, SmsDeliverPdu)
BindGrid(pdu, index)
Return
End If

If TypeOf pdu Is SmsStatusReportPdu Then


Dim data As SmsStatusReportPdu = CType(pdu, SmsStatusReportPdu)
Return
End If
End Sub

Private Function StatusToString(ByVal status As PhoneMessageStatus) As String


Dim ret As String

Select Case status


Case PhoneMessageStatus.All
ret = "All"
Case PhoneMessageStatus.ReceivedRead
ret = "Read"
Case PhoneMessageStatus.ReceivedUnread
ret = "Unread"
Case PhoneMessageStatus.StoredSent
ret = "Sent"
Case PhoneMessageStatus.StoredUnsent
ret = "Unsent"
Case Else
ret = "Unknown (" & status.ToString() & ")"
End Select

Return ret
End Function

Private Function GetMessageStorage() As String


Dim storage As String = PhoneStorageType.Sim
Return storage
End Function

Private Sub btn_delete_all_Click(ByVal sender As Object, ByVal e As System.EventArgs)


If Not Confirmed() Then Return
Cursor.Current = Cursors.WaitCursor
Dim storage As String = GetMessageStorage()

Try
CommSetting.comm.DeleteMessages(DeleteScope.All, storage)
dt.Clear()
dataGrid1.DataSource = dt
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Cursor.Current = Cursors.[Default]
End Sub

Private Function Confirmed() As Boolean


Return (MessageBox.Show(Me, "Really?", "Warning", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) = DialogResult.Yes)
End Function

Private Sub dataGrid1_MouseDown(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs)
Dim myHitTest As System.Windows.Forms.DataGrid.HitTestInfo
myHitTest = dataGrid1.HitTest(e.X, e.Y)
txt_message_index.Text = dataGrid1(myHitTest.Row, 0).ToString()
End Sub

Private Sub btn_delete_Click(ByVal sender As Object, ByVal e As System.EventArgs)


If txt_message_index.Text.Equals("") = True Then
MessageBox.Show("Please Click on Grid", "Message", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Return
End If

Dim index As Integer

Try
index = Integer.Parse(txt_message_index.Text)
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
End Try

If Not Confirmed() Then Return


Cursor.Current = Cursors.WaitCursor
Dim storage As String = GetMessageStorage()

Try
CommSetting.comm.DeleteMessage(index, storage)
MessageBox.Show("Message With Index " & index & " Deleted", "Message",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Cursor.Current = Cursors.[Default]
dt.Clear()
dataGrid1.DataSource = Nothing
ReadMessage()
End Sub
End Class
End Namespace
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports GsmComm.GsmCommunication
Imports System.Runtime.InteropServices

Namespace SMS
Public Class frmConnection
Inherits System.Windows.Forms.Form

Private lblTimeout As System.Windows.Forms.Label


Private lblBaudRate As System.Windows.Forms.Label
Private cboTimeout As System.Windows.Forms.ComboBox
Private lblPort As System.Windows.Forms.Label
Private cboPort As System.Windows.Forms.ComboBox
Private cboBaudRate As System.Windows.Forms.ComboBox
Private btnOK As System.Windows.Forms.Button
Private btnCancel As System.Windows.Forms.Button
Private btnTest As System.Windows.Forms.Button
Private components As System.ComponentModel.Container = Nothing
Private port As Integer
Private baudRate As Integer
Private timeout As Integer

Public Sub New()


InitializeComponent()
End Sub

Protected Overrides Sub Dispose(ByVal disposing As Boolean)


If disposing Then

If components IsNot Nothing Then


components.Dispose()
End If
End If

MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()


Me.lblTimeout = New System.Windows.Forms.Label()
Me.lblBaudRate = New System.Windows.Forms.Label()
Me.cboTimeout = New System.Windows.Forms.ComboBox()
Me.lblPort = New System.Windows.Forms.Label()
Me.cboPort = New System.Windows.Forms.ComboBox()
Me.cboBaudRate = New System.Windows.Forms.ComboBox()
Me.btnOK = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.btnTest = New System.Windows.Forms.Button()
Me.SuspendLayout()
Me.lblTimeout.Location = New System.Drawing.Point(33, 64)
Me.lblTimeout.Name = "lblTimeout"
Me.lblTimeout.TabIndex = 4
Me.lblTimeout.Text = "Ti&meout (ms):"
Me.lblTimeout.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.lblBaudRate.Location = New System.Drawing.Point(33, 40)
Me.lblBaudRate.Name = "lblBaudRate"
Me.lblBaudRate.TabIndex = 2
Me.lblBaudRate.Text = "&Baud rate:"
Me.lblBaudRate.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.cboTimeout.Location = New System.Drawing.Point(145, 64)
Me.cboTimeout.Name = "cboTimeout"
Me.cboTimeout.Size = New System.Drawing.Size(104, 21)
Me.cboTimeout.TabIndex = 5
Me.lblPort.Location = New System.Drawing.Point(33, 16)
Me.lblPort.Name = "lblPort"
Me.lblPort.Size = New System.Drawing.Size(88, 23)
Me.lblPort.TabIndex = 0
Me.lblPort.Text = "&COM-Port:"
Me.lblPort.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.cboPort.Location = New System.Drawing.Point(145, 16)
Me.cboPort.Name = "cboPort"
Me.cboPort.Size = New System.Drawing.Size(104, 21)
Me.cboPort.TabIndex = 1
Me.cboBaudRate.Location = New System.Drawing.Point(145, 40)
Me.cboBaudRate.Name = "cboBaudRate"
Me.cboBaudRate.Size = New System.Drawing.Size(104, 21)
Me.cboBaudRate.TabIndex = 3
Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnOK.Location = New System.Drawing.Point(104, 112)
Me.btnOK.Name = "btnOK"
Me.btnOK.TabIndex = 7
Me.btnOK.Text = "OK"
AddHandler Me.btnOK.Click, New System.EventHandler(AddressOf Me.btnOK_Click)
Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnCancel.Location = New System.Drawing.Point(192, 112)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.TabIndex = 8
Me.btnCancel.Text = "Cancel"
Me.btnTest.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnTest.Location = New System.Drawing.Point(16, 112)
Me.btnTest.Name = "btnTest"
Me.btnTest.TabIndex = 6
Me.btnTest.Text = "&Test"
AddHandler Me.btnTest.Click, New System.EventHandler(AddressOf Me.btnTest_Click)
Me.AcceptButton = Me.btnOK
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.CancelButton = Me.btnCancel
Me.ClientSize = New System.Drawing.Size(282, 152)
Me.Controls.Add(Me.btnTest)
Me.Controls.Add(Me.btnCancel)
Me.Controls.Add(Me.btnOK)
Me.Controls.Add(Me.lblTimeout)
Me.Controls.Add(Me.lblBaudRate)
Me.Controls.Add(Me.cboTimeout)
Me.Controls.Add(Me.lblPort)
Me.Controls.Add(Me.cboPort)
Me.Controls.Add(Me.cboBaudRate)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmConnection"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
Me.Text = "Connection settings"
AddHandler Me.Load, New System.EventHandler(AddressOf Me.frmConnection_Load)
Me.ResumeLayout(False)
End Sub

Public Sub SetData(ByVal port As Integer, ByVal baudRate As Integer, ByVal timeout As
Integer)
Me.port = port
Me.baudRate = baudRate
Me.timeout = timeout
End Sub

Public Sub GetData(<Out> ByRef port As Integer, <Out> ByRef baudRate As Integer, <Out>
ByRef timeout As Integer)
port = Me.port
baudRate = Me.baudRate
timeout = Me.timeout
End Sub

Private Function EnterNewSettings() As Boolean


Dim newPort As Integer
Dim newBaudRate As Integer
Dim newTimeout As Integer

Try
newPort = Integer.Parse(cboPort.Text)
Catch __unusedException1__ As Exception
MessageBox.Show(Me, "Invalid port number.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
cboPort.Focus()
Return False
End Try

Try
newBaudRate = Integer.Parse(cboBaudRate.Text)
Catch __unusedException1__ As Exception
MessageBox.Show(Me, "Invalid baud rate.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
cboBaudRate.Focus()
Return False
End Try

Try
newTimeout = Integer.Parse(cboTimeout.Text)
Catch __unusedException1__ As Exception
MessageBox.Show(Me, "Invalid timeout value.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
cboTimeout.Focus()
Return False
End Try

SetData(newPort, newBaudRate, newTimeout)


Return True
End Function

Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs)


If Not EnterNewSettings() Then DialogResult = DialogResult.None
End Sub

Private Sub frmConnection_Load(ByVal sender As Object, ByVal e As System.EventArgs)


cboPort.Items.Add("1")
cboPort.Items.Add("2")
cboPort.Items.Add("3")
cboPort.Items.Add("4")
cboPort.Items.Add("5")
cboPort.Items.Add("6")
cboPort.Items.Add("7")
cboPort.Text = port.ToString()
cboBaudRate.Items.Add("9600")
cboBaudRate.Items.Add("19200")
cboBaudRate.Items.Add("38400")
cboBaudRate.Items.Add("57600")
cboBaudRate.Items.Add("115200")
cboBaudRate.Text = baudRate.ToString()
cboTimeout.Items.Add("150")
cboTimeout.Items.Add("300")
cboTimeout.Items.Add("600")
cboTimeout.Items.Add("900")
cboTimeout.Items.Add("1200")
cboTimeout.Items.Add("1500")
cboTimeout.Items.Add("1800")
cboTimeout.Items.Add("2000")
cboTimeout.Text = timeout.ToString()
End Sub

Private Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs)


If Not EnterNewSettings() Then Return
Cursor.Current = Cursors.WaitCursor
Dim comm As GsmCommMain = New GsmCommMain(port, baudRate, timeout)

Try
comm.Open()

While Not comm.IsConnected()


Cursor.Current = Cursors.[Default]

If MessageBox.Show(Me, "No phone connected.", "Connection setup",


MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation) = DialogResult.Cancel Then
comm.Close()
Return
End If

Cursor.Current = Cursors.WaitCursor
End While

comm.Close()
Catch ex As Exception
MessageBox.Show(Me, "Connection error: " & ex.Message, "Connection setup",
MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
End Try

MessageBox.Show(Me, "Successfully connected to the phone.", "Connection setup",


MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
End Namespace
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports GsmComm.PduConverter
Imports GsmComm.GsmCommunication

Namespace SMS
Public Class Receive
Inherits System.Windows.Forms.Form

Private btnReadMessage As System.Windows.Forms.Button


Private rbMessagePhone As System.Windows.Forms.RadioButton
Private rbMessageSIM As System.Windows.Forms.RadioButton
Private txtOutput As System.Windows.Forms.TextBox
Private groupBox1 As System.Windows.Forms.GroupBox
Private dataGrid1 As System.Windows.Forms.DataGrid
Private components As System.ComponentModel.Container = Nothing
Private dt As DataTable = New DataTable()
Private Delegate Sub SetTextCallback(ByVal text As String)

Public Sub New()


InitializeComponent()
End Sub

Protected Overrides Sub Dispose(ByVal disposing As Boolean)


If disposing Then

If components IsNot Nothing Then


components.Dispose()
End If
End If

MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()


Me.btnReadMessage = New System.Windows.Forms.Button()
Me.rbMessagePhone = New System.Windows.Forms.RadioButton()
Me.rbMessageSIM = New System.Windows.Forms.RadioButton()
Me.txtOutput = New System.Windows.Forms.TextBox()
Me.groupBox1 = New System.Windows.Forms.GroupBox()
Me.dataGrid1 = New System.Windows.Forms.DataGrid()
Me.groupBox1.SuspendLayout()
(CType((Me.dataGrid1), System.ComponentModel.ISupportInitialize)).BeginInit()
Me.SuspendLayout()
Me.btnReadMessage.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnReadMessage.Location = New System.Drawing.Point(192, 80)
Me.btnReadMessage.Name = "btnReadMessage"
Me.btnReadMessage.Size = New System.Drawing.Size(112, 24)
Me.btnReadMessage.TabIndex = 17
Me.btnReadMessage.Text = "Read All Messages"
AddHandler Me.btnReadMessage.Click, New System.EventHandler(AddressOf
Me.btnReadMessage_Click)
Me.rbMessagePhone.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.rbMessagePhone.Location = New System.Drawing.Point(16, 56)
Me.rbMessagePhone.Name = "rbMessagePhone"
Me.rbMessagePhone.Size = New System.Drawing.Size(64, 24)
Me.rbMessagePhone.TabIndex = 25
Me.rbMessagePhone.Text = "Phone"
Me.rbMessageSIM.Checked = True
Me.rbMessageSIM.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.rbMessageSIM.Location = New System.Drawing.Point(16, 24)
Me.rbMessageSIM.Name = "rbMessageSIM"
Me.rbMessageSIM.Size = New System.Drawing.Size(64, 24)
Me.rbMessageSIM.TabIndex = 24
Me.rbMessageSIM.TabStop = True
Me.rbMessageSIM.Text = "SIM"
Me.txtOutput.Location = New System.Drawing.Point(8, 304)
Me.txtOutput.Multiline = True
Me.txtOutput.Name = "txtOutput"
Me.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtOutput.Size = New System.Drawing.Size(448, 144)
Me.txtOutput.TabIndex = 57
Me.txtOutput.Text = ""
Me.groupBox1.Controls.Add(Me.rbMessageSIM)
Me.groupBox1.Controls.Add(Me.rbMessagePhone)
Me.groupBox1.Location = New System.Drawing.Point(8, 8)
Me.groupBox1.Name = "groupBox1"
Me.groupBox1.Size = New System.Drawing.Size(176, 96)
Me.groupBox1.TabIndex = 58
Me.groupBox1.TabStop = False
Me.groupBox1.Text = "Message Storage"
Me.dataGrid1.DataMember = ""
Me.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.dataGrid1.Location = New System.Drawing.Point(8, 120)
Me.dataGrid1.Name = "dataGrid1"
Me.dataGrid1.Size = New System.Drawing.Size(448, 176)
Me.dataGrid1.TabIndex = 59
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(464, 454)
Me.Controls.Add(Me.dataGrid1)
Me.Controls.Add(Me.groupBox1)
Me.Controls.Add(Me.txtOutput)
Me.Controls.Add(Me.btnReadMessage)
Me.Name = "Receive"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Read Messages"
AddHandler Me.Load, New System.EventHandler(AddressOf Me.Receive_Load)
Me.groupBox1.ResumeLayout(False)
(CType((Me.dataGrid1), System.ComponentModel.ISupportInitialize)).EndInit()
Me.ResumeLayout(False)
End Sub

Private Sub btnReadMessage_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Cursor.Current = Cursors.WaitCursor
Dim storage As String = GetMessageStorage()

Try
Dim messages As DecodedShortMessage() =
CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage)

For Each message As DecodedShortMessage In messages


Output(String.Format("Message status = {0}, Location = {1}/{2}",
StatusToString(message.Status), message.Storage, message.Index))
ShowMessage(message.Data)
Output("")
Next

Output(String.Format("{0,9} messages read.", messages.Length.ToString()))


Output("")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Cursor.Current = Cursors.[Default]
End Sub

Private Sub BindGrid(ByVal pdu As SmsPdu)


Dim dr As DataRow = dt.NewRow()
Dim data As SmsDeliverPdu = CType(pdu, SmsDeliverPdu)
dr(0) = data.OriginatingAddress.ToString()
dr(1) = data.SCTimestamp.ToString()
dr(2) = data.UserDataText
dt.Rows.Add(dr)
dataGrid1.DataSource = dt
End Sub

Private Sub ShowMessage(ByVal pdu As SmsPdu)


If TypeOf pdu Is SmsSubmitPdu Then
Dim data As SmsSubmitPdu = CType(pdu, SmsSubmitPdu)
Output("SENT/UNSENT MESSAGE")
Output("Recipient: " & data.DestinationAddress)
Output("Message text: " & data.UserDataText)
Output("-------------------------------------------------------------------")
Return
End If

If TypeOf pdu Is SmsDeliverPdu Then


Dim data As SmsDeliverPdu = CType(pdu, SmsDeliverPdu)
Output("RECEIVED MESSAGE")
Output("Sender: " & data.OriginatingAddress)
Output("Sent: " & data.SCTimestamp.ToString())
Output("Message text: " & data.UserDataText)
Output("-------------------------------------------------------------------")
BindGrid(pdu)
Return
End If

If TypeOf pdu Is SmsStatusReportPdu Then


Dim data As SmsStatusReportPdu = CType(pdu, SmsStatusReportPdu)
Output("STATUS REPORT")
Output("Recipient: " & data.RecipientAddress)
Output("Status: " & data.Status.ToString())
Output("Timestamp: " & data.DischargeTime.ToString())
Output("Message ref: " & data.MessageReference.ToString())
Output("-------------------------------------------------------------------")
Return
End If

Output("Unknown message type: " & pdu.[GetType]().ToString())


End Sub

Private Function StatusToString(ByVal status As PhoneMessageStatus) As String


Dim ret As String

Select Case status


Case PhoneMessageStatus.All
ret = "All"
Case PhoneMessageStatus.ReceivedRead
ret = "Read"
Case PhoneMessageStatus.ReceivedUnread
ret = "Unread"
Case PhoneMessageStatus.StoredSent
ret = "Sent"
Case PhoneMessageStatus.StoredUnsent
ret = "Unsent"
Case Else
ret = "Unknown (" & status.ToString() & ")"
End Select

Return ret
End Function

Private Function GetMessageStorage() As String


Dim storage As String = String.Empty
If rbMessageSIM.Checked Then storage = PhoneStorageType.Sim
If rbMessagePhone.Checked Then storage = PhoneStorageType.Phone

If storage.Length = 0 Then
Throw New ApplicationException("Unknown message storage.")
Else
Return storage
End If
End Function
Private Sub Output(ByVal text As String)
If Me.txtOutput.InvokeRequired Then
Dim stc As SetTextCallback = New SetTextCallback(AddressOf Output)
Me.Invoke(stc, New Object() {text})
Else
txtOutput.AppendText(text)
txtOutput.AppendText(vbCrLf)
End If
End Sub

Private Sub Receive_Load(ByVal sender As Object, ByVal e As System.EventArgs)


dt.Columns.Add("Sender", GetType(String))
dt.Columns.Add("Time", GetType(String))
dt.Columns.Add("Message", GetType(String))
End Sub

Private Sub Output(ByVal text As String, ParamArray args As Object())


Dim msg As String = String.Format(text, args)
Output(msg)
End Sub
End Class
End Namespace
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports GsmComm.PduConverter
Imports GsmComm.GsmCommunication

Namespace SMS
Public Class Send
Inherits System.Windows.Forms.Form

Private pictureBox1 As System.Windows.Forms.PictureBox


Private label1 As System.Windows.Forms.Label
Private txt_destination_numbers As System.Windows.Forms.TextBox
Private label2 As System.Windows.Forms.Label
Private txt_text_remaining As System.Windows.Forms.TextBox
Private btnSendMessage As System.Windows.Forms.Button
Private BtnClear As System.Windows.Forms.Button
Private txt_message As System.Windows.Forms.TextBox
Private txtOutput As System.Windows.Forms.TextBox
Private chkUnicode As System.Windows.Forms.CheckBox
Private chkAlert As System.Windows.Forms.CheckBox
Private groupBox1 As System.Windows.Forms.GroupBox
Private label19 As System.Windows.Forms.Label
Private txtSendTimes As System.Windows.Forms.TextBox
Private chkMultipleTimes As System.Windows.Forms.CheckBox
Private components As System.ComponentModel.Container = Nothing
Private Delegate Sub SetTextCallback(ByVal text As String)

Public Sub New()


InitializeComponent()
End Sub

Protected Overrides Sub Dispose(ByVal disposing As Boolean)


If disposing Then

If components IsNot Nothing Then


components.Dispose()
End If
End If

MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()


Dim resources As System.Resources.ResourceManager = New
System.Resources.ResourceManager(GetType(Send))
Me.pictureBox1 = New System.Windows.Forms.PictureBox()
Me.label1 = New System.Windows.Forms.Label()
Me.txt_destination_numbers = New System.Windows.Forms.TextBox()
Me.label2 = New System.Windows.Forms.Label()
Me.txt_message = New System.Windows.Forms.TextBox()
Me.txt_text_remaining = New System.Windows.Forms.TextBox()
Me.btnSendMessage = New System.Windows.Forms.Button()
Me.BtnClear = New System.Windows.Forms.Button()
Me.txtOutput = New System.Windows.Forms.TextBox()
Me.chkUnicode = New System.Windows.Forms.CheckBox()
Me.chkAlert = New System.Windows.Forms.CheckBox()
Me.groupBox1 = New System.Windows.Forms.GroupBox()
Me.txtSendTimes = New System.Windows.Forms.TextBox()
Me.chkMultipleTimes = New System.Windows.Forms.CheckBox()
Me.label19 = New System.Windows.Forms.Label()
Me.groupBox1.SuspendLayout()
Me.SuspendLayout()
Me.pictureBox1.BackgroundImage =
(CType((resources.GetObject("pictureBox1.BackgroundImage")), System.Drawing.Image))
Me.pictureBox1.Location = New System.Drawing.Point(0, 0)
Me.pictureBox1.Name = "pictureBox1"
Me.pictureBox1.Size = New System.Drawing.Size(368, 104)
Me.pictureBox1.TabIndex = 0
Me.pictureBox1.TabStop = False
Me.label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (CByte((0))))
Me.label1.Location = New System.Drawing.Point(0, 112)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(144, 24)
Me.label1.TabIndex = 1
Me.label1.Text = "Destination Number :"
Me.txt_destination_numbers.Location = New System.Drawing.Point(0, 136)
Me.txt_destination_numbers.Name = "txt_destination_numbers"
Me.txt_destination_numbers.Size = New System.Drawing.Size(224, 20)
Me.txt_destination_numbers.TabIndex = 2
Me.txt_destination_numbers.Text = ""
Me.label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 10F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (CByte((0))))
Me.label2.Location = New System.Drawing.Point(0, 168)
Me.label2.Name = "label2"
Me.label2.Size = New System.Drawing.Size(72, 16)
Me.label2.TabIndex = 3
Me.label2.Text = "Message :"
Me.txt_message.Location = New System.Drawing.Point(0, 192)
Me.txt_message.Multiline = True
Me.txt_message.Name = "txt_message"
Me.txt_message.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txt_message.Size = New System.Drawing.Size(224, 112)
Me.txt_message.TabIndex = 4
Me.txt_message.Text = ""
AddHandler Me.txt_message.TextChanged, New System.EventHandler(AddressOf
Me.textBox1_TextChanged)
Me.txt_text_remaining.BackColor = System.Drawing.SystemColors.Control
Me.txt_text_remaining.Enabled = False
Me.txt_text_remaining.Location = New System.Drawing.Point(224, 288)
Me.txt_text_remaining.Name = "txt_text_remaining"
Me.txt_text_remaining.Size = New System.Drawing.Size(40, 20)
Me.txt_text_remaining.TabIndex = 5
Me.txt_text_remaining.Text = "160"
Me.btnSendMessage.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.btnSendMessage.Location = New System.Drawing.Point(144, 320)
Me.btnSendMessage.Name = "btnSendMessage"
Me.btnSendMessage.Size = New System.Drawing.Size(80, 24)
Me.btnSendMessage.TabIndex = 16
Me.btnSendMessage.Text = "Send"
AddHandler Me.btnSendMessage.Click, New System.EventHandler(AddressOf
Me.btnSendMessage_Click)
Me.BtnClear.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.BtnClear.Location = New System.Drawing.Point(56, 320)
Me.BtnClear.Name = "BtnClear"
Me.BtnClear.Size = New System.Drawing.Size(80, 24)
Me.BtnClear.TabIndex = 17
Me.BtnClear.Text = "Clear"
AddHandler Me.BtnClear.Click, New System.EventHandler(AddressOf
Me.BtnClear_Click)
Me.txtOutput.Location = New System.Drawing.Point(0, 352)
Me.txtOutput.Multiline = True
Me.txtOutput.Name = "txtOutput"
Me.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtOutput.Size = New System.Drawing.Size(504, 120)
Me.txtOutput.TabIndex = 56
Me.txtOutput.Text = ""
Me.chkUnicode.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.chkUnicode.Location = New System.Drawing.Point(16, 56)
Me.chkUnicode.Name = "chkUnicode"
Me.chkUnicode.Size = New System.Drawing.Size(208, 24)
Me.chkUnicode.TabIndex = 58
Me.chkUnicode.Text = "Send as Unicode (UCS2)"
Me.chkAlert.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.chkAlert.Location = New System.Drawing.Point(16, 24)
Me.chkAlert.Name = "chkAlert"
Me.chkAlert.Size = New System.Drawing.Size(176, 24)
Me.chkAlert.TabIndex = 57
Me.chkAlert.Text = "Request immediate display (alert)"
Me.groupBox1.Controls.Add(Me.chkUnicode)
Me.groupBox1.Controls.Add(Me.chkAlert)
Me.groupBox1.Controls.Add(Me.txtSendTimes)
Me.groupBox1.Controls.Add(Me.chkMultipleTimes)
Me.groupBox1.Controls.Add(Me.label19)
Me.groupBox1.Location = New System.Drawing.Point(240, 112)
Me.groupBox1.Name = "groupBox1"
Me.groupBox1.Size = New System.Drawing.Size(264, 128)
Me.groupBox1.TabIndex = 59
Me.groupBox1.TabStop = False
Me.groupBox1.Text = "Option"
Me.txtSendTimes.Location = New System.Drawing.Point(120, 88)
Me.txtSendTimes.Name = "txtSendTimes"
Me.txtSendTimes.Size = New System.Drawing.Size(48, 20)
Me.txtSendTimes.TabIndex = 61
Me.txtSendTimes.Text = "1"
Me.chkMultipleTimes.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.chkMultipleTimes.Location = New System.Drawing.Point(16, 88)
Me.chkMultipleTimes.Name = "chkMultipleTimes"
Me.chkMultipleTimes.TabIndex = 60
Me.chkMultipleTimes.Text = "Send message"
Me.label19.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.label19.Location = New System.Drawing.Point(176, 88)
Me.label19.Name = "label19"
Me.label19.Size = New System.Drawing.Size(72, 23)
Me.label19.TabIndex = 62
Me.label19.Text = "times"
Me.label19.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(504, 478)
Me.Controls.Add(Me.groupBox1)
Me.Controls.Add(Me.txtOutput)
Me.Controls.Add(Me.BtnClear)
Me.Controls.Add(Me.btnSendMessage)
Me.Controls.Add(Me.txt_text_remaining)
Me.Controls.Add(Me.txt_message)
Me.Controls.Add(Me.label2)
Me.Controls.Add(Me.txt_destination_numbers)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.pictureBox1)
Me.Name = "Send"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Send SMS"
AddHandler Me.Load, New System.EventHandler(AddressOf Me.Send_Load)
Me.groupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub

Private Sub textBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)


Dim remaining As Integer = Integer.Parse(txt_text_remaining.Text.Trim())
remaining -= 1
txt_text_remaining.Text = remaining.ToString()
End Sub

Private Sub BtnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs)


txt_message.Text = ""
txt_message.Focus()
End Sub

Private Sub btnSendMessage_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Cursor.Current = Cursors.WaitCursor

Try
Dim pdu As SmsSubmitPdu
Dim alert As Boolean = chkAlert.Checked
Dim unicode As Boolean = chkUnicode.Checked
If Not alert AndAlso Not unicode Then
pdu = New SmsSubmitPdu(txt_message.Text, txt_destination_numbers.Text, "")
Else
Dim dcs As Byte

If Not alert AndAlso unicode Then


dcs = DataCodingScheme.NoClass_16Bit
ElseIf alert AndAlso Not unicode Then
dcs = DataCodingScheme.Class0_7Bit
ElseIf alert AndAlso unicode Then
dcs = DataCodingScheme.Class0_16Bit
Else
dcs = DataCodingScheme.NoClass_7Bit
End If

pdu = New SmsSubmitPdu(txt_message.Text, txt_destination_numbers.Text, "",


dcs)
End If

Dim times As Integer = If(chkMultipleTimes.Checked,


Integer.Parse(txtSendTimes.Text), 1)

For i As Integer = 0 To times - 1


CommSetting.comm.SendMessage(pdu)
Output("Message {0} of {1} sent.", i + 1, times)
Output("")
Next

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

Cursor.Current = Cursors.[Default]
End Sub

Private Sub Output(ByVal text As String)


If Me.txtOutput.InvokeRequired Then
Dim stc As SetTextCallback = New SetTextCallback(AddressOf Output)
Me.Invoke(stc, New Object() {text})
Else
txtOutput.AppendText(text)
txtOutput.AppendText(vbCrLf)
End If
End Sub

Private Sub Send_Load(ByVal sender As Object, ByVal e As System.EventArgs)


chkMultipleTimes.Checked = True
End Sub

Private Sub Output(ByVal text As String, ParamArray args As Object())


Dim msg As String = String.Format(text, args)
Output(msg)
End Sub
End Class
End Namespace
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports GsmComm.GsmCommunication
Imports GsmComm.PduConverter
Imports System.Threading

Namespace SMS
Public Class Form1
Inherits System.Windows.Forms.Form

Private mainMenu1 As System.Windows.Forms.MainMenu


Private menuItem1 As System.Windows.Forms.MenuItem
Private lbl_phone_status As System.Windows.Forms.Label
Private txtOutput As System.Windows.Forms.TextBox
Private label1 As System.Windows.Forms.Label
Private mnu_send As System.Windows.Forms.MenuItem
Private mnu_read As System.Windows.Forms.MenuItem
Private Delegate Sub SetTextCallback(ByVal text As String)
Private comm_settings As CommSetting = New CommSetting()
Private mnudelete As System.Windows.Forms.MenuItem
Private components As System.ComponentModel.Container = Nothing

Public Sub New()


InitializeComponent()
End Sub

Protected Overrides Sub Dispose(ByVal disposing As Boolean)


If disposing Then

If components IsNot Nothing Then


components.Dispose()
End If
End If

MyBase.Dispose(disposing)
End Sub

Private Sub InitializeComponent()


Me.mainMenu1 = New System.Windows.Forms.MainMenu()
Me.menuItem1 = New System.Windows.Forms.MenuItem()
Me.mnu_send = New System.Windows.Forms.MenuItem()
Me.mnu_read = New System.Windows.Forms.MenuItem()
Me.lbl_phone_status = New System.Windows.Forms.Label()
Me.txtOutput = New System.Windows.Forms.TextBox()
Me.label1 = New System.Windows.Forms.Label()
Me.mnudelete = New System.Windows.Forms.MenuItem()
Me.SuspendLayout()
Me.mainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.menuItem1})
Me.menuItem1.Index = 0
Me.menuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem()
{Me.mnu_send, Me.mnu_read, Me.mnudelete})
Me.menuItem1.Text = "Message"
Me.mnu_send.Index = 0
Me.mnu_send.Text = "Send"
AddHandler Me.mnu_send.Click, New System.EventHandler(AddressOf
Me.mnu_send_click)
Me.mnu_read.Index = 1
Me.mnu_read.Text = "Read"
AddHandler Me.mnu_read.Click, New System.EventHandler(AddressOf
Me.mnu_read_click)
Me.lbl_phone_status.Anchor = (CType(((System.Windows.Forms.AnchorStyles.Bottom
Or System.Windows.Forms.AnchorStyles.Right)), System.Windows.Forms.AnchorStyles))
Me.lbl_phone_status.BackColor = System.Drawing.Color.White
Me.lbl_phone_status.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lbl_phone_status.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (CByte((0))))
Me.lbl_phone_status.ForeColor = System.Drawing.Color.Red
Me.lbl_phone_status.Location = New System.Drawing.Point(360, 368)
Me.lbl_phone_status.Name = "lbl_phone_status"
Me.lbl_phone_status.Size = New System.Drawing.Size(196, 23)
Me.lbl_phone_status.TabIndex = 54
Me.lbl_phone_status.Text = "NO PHONE CONNECTED"
Me.lbl_phone_status.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.lbl_phone_status.UseMnemonic = False
Me.txtOutput.Enabled = False
Me.txtOutput.Location = New System.Drawing.Point(88, 72)
Me.txtOutput.Multiline = True
Me.txtOutput.Name = "txtOutput"
Me.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtOutput.Size = New System.Drawing.Size(472, 272)
Me.txtOutput.TabIndex = 55
Me.txtOutput.Text = ""
Me.label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 10F,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, (CByte((0))))
Me.label1.Location = New System.Drawing.Point(88, 40)
Me.label1.Name = "label1"
Me.label1.Size = New System.Drawing.Size(104, 24)
Me.label1.TabIndex = 56
Me.label1.Text = "Received SMS :"
Me.mnudelete.Index = 2
Me.mnudelete.Text = "Delete"
AddHandler Me.mnudelete.Click, New System.EventHandler(AddressOf
Me.mnudelete_Click)
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(656, 417)
Me.Controls.Add(Me.label1)
Me.Controls.Add(Me.txtOutput)
Me.Controls.Add(Me.lbl_phone_status)
Me.Menu = Me.mainMenu1
Me.Name = "Form1"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "SMS Server"
AddHandler Me.Closing, New System.ComponentModel.CancelEventHandler(AddressOf
Me.Form1_Closing)
AddHandler Me.Load, New System.EventHandler(AddressOf Me.Form1_Load)
Me.ResumeLayout(False)
End Sub

<STAThread>
Private Shared Sub Main()
Application.Run(New Form1())
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)


Dim port As Integer = GsmCommMain.DefaultPortNumber
Dim baudRate As Integer = 9600
Dim timeout As Integer = GsmCommMain.DefaultTimeout
Dim dlg As frmConnection = New frmConnection()
dlg.StartPosition = FormStartPosition.CenterScreen
dlg.SetData(port, baudRate, timeout)

If dlg.ShowDialog(Me) = DialogResult.OK Then


dlg.GetData(port, baudRate, timeout)
CommSetting.Comm_Port = port
CommSetting.Comm_BaudRate = baudRate
CommSetting.Comm_TimeOut = timeout
Else
Close()
Return
End If

Cursor.Current = Cursors.WaitCursor
CommSetting.comm = New GsmCommMain(port, baudRate, timeout)
Cursor.Current = Cursors.[Default]
AddHandler CommSetting.comm.PhoneConnected, New EventHandler(AddressOf
comm_PhoneConnected)
CommSetting.comm.MessageReceived += New
MessageReceivedEventHandler(AddressOf comm_MessageReceived)
Dim retry As Boolean

Do
retry = False

Try
Cursor.Current = Cursors.WaitCursor
CommSetting.comm.Open()
Cursor.Current = Cursors.[Default]
Catch __unusedException1__ As Exception
Cursor.Current = Cursors.[Default]
If MessageBox.Show(Me, "Unable to open the port.", "Error",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) = DialogResult.Retry Then
retry = True
Else
Close()
Return
End If
End Try
Loop While retry
End Sub

Private Delegate Sub ConnectedHandler(ByVal connected As Boolean)

Private Sub OnPhoneConnectionChange(ByVal connected As Boolean)


lbl_phone_status.Text = "CONNECTED"
End Sub

Private Sub comm_MessageReceived(ByVal sender As Object, ByVal e As


GsmComm.GsmCommunication.MessageReceivedEventArgs)
MessageReceived()
End Sub

Private Sub comm_PhoneConnected(ByVal sender As Object, ByVal e As EventArgs)


Me.Invoke(New ConnectedHandler(AddressOf OnPhoneConnectionChange), New
Object() {True})
End Sub

Private Function GetMessageStorage() As String


Dim storage As String = String.Empty
storage = PhoneStorageType.Sim

If storage.Length = 0 Then
Throw New ApplicationException("Unknown message storage.")
Else
Return storage
End If
End Function

Private Sub MessageReceived()


Cursor.Current = Cursors.WaitCursor
Dim storage As String = GetMessageStorage()
Dim messages As DecodedShortMessage() =
CommSetting.comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, storage)

For Each message As DecodedShortMessage In messages


Output(String.Format("Message status = {0}, Location = {1}/{2}",
StatusToString(message.Status), message.Storage, message.Index))
ShowMessage(message.Data)
Output("")
Next

Output(String.Format("{0,9} messages read.", messages.Length.ToString()))


Output("")
End Sub

Private Function StatusToString(ByVal status As PhoneMessageStatus) As String


Dim ret As String

Select Case status


Case PhoneMessageStatus.All
ret = "All"
Case PhoneMessageStatus.ReceivedRead
ret = "Read"
Case PhoneMessageStatus.ReceivedUnread
ret = "Unread"
Case PhoneMessageStatus.StoredSent
ret = "Sent"
Case PhoneMessageStatus.StoredUnsent
ret = "Unsent"
Case Else
ret = "Unknown (" & status.ToString() & ")"
End Select

Return ret
End Function

Private Sub Output(ByVal text As String)


If Me.txtOutput.InvokeRequired Then
Dim stc As SetTextCallback = New SetTextCallback(AddressOf Output)
Me.Invoke(stc, New Object() {text})
Else
txtOutput.AppendText(text)
txtOutput.AppendText(vbCrLf)
End If
End Sub

Private Sub ShowMessage(ByVal pdu As SmsPdu)


If TypeOf pdu Is SmsSubmitPdu Then
Dim data As SmsSubmitPdu = CType(pdu, SmsSubmitPdu)
Output("SENT/UNSENT MESSAGE")
Output("Recipient: " & data.DestinationAddress)
Output("Message text: " & data.UserDataText)
Output("-------------------------------------------------------------------")
Return
End If

If TypeOf pdu Is SmsDeliverPdu Then


Dim data As SmsDeliverPdu = CType(pdu, SmsDeliverPdu)
Output("RECEIVED MESSAGE")
Output("Sender: " & data.OriginatingAddress)
Output("Sent: " & data.SCTimestamp.ToString())
Output("Message text: " & data.UserDataText)
Output("-------------------------------------------------------------------")
Return
End If

If TypeOf pdu Is SmsStatusReportPdu Then


Dim data As SmsStatusReportPdu = CType(pdu, SmsStatusReportPdu)
Output("STATUS REPORT")
Output("Recipient: " & data.RecipientAddress)
Output("Status: " & data.Status.ToString())
Output("Timestamp: " & data.DischargeTime.ToString())
Output("Message ref: " & data.MessageReference.ToString())
Output("-------------------------------------------------------------------")
Return
End If

Output("Unknown message type: " & pdu.[GetType]().ToString())


End Sub

Private Sub mnu_send_click(ByVal sender As Object, ByVal e As System.EventArgs)


Dim send_sms As Send = New Send()
send_sms.Show()
End Sub

Private Sub mnu_read_click(ByVal sender As Object, ByVal e As System.EventArgs)


Dim receice_sms As Receive = New Receive()
receice_sms.Show()
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As


System.ComponentModel.CancelEventArgs)
If CommSetting.comm IsNot Nothing Then
RemoveHandler CommSetting.comm.PhoneConnected, New EventHandler(AddressOf
comm_PhoneConnected)
CommSetting.comm.MessageReceived -= New
MessageReceivedEventHandler(AddressOf comm_MessageReceived)
If CommSetting.comm IsNot Nothing AndAlso CommSetting.comm.IsOpen() Then
CommSetting.comm.Close()
CommSetting.comm = Nothing
End If
End Sub

Private Sub mnudelete_Click(ByVal sender As Object, ByVal e As System.EventArgs)


Dim delete As Delete = New Delete()
delete.Show()
End Sub
End Class
End Namespace

Potrebbero piacerti anche