Sorry, no pairing required. I've checked the at setting for the module.
I also manages to get my hands on the VB code. Code copied below. As you will see, it connects then sends the data. It's using the In The Hand .Net lib. Have you used this before?
The code is only for one module, and DoUpload() is the sub doing the business.
Code:
Imports InTheHand.Net
Imports InTheHand.Net.Sockets
Imports InTheHand.Net.Bluetooth
Imports Microsoft.Win32
Public Class UploadPanel
#Region "Variables"
Private mStatus As StatusEnum
Private mstrErrorText As String
Private mTemplate As clsTemplate
' Storage for original BT radio mode
Private mOrigRadioMode As RadioMode
Private mstrOrigName As String
#End Region ' Variables
#Region "Constants"
Private Const cintMaxBufferSize As Integer = 1024
Private Const cstrFriendlyName As String = "somename"
Private Const cstrPassword As String = "somepass"
Private Const cintMaxDataBlockSize As Integer = 86
Private Const cintBTRxTimeout As Integer = 5 ' Seconds
Private Const cdblBTConnectionTime As Double = 1.5 ' Seconds
Private Const cdblBTRadioOnTime As Double = 6.0 ' Seconds
' ASCII character codes
Private Const cintACK As Integer = 6 ' Acknowledge
Private Const cintETB As Integer = 23 ' End of Transmission Block
#End Region ' Constants
#Region "Events"
Public Event UploadFinished(ByVal NewStatus As StatusEnum)
Public Event EnterKeyPress()
#End Region ' Events
#Region "Enums"
Public Enum StatusEnum
Searching
Uploading
Complete
UploadError
SearchError
End Enum
#End Region ' Enums
#Region "Properties"
Public ReadOnly Property Status() As StatusEnum
Get
Return Me.mStatus
End Get
End Property
Public Property Template() As clsTemplate
Get
Return Me.mTemplate
End Get
Set(ByVal value As clsTemplate)
Me.mTemplate = value
End Set
End Property
#End Region ' Properties
#Region "Methods"
#Region "Private"
Private Sub UploadPanel_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then
'Enter
RaiseEvent EnterKeyPress()
End If
End Sub
Private Sub UploadPanel_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
' Centre controls vertically
Me.lblStatus.Top = CType((Me.Height / 2) - (Me.lblStatus.Height / 2), Integer)
Me.picSearching.Top = Me.lblStatus.Top
' Move picturebox controls
Me.picComplete.Location = Me.picSearching.Location
Me.picError.Location = Me.picSearching.Location
Me.picUploading.Location = Me.picSearching.Location
End Sub ' UploadPanel_Resize
Private Sub SetStatus(ByVal NewStatus As StatusEnum)
Try
Me.mStatus = NewStatus
' Initialise all picture box controls
For Each ctl As Control In Me.pnlMain.Controls
If TypeOf (ctl) Is PictureBox Then
ctl.Visible = False
End If
Next
Select Case Me.mStatus
Case StatusEnum.Searching
Me.picSearching.Visible = True
Me.lblStatus.Text = gResMan.GetString("Searching_for_eGO_unit")
Case StatusEnum.Uploading
Me.picUploading.Visible = True
Me.lblStatus.Text = gResMan.GetString("Uploading_to_eGO_unit")
Case StatusEnum.Complete
Me.picComplete.Visible = True
Me.lblStatus.Text = gResMan.GetString("Upload_complete")
RaiseEvent UploadFinished(NewStatus)
Case StatusEnum.UploadError, StatusEnum.SearchError
Me.picError.Visible = True
Me.lblStatus.Text = Me.mstrErrorText
RaiseEvent UploadFinished(NewStatus)
End Select
Me.Parent.Refresh()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub ' SetStatus
Private Sub DoUpload(ByVal myBluetoothDeviceInfo As BluetoothDeviceInfo)
' Create new Bluetooth Client
Dim myClient As New BluetoothClient
Try
Try
' Connect to Bluetooth Client SerialPort
myClient.Connect(New BluetoothEndPoint(myBluetoothDeviceInfo.DeviceAddress, Bluetooth.BluetoothService.SerialPort))
Catch ex As Exception
Me.mstrErrorText = gResMan.GetString("Cannot_connect_to_eGO_unit")
SetStatus(StatusEnum.UploadError)
Exit Sub
End Try
' Pause to allow eGO BlueTooth connection to open
Dim dtWait As Date = Now.AddSeconds(cdblBTConnectionTime)
Do
Loop Until Now > dtWait
' Create stream object
Dim myStream As System.Net.Sockets.NetworkStream = Nothing
Try
myStream = myClient.GetStream()
Catch ex As Exception
Me.mstrErrorText = gResMan.GetString("Cannot_connect_to_eGO_unit")
SetStatus(StatusEnum.UploadError)
Exit Sub
End Try
' Retrieve Write Data from template & split into data blocks if required
Dim strDataToWrite As String = Me.mTemplate.SendString
Dim str1stDataBlock As String = String.Empty
Dim str2ndDataBlock As String = String.Empty
If strDataToWrite.Length > cintMaxDataBlockSize Then
str1stDataBlock = cstrPassword & strDataToWrite.Substring(0, cintMaxDataBlockSize) & Chr(cintETB)
str2ndDataBlock = strDataToWrite.Substring(cintMaxDataBlockSize, strDataToWrite.Length - cintMaxDataBlockSize) & Chr(cintETB)
Else
str1stDataBlock = cstrPassword & strDataToWrite & Chr(cintETB)
End If
' Write 1st data block via Bluetooth connection & wait for acknowledge
If Not WriteToBluetooth(myStream, str1stDataBlock, cintACK) Then
' No acknowledge received from eGO -> set error status
Me.mstrErrorText = String.Format(gResMan.GetString("No_Ack({0})_from_eGO_unit"), 1)
SetStatus(StatusEnum.UploadError)
Exit Try
End If
' If required -> write 2nd data block via Bluetooth connection & wait for acknowledge
If str2ndDataBlock <> String.Empty Then
If Not WriteToBluetooth(myStream, str2ndDataBlock, cintETB) Then
Me.mstrErrorText = String.Format(gResMan.GetString("No_Ack({0})_from_eGO_unit"), 2)
SetStatus(StatusEnum.UploadError)
Exit Try
End If
End If
' Here if Upload completed -> set status
SetStatus(StatusEnum.Complete)
Catch ex As Exception
MessageBox.Show(ex.ToString)
Finally
' Close Bluetooth client connection
If myClient.Connected Then
myClient.Close()
End If
End Try
End Sub ' DoUpload
Private Function WriteToBluetooth(ByVal myStream As System.Net.Sockets.NetworkStream, _
ByVal DataToWrite As String, _
ByVal AckByte As Byte) As Boolean
Try
' Load data string into write buffer
Dim myWriteBuffer As Byte() = System.Text.Encoding.ASCII.GetBytes(DataToWrite)
' Write to eGO via BlueTooth
myStream.Write(myWriteBuffer, 0, myWriteBuffer.Length)
' Wait for EOF or Timeout
Dim dtTimeout As Date = Now.AddSeconds(cintBTRxTimeout)
Dim blnAckRx As Boolean = False
If myStream.CanRead Then
Dim intBytesRead As Integer
Dim Buffer(cintMaxBufferSize) As Byte
' Wait for incoming data
Do
intBytesRead = 0
intBytesRead = myStream.Read(Buffer, 0, cintMaxBufferSize)
If Buffer(0) = AckByte Then
blnAckRx = True
End If
Loop Until blnAckRx Or (Now > dtTimeout)
End If
' Return true only if ACK byte received
If blnAckRx Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function ' WriteToBluetooth
Public Function StartBluetooth() As Boolean
Dim blnReturn As Boolean = False
Try
If BluetoothRadio.IsSupported Then
' Store current BT status & turn BT ON
mOrigRadioMode = BluetoothRadio.PrimaryRadio.Mode
' If BT not Discoverable then
' -> switch ON & pause
' EndIf
If mOrigRadioMode <> RadioMode.Discoverable Then
BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable
' Wait for eGO BlueTooth radio to initialise
Dim dtWait As Date = Now.AddSeconds(cdblBTRadioOnTime)
Do
Loop Until Now > dtWait
End If
' Store device name & set device name if required
mstrOrigName = GetName()
If mstrOrigName <> cstrFriendlyName Then
SetName(cstrFriendlyName)
End If
' Set result = success
blnReturn = True
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Return blnReturn
End Function ' StartBluetooth
Public Function StopBluetooth() As Boolean
Dim blnReturn As Boolean = False
Try
' Restore original BT status
If mOrigRadioMode <> RadioMode.Discoverable Then
BluetoothRadio.PrimaryRadio.Mode = mOrigRadioMode
End If
' Restore device name if required
If mstrOrigName <> cstrFriendlyName Then
SetName(mstrOrigName)
End If
blnReturn = True
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Return blnReturn
End Function ' StopBluetooth
#End Region ' Private
#Region "Public"
Public Sub Initialise()
' Move picturebox controls
Me.picComplete.Location = Me.picSearching.Location
Me.picError.Location = Me.picSearching.Location
Me.picUploading.Location = Me.picSearching.Location
' Set status
SetStatus(StatusEnum.Searching)
' Set Error Text
Me.mstrErrorText = gResMan.GetString("None")
End Sub ' Initialise
Public Sub StartUpload(ByVal TemplateToUpload As clsTemplate)
' Start Bluetooth
If Not StartBluetooth() Then
Me.mstrErrorText = gResMan.GetString("Bluetooth_error")
SetStatus(StatusEnum.SearchError)
Exit Sub
End If
' Set status
SetStatus(StatusEnum.Searching)
' Set Template
Me.mTemplate = TemplateToUpload
' Start Upload
Dim btclient As New BluetoothClient
Dim btdeviceinfo() As BluetoothDeviceInfo
' Attempt to discover BT devices
btdeviceinfo = btclient.DiscoverDevices(1, False, False, True)
' Determine if eGO unit found
Dim blnEgoFound As Boolean = False
For Each myBluetoothDeviceInfo As BluetoothDeviceInfo In btdeviceinfo
If myBluetoothDeviceInfo.DeviceName = cstrFriendlyName Then
' Set "found" status
blnEgoFound = True
' Set status
SetStatus(StatusEnum.Uploading)
' Do Upload
DoUpload(myBluetoothDeviceInfo)
Exit For
End If
Next
' If eGO not found then set error status
If Not blnEgoFound Then
Me.mstrErrorText = gResMan.GetString("eGO_unit_not_found")
SetStatus(StatusEnum.SearchError)
End If
' Stop Bluetooth
StopBluetooth()
End Sub ' StartUpload
#End Region ' Public
#Region "Shared"
Shared Function GetName() As String
Dim strReturn As String = "Unknown"
Try
Dim strSubKey As String = "Ident"
Dim myRegKey As RegistryKey = Registry.LocalMachine.OpenSubKey(strSubKey)
If Not (myRegKey Is Nothing) Then
strReturn = myRegKey.GetValue("Name", "Unknown").ToString()
End If
myRegKey.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Return strReturn
End Function
Shared Sub SetName(ByVal strNewName As String)
Try
Dim strSubKey As String = "Ident"
Dim myRegKey As RegistryKey = Registry.LocalMachine.OpenSubKey(strSubKey, True)
If Not (myRegKey Is Nothing) Then
myRegKey.SetValue("Name", strNewName)
End If
myRegKey.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
#End Region ' Shared
#End Region ' Methods
End Class