Author Topic: Unable connect. Error: 45 with Bluetooth Client Demo  (Read 38244 times)

andy.stephenson

  • Guest
Unable connect. Error: 45 with Bluetooth Client Demo
« on: January 31, 2011, 08:43:15 PM »
Hi,

Using the client demo code (Delphi), I can enum my radio, and discover my device, but when I select Serial Port Profile, then connect, I get an error 45. The API doc does not give any detail on what this could be. Any ideas?

My device does not use a PIN, and I can connect from a mobile app written in VB - I don't have the source.

Thanks,

Andy

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #1 on: January 31, 2011, 09:15:32 PM »
Hi,

As described in the API Reference Error 45 means WCL_E_UNABLE_CONNECT. There are lot of reasons why that may happen. Unfortunately I have no any idea because I do not know what profile you device uses, it needs pairing or not and so long. Unfortunately I do not know what your mobile app does as I do not have its sources too (and our telepator has been damaged a few days ago).

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #2 on: February 01, 2011, 06:59:40 PM »
Mike,
>As described in the API Reference Error 45 means WCL_E_UNABLE_CONNECT. There are lot of reasons why that may happen. Unfortunately I have no any idea because I do not >know what profile you device uses, it needs pairing or not and so long. Unfortunately I do not know what your mobile app does as I do not have its sources too (and our telepator >has been damaged a few days ago).

I stated that I use the Serial Port Profile.

I don't use pairing.

What does the VCL require to allow the connection?

I have discovered the device no problem, should I be able to just send data using the hardware address? Is another stage required to allow the connection?

I'm using the Ezurio Bluetooth Module, using SPP and I can send from the module to the PC using the VCL with no problems - now that I'm using the old Widcomm dll.

...Andy

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #3 on: February 01, 2011, 08:32:51 PM »
I can guess that your device requres pairing for SPP connection (as most devices do).

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #4 on: February 02, 2011, 07:16:12 PM »
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

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #5 on: February 02, 2011, 07:33:42 PM »
Tested the same demo app with the Microsoft stack and it connects. The Widcomm stack gives error 45.

...Andy

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #6 on: February 02, 2011, 07:56:59 PM »
We never used in the hand as we have own solution.

No, we have no idea why it may apper but I told my team to test and I will back to you soon.

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #7 on: February 02, 2011, 09:42:14 PM »
OK. thank you.

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #8 on: February 15, 2011, 12:39:07 PM »
We never used in the hand as we have own solution.

No, we have no idea why it may apper but I told my team to test and I will back to you soon.

Any news on this?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #9 on: February 15, 2011, 12:59:22 PM »
Unfortunately no yet as we still couldn't reproduce the issue with hardware we have here.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #10 on: February 17, 2011, 04:55:47 PM »
Hi,

it looks like we finaly reproduced the issue. I will back to you soon with fixes/workaround.

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #11 on: February 23, 2011, 09:57:51 PM »
Thanks. I look forward to your findings.

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #12 on: March 16, 2011, 04:04:01 PM »
Anything yet? I'm keen to progress this so as to keep my project alive.

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3675
  • Karma: 1000
    • Wireless Communication Libraries
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #13 on: March 16, 2011, 04:19:21 PM »
The issue appears on Win XP 64 bit with WidComm stack only. The issue is a WidComm bug and we have no solution for that yet. Unfortunately we couldn't reproduce the issue on other platforms/drivers.

andy.stephenson

  • Guest
Re: Unable connect. Error: 45 with Bluetooth Client Demo
« Reply #14 on: March 18, 2011, 01:19:02 PM »
Sorry, but my non working dev platform is Win XP 32 bit with WidComm stack. Do you know if it is related to specific versions of stack? This is probably sufficient an issue to become a deal breaker to buying this library.

Thank you for your help to date in evaluating the library.

I will work something else out.

 

Sitemap 1 2 3 4 5 6 7