Solved

Can I read and send SMS messages via a Bluetooth connected cell phone?

Posted on 2010-09-12
6
1,794 Views
Last Modified: 2013-11-27
I have a number of cell phones that can connect to my laptop via Bluetooth. At present I have to use the cell phone supplier's software to read and send SMS messages from my lapto but that doesn't provide for easy connectivity to my other databases.

Is it possible to write a MS Web Developer or MS Visual Basic express application that can read and send SMS messages from a connected cell phone (that I can then easily merge with data from my databases)?

And if it is possible then can I connect to virtually any cell phone via the Bluetooth interface? I.e. is the command set, or whatever is needed to extract and send the data, relatively consistent accross cell phone brands, or am I going to have to write a different interface for virtually every brand and make of cell phone that connects?
0
Comment
Question by:Rob4077
  • 5
6 Comments
 

Author Comment

by:Rob4077
ID: 33656852
After an afternoon of searching I have found some VB.Net sample code that first checks to find ports and then checks the selected ports to find the ones that are supposed to be modems. The problem is that it is not recognising Port 13 as a modem. However I have checked the Properties of my phone in the Phone and Modem list and it tells me it is attached to Com13. If I try to connect to it via Hyperterminal, Hyperterminal will connect to it and happily initiate a phone call using it.
Can anyone help me figure out what I need to do to get the code in the sample to find my modem. If I can do that I should be able to figure out how to send AT Commands to it to send and retrieve messages.
Attached is the code that the sample form is using. I have modified it a little from the original so that it checks 21 ports instead of only 4 as was the case in the original.
Firstly the code doesn't detect that port 13 is a modem and even if I get it to check port 13 specifically it doesn't recognise it as a modem.

' Copyright (c) Microsoft Corporation. All rights reserved.

Imports System.Text



