By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,442 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

a little help in bluetooth

P: n/a
excuse me, im a newbie programmer and i need a code on how to to be able to
send files from a mobile phone to a pc through bluetooth in vb.net

can anyone post a code here on how to detect a bluetooth device and how to
send files to the pc in vb.net?

i would really really appreciate your help!!

Dec 21 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
JDS
On Dec 21, 3:25*pm, "jabslim" <u40064@uwewrote:
excuse me, im a newbie programmer and i need a code on how to to be able to
send files from a mobile phone to a pc through bluetooth in vb.net

can anyone post a code here on how to detect a bluetooth device and how to
send files to the pc in vb.net?

i would really really appreciate your help!!
One way to do it is to assign a com port to the PC Bluetooth
connection and then use System.IO.SerialPort. You will then also need
a program on the PC to receive the file.

HTH
Dec 22 '07 #2

P: n/a
>One way to do it is to assign a com port to the PC Bluetooth
>connection and then use System.IO.SerialPort. You will then also need
a program on the PC to receive the file.

HTH


thanks for the info!! if it's convenient for you, can you please post a
sample on how to really use the codes for it? because i haven't the slightest
idea on how to really control the dongle(bluetooth) using codes in vb.net. i
have searched and read other forums about bluetooth, but i just cant
understand how it is being controlled to receive files.

what kind of program for the pc do you recommend for the dongle?

--
Message posted via http://www.dotnetmonster.com

Dec 22 '07 #3

P: n/a
JDS
On 22 Dec, 16:13, "jabslim via DotNetMonster.com" <u40064@uwewrote:
One way to do it is to assign a com port to the PC Bluetooth
connection and then use System.IO.SerialPort. You will then also need
a program on the PC to receive the file.
HTH

thanks for the info!! if it's convenient for you, can you please post a
sample on how to really use the codes for it? because i haven't the slightest
idea on how to really control the dongle(bluetooth) using codes in vb.net. i
have searched and read other forums about bluetooth, but i just cant
understand how it is being controlled to receive files.

what kind of program for the pc do you recommend for the dongle?

--
Message posted viahttp://www.dotnetmonster.com
Try the following. It is only a test piece of code and does not have
any file IO but you should be able to adapt it easily. It has a simple
form with a combo box to display the available com ports (you will
have to assign a com port to the Bluetooth connection manually
beforehand) and a text box that displays received data (well the first
6 characters of each received line in this case).

For testing you could use Hyperterminal on the PC and the functions on
the Transfer menu ("Capture text..." and "Send text file..."). Again
you will have to assign a com port to the Bluetooth connection
manually beforehand.

Imports System.IO.Ports

Public Class frmMain
#Region "Variables"
Dim WithEvents mserialPort As New SerialPort
Dim mstrRxData As String
#End Region

#Region "Form"
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim strPorts() As String
strPorts = SerialPort.GetPortNames
For Each port As String In strPorts
Me.cbComPort.Items.Add(port)
Next
If Me.cbComPort.Items.Count = 0 Then
MsgBox("No com ports found")
Else
Me.cbComPort.SelectedIndex = 0
End If
Catch ex As Exception
MsgBox("Form load error: " & ex.Message)
End Try
End Sub
#End Region

#Region "Data"
Private Sub DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles
mserialPort.DataReceived
Try
Me.tbRxData.Invoke(New myDelegate(AddressOf ProcessData),
New Object() {})
Catch ex As Exception
MsgBox("DataReceived() error: " & ex.Message)
End Try
End Sub

Public Delegate Sub myDelegate()
Public Sub ProcessData()
Try
Dim rxData As String = ""
Static strBuffer As String

rxData = mserialPort.ReadExisting
strBuffer &= rxData
If strBuffer.EndsWith(vbCrLf) Then
Me.tbRxData.Text = Mid(strBuffer, 1, 6)
strBuffer = ""
End If
Catch ex As Exception
MsgBox("ProcessData() error: " & ex.Message)
End Try
End Sub
#End Region

