Solved

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

Posted on 2010-09-12
6
1,871 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Defend Against the WCry Ransomware Attack

On May 12, 2017, an extremely virulent ransomware variant named WCry 2.0 began to infect organizations. Within several hours, over 75,000 victims were reported in 90+ countries. Learn more from our research team about this threat & how to protect your organization!

 

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Tired of waiting for your show or movie to load?  Are buffering issues a constant problem with your internet connection?  Check this article out to see if these simple adjustments are the solution for you.
DECT technology has become a popular standard for wireless voice communication. DECT devices are not likely to be affected by other electronic devices and signals because they operate in a separate frequency-band.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
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…

734 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