Public Class MainForm



    ' Declare necessary class variables.

    Private CommPort As New RS232()

    Private IsModemFound As Boolean = False

    Private ModemPort As Integer = 0





    ' This subroutine checks for available ports on the local machine. It does 

    '   this by attempting to open ports 1 through 4.

    Private Sub CheckForPortsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForPortsButton.Click



        ' Check for Availability of each of the 4 Comm Ports, and

        '   place a check in the list box items that have openable ports.

        Dim i As Integer

        For i = 1 To 21

            WriteMessage("Testing COM" + i.ToString())

            If IsPortAvailable(i) Then

                ' Check the box for available ports.

                Me.PortsList.SetItemChecked(i - 1, True)

            Else

                ' Uncheck the box for unavailable ports.

                Me.PortsList.SetItemChecked(i - 1, False)

            End If

        Next

        ' Enable the Find Modems button.

        Me.CheckModemsButton.Enabled = True

    End Sub



    ' This subroutine attempts to send an AT command to any active Comm Ports.

    '   If a response is returned then a usable modem has been detected

    '   on that port.

    Private Sub CheckModemsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckModemsButton.Click

        Dim i As Integer

        For i = 0 To 21

            'Stop

            If Me.PortsList.GetItemChecked(i) Then

                ' Item is checked so it MIGHT be a valid port.

                ' Test for validity.

                If IsPortAvailable(i + 1) Then

                    ' Check if port responds to an AT command.

                    If IsPortAModem(i + 1) Then

                        ' Set the class variables to the last modem found.

                        Me.IsModemFound = True

                        Me.ModemPort = i + 1

                        ' Write message to the user.

                        WriteMessage("Port " + (i + 1).ToString() + _

                            " is a responsive modem.")

                    Else

                        ' Write message to the user.

                        WriteMessage("Port " + (i + 1).ToString() + _

                            " is not a responsive modem.")

                    End If

                Else

                    WriteMessage("Port " + (i + 1).ToString() + _

                            " is not a modem.")

                End If

            End If

        Next

        ' If a modem was found, enable the rest of the buttons, so the user

        '   can interact with the modem.

        If Me.IsModemFound Then

            Me.SelectedModemTextbox.Text = "Using Modem on COM" + _

                Me.ModemPort.ToString()

            Me.UserCommandTextbox.Enabled = True

            Me.SendATCommandButton.Enabled = True

            Me.SendUserCommandButton.Enabled = True

        End If

    End Sub



    ' This subroutine clears the TextBox.

    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click

        Me.StatusTextbox.Clear()

    End Sub





    ' This subroutine sends an AT command to the modem, and records its response.

    '   It depends on the timer to do the reading of the response.

    Private Sub SendATCommandButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendATCommandButton.Click



        ' Always wrap up working with Comm Ports in exception handlers.

        Try

            ' Enable the timer.

            Me.tmrReadCommPort.Enabled = True

            ' Attempt to open the port.

            CommPort.Open(ModemPort, 115200, 8, RS232.DataParity.Parity_None, _

                RS232.DataStopBit.StopBit_1, 4096)



            ' Write an AT Command to the Port.

            CommPort.Write(Encoding.ASCII.GetBytes("AT" & Chr(13)))

            ' Sleep long enough for the modem to respond and the timer to fire.

            System.Threading.Thread.Sleep(200)

            Application.DoEvents()

            CommPort.Close()



        Catch ex As Exception

            ' Warn the user.

            MessageBox.Show("Unable to communicate with Modem")

        Finally

            ' Disable the timer.

            Me.tmrReadCommPort.Enabled = False

        End Try



    End Sub





    ' This subroutine sends a user specified command to the modem, and records its 

    '   response. It depends on the timer to do the reading of the response.

    Private Sub SendUserCommandButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendUserCommandButton.Click



        ' Always wrap up working with Comm Ports in exception handlers.

        Try

            ' Enable the timer.

            Me.tmrReadCommPort.Enabled = True

            ' Attempt to open the port.

            CommPort.Open(ModemPort, 115200, 8, RS232.DataParity.Parity_None, RS232.DataStopBit.StopBit_1, 4096)



            ' Write an user specified Command to the Port.

            CommPort.Write(Encoding.ASCII.GetBytes(Me.UserCommandTextbox.Text & Chr(13)))

            ' Sleep long enough for the modem to respond and the timer to fire.

            System.Threading.Thread.Sleep(200)

            Application.DoEvents()

            CommPort.Close()



        Catch ex As Exception

            ' Warn the user.

            MessageBox.Show("Unable to communicate with Modem")

        Finally

            ' Disable the timer.

            Me.tmrReadCommPort.Enabled = False

        End Try



    End Sub



    ' This subroutine is fired when the timer event is raised. It writes whatever

    '   is in the Comm Port buffer to the output window.

    Private Sub tmrReadCommPort_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrReadCommPort.Tick

        Try

            ' As long as there is information, read one byte at a time and 

            '   output it.

            While (CommPort.Read(1) <> -1)

                ' Write the output to the screen.

                WriteMessage(Chr(CommPort.InputStream(0)), False)

            End While

        Catch exc As Exception

            ' An exception is raised when there is no information to read.

            '   Don't do anything here, just let the exception go.

        End Try



    End Sub





    ' This function checks to see if the port is a modem, by sending 

    '   an AT command to the port. If the port responds, it is assumed to 

    '   be a modem. The function returns a Boolean.

    Private Function IsPortAModem(ByVal port As Integer) As Boolean



        ' Always wrap up working with Comm Ports in exception handlers.

        Try

            ' Attempt to open the port.

            CommPort.Open(port, 115200, 8, RS232.DataParity.Parity_None, _

                RS232.DataStopBit.StopBit_1, 4096)



            ' Write an AT Command to the Port.

            CommPort.Write(Encoding.ASCII.GetBytes("AT" & Chr(13)))

            ' Sleep long enough for the modem to respond.

            System.Threading.Thread.Sleep(200)

            Application.DoEvents()

            ' Try to get info from the Comm Port.

            Try

                ' Try to read a single byte. If you get it, then assume

                '   that the port contains a modem. Clear the buffer before 

                '   leaving.

                CommPort.Read(1)

                CommPort.ClearInputBuffer()

                CommPort.Close()

                Return True

            Catch exc As Exception

                ' Nothing to read from the Comm Port, so set to False

                CommPort.Close()

                Return False

            End Try

        Catch exc As Exception

            ' Port could not be opened or written to.

            Me.PortsList.SetItemChecked(port - 1, False)

            MsgBox("Could not open port.", MsgBoxStyle.OKOnly, Me.Text)

            Return False

        End Try





    End Function



    ' This function attempts to open the passed Comm Port. If it is

    '   available, it returns True, else it returns False. To determine

    '   availability a Try-Catch block is used.

    Private Function IsPortAvailable(ByVal ComPort As Integer) As Boolean

        Try

            CommPort.Open(ComPort, 115200, 8, RS232.DataParity.Parity_None, _

                RS232.DataStopBit.StopBit_1, 4096)

            ' If it makes it to here, then the Comm Port is available.

            CommPort.Close()

            Return True

        Catch

            ' If it gets here, then the attempt to open the Comm Port

            '   was unsuccessful.

            Return False

        End Try

    End Function



    ' This subroutine writes a message to the txtStatus TextBox.

    Private Sub WriteMessage(ByVal message As String)

        Me.StatusTextbox.Text += message + vbCrLf

    End Sub



    ' This subroutine writes a message to the txtStatus TextBox and allows

    '   the line feed to be suppressed.

    Private Sub WriteMessage(ByVal message As String, ByVal linefeed As Boolean)

        Me.StatusTextbox.Text += message

        If linefeed Then

            Me.StatusTextbox.Text += vbCrLf

        End If

    End Sub



    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

        End

    End Sub



