📄 testcase.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 System.IO
Imports System.Reflection
Imports System.Collections
Imports System.Windows.Forms
Imports Dreamworld.Mobile.PhoneControllerSDK
Imports Dreamworld.Protocol.IrMC
Module TestCase
Sub Main()
'Note,I only test on Siemens CX6C, M55 and Nokia 6021
'You can add your phone to support list.
'Add your phone ModelID to SupportModel property.
Dim ap() As PluginServices.AvailablePlugin
Dim plugInFilePath As String = Path.GetDirectoryName(Application.ExecutablePath)
ap = PluginServices.FindPlugins(plugInFilePath, "Dreamworld.Mobile.PhoneControllerSDK.IPhoneController")
Dim port As String
Dim baudrate As Integer = 115200
Dim index As Integer
If PluginServices.AutoSearch(ap, port, index) = True Then
Console.WriteLine("Find phone on port :{0}", port)
Else
Console.WriteLine("Can't find phone. Press enter key to exit.")
Console.ReadLine()
Exit Sub
End If
Console.BufferHeight = 9999
Console.BufferWidth = 100
Console.Clear()
Console.WriteLine("Using plugin name={0}", ap(index).ClassName)
Console.WriteLine()
Dim phone As IPhoneController = DirectCast(PluginServices.CreateInstance(ap(index)), IPhoneController)
RunTestCase(port, baudrate, phone)
End Sub
Public Sub RunTestCase(ByVal Port As String, ByVal baudrate As Integer, ByVal phone As IPhoneController)
TestCase1(Port, baudrate, phone)
Console.WriteLine("Press enter key to next")
Console.ReadLine()
Console.Clear()
TestCase2(Port, baudrate, phone)
Console.WriteLine("Press enter key to next")
Console.ReadLine()
Console.Clear()
TestCase3(Port, baudrate, phone)
Console.WriteLine("Press enter key to next")
Console.ReadLine()
Console.Clear()
TestCase4(Port, baudrate, phone)
Console.WriteLine("Press enter key to next")
Console.ReadLine()
Console.Clear()
TestCase5(Port, baudrate, phone)
Console.WriteLine("Press enter key to exit")
Console.ReadLine()
End Sub
''' <summary>
''' Select plugin from Model ID
''' </summary>
''' <param name="ap">AvaliablePlugin</param>
''' <param name="baudrate">Speed</param>
''' <param name="port">Port name like "COM1:"</param>
''' <param name="CommPhoneClassName">The name of commphone class.</param>
''' <returns>Plugin number in AvialiablePlugin</returns>
''' <remarks></remarks>
Function SelectPlugin(ByVal port As String, ByVal baudrate As Integer, ByVal ap As PluginServices.AvailablePlugin(), ByVal CommPhoneClassName As String) As Integer
If ap Is Nothing Then
Throw New Exception("Not plugin found")
End If
Dim ModelID As String = String.Empty
'Find commbase class and get modelID
For i As Integer = 0 To ap.Length - 1
If ap(i).ClassName = CommPhoneClassName Then
Dim objPlugin As IPhoneController
objPlugin = DirectCast(PluginServices.CreateInstance(ap(i)), IPhoneController)
With objPlugin
.Connect(port, baudrate, 1000)
.SetStandard()
ModelID = .GetModelID()
.Disconnect()
End With
End If
Next
'Loop every plugin to find supported device.
For i As Integer = 0 To ap.Length - 1
Dim objPlugin As IPhoneController
objPlugin = DirectCast(PluginServices.CreateInstance(ap(i)), IPhoneController)
Dim supportedModel As String() = objPlugin.SupportedModel
For j As Integer = 0 To supportedModel.Length - 1
If ModelID = supportedModel(j) Then
Return i
End If
Next
Next
'If not found
Throw New NotSupportedException("Your phone are not supported")
End Function
''' <summary>
''' Test Phone Connect and Basic Information
''' </summary>
''' <remarks></remarks>
Sub TestCase1(ByVal port As String, ByVal baudrate As Integer, ByVal phone As IPhoneController)
'Test Connect
Try
Console.WriteLine("1.Test connect phone using given port and baudrate. This should success.")
Console.WriteLine(" Connected:{0}", phone.Connect(port, baudrate))
Catch e As Exception
Console.WriteLine(" Failed:{0}", e.Message)
End Try
'Test SetStandard
Try
Console.WriteLine("2.Test set standard. This should success.")
phone.SetStandard()
Console.WriteLine(" Success")
Catch ex As Exception
Console.WriteLine(" Failed to set standard:{0}", ex.Message)
End Try
'Test Get base information
Try
Console.WriteLine("3.Get your base information")
'Console.WriteLine(" IMSI:{0}", phone.GetIMSI)
Console.WriteLine(" Manufacture:{0}", phone.GetManufactureID)
Console.WriteLine(" ModelID:{0}", phone.GetModelID)
'Console.WriteLine(" OwnNumber:{0}", phone.GetOwnNumber)
Console.WriteLine(" BatteryCharege:{0}%", phone.GetBatteryCharge)
Console.WriteLine(" QualityOfService:-{0}mdB", phone.GetQualityOfService)
Console.WriteLine(" ServiceCenterNumber:{0}", phone.GetServiceCenterNumber)
Catch ex As Exception
Console.WriteLine(" Failed:{0}", ex.Message)
End Try
Try
Console.WriteLine("4.Disconnect phone:")
Console.WriteLine(phone.Disconnect())
Catch ex As Exception
Console.WriteLine(" Failed:{0}", ex.Message)
End Try
End Sub
''' <summary>
''' Test phonebook
''' </summary>
''' <remarks></remarks>
Sub TestCase2(ByVal port As String, ByVal baudrate As Integer, ByVal phone As IPhoneController)
Console.WriteLine("Test Case 2:")
'Test Connect
Try
Console.WriteLine("1.Test connect phone using given port and baudrate. This should success.")
Console.WriteLine(" Connected:{0}", phone.Connect(port, baudrate))
Console.WriteLine(" Set standard:{0}", phone.SetStandard)
Catch e As Exception
Console.WriteLine(" Failed:{0}", e.Message)
End Try
Dim lastIndex As Integer 'will be used later
Try
Console.WriteLine("2.Test getting all your phonebook entries from SIM card.")
Console.WriteLine(" Selecting phonebook to SIM card: {0}", phone.SelectPhonebookType(PhonebookType.SIMCard))
Console.WriteLine(" Reading phonebook, you may wait some seconds.")
Dim entries As PhonebookEntry() = phone.ReadAllPhonebookEntry()
If entries IsNot Nothing Then
For i As Integer = 0 To entries.Length - 1
With entries(i)
Console.WriteLine(" ID={0} Name={1} HomeNumber={2}", .Index, .Name, .SIMNumber)
If .Index > lastIndex Then lastIndex = .Index
End With
Next
Console.WriteLine(" Total entries: {0}", entries.Length)
End If
Catch ex As Exception
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -