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?
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