End Class

Open in new window

0
 
LVL 3

Expert Comment

by:Ironnica
ID: 33699609
It is possible. Please have a look at the following site which can help you: http://msdn.microsoft.com/en-us/library/bb158662.aspx
0
 

Author Comment

by:Rob4077
ID: 33699713
Thanks Ironnica but I think those code samples are for Windows Mobile. As I understand it Windows Mobile is intended to build applications that run on a cell phone with a Windows based operating system.
What I was hoping to do was read SMS messages from, and send SMS messages via, a cell phone connected to a laptop via Bluetooth using a Visual Basic.Net Studio Express Edition application. The intention is to read SMS messages coming to the phone, try to parse them and if they are in the right format and are related to my SQL Server Express database then I want to update the details in the database and display the details on my laptop. I also want to be able to send SMS messages from the same application.
The code provided above searches all the comm ports on my laptop and identifies the laptop's virtual modem as a modem but, correctly, reports that it cannot open or write to the port. However it does not recognise Comm port 13 (which is the port my Bluetooth connection sets up) as a modem and so cannot open or write to it. I am looking for help to see how I can communicate with my cell phone via this comm port.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Rob4077
ID: 33699999
I have just tried installing a Sierra 885 Air Card into one of the USB ports. According to the Device Manager it says:  Sierra Wireless AT Command Port (UMTS) (Com 6) and Sierra Wireless DM Port (UMTS) (Com 7) Yet when I run the code it still tells me these are unresponsive ports.
Can anyone help me figure out how to communicate with, preferably, the Bluetooth connected cell phone, or at least the Air Card from a Visual Basic 2008 Express Edition?
0
 

Author Comment

by:Rob4077
ID: 33700400
BTW, Ironnica my comment that "As I understand it Windows Mobile is intended to build applications that run on a cell phone with a Windows based operating system." should probably have been constructed as a question rather than a statement. If I am wrong and that's the way to go I would love to hear from you.
0
 

Accepted Solution

by:
Rob4077 earned 0 total points
ID: 33839181
I have found a package that will provide the functionality I need
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now