#Region "Menus"
Private Sub mnuConnect_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuConnect.Click
Try
With mserialPort
If Not .IsOpen Then
.PortName = Me.cbComPort.Text
.Open()
Me.tbRxData.Text = "Connected"
Me.mnuConnect.Text = "Disconnect"
Me.mnuExit.Enabled = False
Else
.Close()
Me.tbRxData.Text = "Disconnected"
Me.mnuConnect.Text = "Connect"
Me.mnuExit.Enabled = True
End If
End With
Catch ex As InvalidOperationException
MsgBox("mnuConnect error: port already open")
Catch ex As ArgumentOutOfRangeException
MsgBox("mnuConnect error: invalid port setting")
Catch ex As ArgumentException
MsgBox("mnuConnect error: invalid port name or file type")
Catch ex As IO.IOException
MsgBox("mnuConnect error: invalid port state or port
setting")
Catch ex As UnauthorizedAccessException
MsgBox("mnuConnect error: access denied to specified
port")
Catch ex As Exception
MsgBox("mnuConnect error: " & ex.Message)
End Try
End Sub

Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuExit.Click
Application.Exit()
End Sub
#End Region
End Class

Dec 23 '07 #4

P: n/a
thanks a lot pal!! ill try to understand and learn how the code works!!

if i have further questions, ill just post it here again!!

once again, i really thank you!! you're really helpful!!

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...b-net/200712/1

Dec 23 '07 #5

P: n/a
On Dec 23, 2:44 pm, JDS <ad...@jeremysage.comwrote:
On 22 Dec, 16:13, "jabslim via DotNetMonster.com" <u40064@uwewrote:
>One way to do it is to assign a com port to the PC Bluetooth
>connection and then use System.IO.SerialPort. You will then also need
>a program on the PC to receive the file.
>HTH
thanks for the info!! if it's convenient for you, can you please post a
sample on how to really use the codes for it? because i haven't the slightest
idea on how to really control the dongle(bluetooth) using codes in vb.net. i
have searched and read other forums about bluetooth, but i just cant
understand how it is being controlled to receive files.
what kind of program for the pc do you recommend for the dongle?
--
Message posted viahttp://www.dotnetmonster.com

Try the following. It is only a test piece of code and does not have
any file IO but you should be able to adapt it easily. It has a simple
form with a combo box to display the available com ports (you will
have to assign a com port to the Bluetooth connection manually
beforehand) and a text box that displays received data (well the first
6 characters of each received line in this case).

For testing you could use Hyperterminal on the PC and the functions on
the Transfer menu ("Capture text..." and "Send text file..."). Again
you will have to assign a com port to the Bluetooth connection
manually beforehand.

Imports System.IO.Ports

Public Class frmMain
#Region "Variables"
Dim WithEvents mserialPort As New SerialPort
Dim mstrRxData As String
#End Region

#Region "Form"
Private Sub frmMain_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
Dim strPorts() As String
strPorts = SerialPort.GetPortNames
For Each port As String In strPorts
Me.cbComPort.Items.Add(port)
Next
If Me.cbComPort.Items.Count = 0 Then
MsgBox("No com ports found")
Else
Me.cbComPort.SelectedIndex = 0
End If
Catch ex As Exception
MsgBox("Form load error: " & ex.Message)
End Try
End Sub
#End Region

#Region "Data"
Private Sub DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles
mserialPort.DataReceived
Try
Me.tbRxData.Invoke(New myDelegate(AddressOf ProcessData),
New Object() {})
Catch ex As Exception
MsgBox("DataReceived() error: " & ex.Message)
End Try
End Sub

Public Delegate Sub myDelegate()
Public Sub ProcessData()
Try
Dim rxData As String = ""
Static strBuffer As String

rxData = mserialPort.ReadExisting
strBuffer &= rxData
If strBuffer.EndsWith(vbCrLf) Then
Me.tbRxData.Text = Mid(strBuffer, 1, 6)
strBuffer = ""
End If
Catch ex As Exception
MsgBox("ProcessData() error: " & ex.Message)
End Try
End Sub
#End Region

#Region "Menus"
Private Sub mnuConnect_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuConnect.Click
Try
With mserialPort
If Not .IsOpen Then
.PortName = Me.cbComPort.Text
.Open()
Me.tbRxData.Text = "Connected"
Me.mnuConnect.Text = "Disconnect"
Me.mnuExit.Enabled = False
Else
.Close()
Me.tbRxData.Text = "Disconnected"
Me.mnuConnect.Text = "Connect"
Me.mnuExit.Enabled = True
End If
End With
Catch ex As InvalidOperationException
MsgBox("mnuConnect error: port already open")
Catch ex As ArgumentOutOfRangeException
MsgBox("mnuConnect error: invalid port setting")
Catch ex As ArgumentException
MsgBox("mnuConnect error: invalid port name or file type")
Catch ex As IO.IOException
MsgBox("mnuConnect error: invalid port state or port
setting")
Catch ex As UnauthorizedAccessException
MsgBox("mnuConnect error: access denied to specified
port")
Catch ex As Exception
MsgBox("mnuConnect error: " & ex.Message)
End Try
End Sub

Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuExit.Click
Application.Exit()
End Sub
#End Region
End Class
Does it work for USB Bluetooth dongles?
Dec 24 '07 #6

P: n/a
JDS
On 24 Dec, 22:16, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Dec 23, 2:44 pm, JDS <ad...@jeremysage.comwrote:


On 22 Dec, 16:13, "jabslim via DotNetMonster.com" <u40064@uwewrote:
One way to do it is to assign a com port to the PC Bluetooth
connection and then use System.IO.SerialPort. You will then also need
a program on the PC to receive the file.
HTH
thanks for the info!! if it's convenient for you, can you please post a
sample on how to really use the codes for it? because i haven't the slightest
idea on how to really control the dongle(bluetooth) using codes in vb.net. i
have searched and read other forums about bluetooth, but i just cant
understand how it is being controlled to receive files.
what kind of program for the pc do you recommend for the dongle?
--
Message posted viahttp://www.dotnetmonster.com
Try the following. It is only a test piece of code and does not have
any file IO but you should be able to adapt it easily. It has a simple
form with a combo box to display the available com ports (you will
have to assign a com port to the Bluetooth connection manually
beforehand) and a text box that displays received data (well the first
6 characters of each received line in this case).
For testing you could use Hyperterminal on the PC and the functions on
the Transfer menu ("Capture text..." and "Send text file..."). Again
you will have to assign a com port to the Bluetooth connection
manually beforehand.
Imports System.IO.Ports
Public Class frmMain
#Region "Variables"
* * Dim WithEvents mserialPort As New SerialPort
* * Dim mstrRxData As String
#End Region
#Region "Form"
* * Private Sub frmMain_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
* * * * Try
* * * * * * Dim strPorts() As String
* * * * * * strPorts = SerialPort.GetPortNames
* * * * * * For Each port As String In strPorts
* * * * * * * * Me.cbComPort.Items.Add(port)
* * * * * * Next
* * * * * * If Me.cbComPort.Items.Count = 0 Then
* * * * * * * * MsgBox("No com ports found")
* * * * * * Else
* * * * * * * * Me.cbComPort.SelectedIndex = 0
* * * * * * End If
* * * * Catch ex As Exception
* * * * * * MsgBox("Form load error: " & ex.Message)
* * * * End Try
* * End Sub
#End Region
#Region "Data"
* * Private Sub DataReceived(ByVal sender As Object, ByVal e As
System.IO.Ports.SerialDataReceivedEventArgs) Handles
mserialPort.DataReceived
* * * * Try
* * * * * * Me.tbRxData.Invoke(New myDelegate(AddressOf ProcessData),
New Object() {})
* * * * Catch ex As Exception
* * * * * * MsgBox("DataReceived() error: " & ex.Message)
* * * * End Try
* * End Sub
* * Public Delegate Sub myDelegate()
* * Public Sub ProcessData()
* * * * Try
* * * * * * Dim rxData As String = ""
* * * * * * Static strBuffer As String
* * * * * * rxData = mserialPort.ReadExisting
* * * * * * strBuffer &= rxData
* * * * * * If strBuffer.EndsWith(vbCrLf) Then
* * * * * * * * Me.tbRxData.Text = Mid(strBuffer, 1, 6)
* * * * * * * * strBuffer = ""
* * * * * * End If
* * * * Catch ex As Exception
* * * * * * MsgBox("ProcessData() error: " & ex.Message)
* * * * End Try
* * End Sub
#End Region
#Region "Menus"
* * Private Sub mnuConnect_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuConnect.Click
* * * * Try
* * * * * * With mserialPort
* * * * * * * * If Not .IsOpen Then
* * * * * * * * * * .PortName = Me.cbComPort.Text
* * * * * * * * * * .Open()
* * * * * * * * * * Me.tbRxData.Text = "Connected"
* * * * * * * * * * Me.mnuConnect.Text = "Disconnect"
* * * * * * * * * * Me.mnuExit.Enabled = False
* * * * * * * * Else
* * * * * * * * * * .Close()
* * * * * * * * * * Me.tbRxData.Text = "Disconnected"
* * * * * * * * * * Me.mnuConnect.Text = "Connect"
* * * * * * * * * * Me.mnuExit.Enabled = True
* * * * * * * * End If
* * * * * * End With
* * * * Catch ex As InvalidOperationException
* * * * * * MsgBox("mnuConnect error: port already open")
* * * * Catch ex As ArgumentOutOfRangeException
* * * * * * MsgBox("mnuConnect error: invalid port setting")
* * * * Catch ex As ArgumentException
* * * * * * MsgBox("mnuConnect error: invalid port name or file type")
* * * * Catch ex As IO.IOException
* * * * * * MsgBox("mnuConnect error: invalid port state or port
setting")
* * * * Catch ex As UnauthorizedAccessException
* * * * * * MsgBox("mnuConnect error: access denied to specified
port")
* * * * Catch ex As Exception
* * * * * * MsgBox("mnuConnect error: " & ex.Message)
* * * * End Try
* * End Sub
* * Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mnuExit.Click
* * * * Application.Exit()
* * End Sub
#End Region
End Class

Does it work for USB Bluetooth dongles?- Hide quoted text -

- Show quoted text -
I have used it with a USB Bluetooth dongle on the PC communicating
with a Windows Mobile device. It is not that sophisticated as it
requires the user to assign a com port to the Bluetooth interface on
both the PC and the mobile device - but it works! I am sure there will
be ways of creating a more user-friendly interface by handling the
Bluetooth directly but it is bound to require more programming.

One note on assigning ports. The terminology uses "outgoing" and
"incoming" which is a little confusing as it does not relate to the
direction of the data. It refers to which device initiates the
connection; i.e. if the PC is listening for the connection and the
mobile device initiates, then the PC port will be "incoming" and the
mobile device "outgoing" even if all the data is transmitted only from
the PC to the mobile device.

HTH
Dec 26 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.