Author Topic: wclClient Disconnects all the time  (Read 5567 times)

Offline DILLIGAF

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
wclClient Disconnects all the time
« on: May 24, 2008, 04:54:35 PM »
Hi...
I'm having some problem with wclClient...

It keeps disconnecting from the phone .. I would like it to stay connected as long as the phone is nearby
I'm new on this, both Visual Basic and wcl .NET

My code looks like this

Code: [Select]
    Private Sub StartMonitorClient()

        If clbCallerID.CheckedIndices.Count Then
            WclClient.ClientTransport = WCLX.wclClientTransportx.ctBluetooth
            WclClient.BluetoothParams.Radio = Radio
            WclClient.BluetoothParams.Address = clbCallerID.SelectedItem.ToString

            WclClient.Open()

            TClient.Enabled = True
        Else
            MsgBox("Choose a device to connect to")
        End If

    Private Sub TClient_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TClient.Tick

        If WclClient.Connected Then
            TClient.Enabled = False
            WriteToLog("Connected wclClient")

            Dim Coder As Encoding = Encoding.ASCII
            Dim Buf() As Byte = Coder.GetBytes("AT+CLIP=1" + vbCrLf)
            WclClient.Write(Buf)
            Buf = Nothing
            Coder = Nothing
            WriteToLog("Sent AT+CLIP=1 to wclClient")

            ClientConnect = True
        End If

    Private Sub wclClient_Disconnect(ByVal sender As Object, ByVal e As System.EventArgs) Handles WclClient.Disconnect

        laClientSignal.Text = "Signal Level: Not Connected"
        If ClientConnect = False Then WriteToLog("Connection to wclClient terminated by user")
        If ClientConnect = True Then
            TClientReConnect.Enabled = True

            WriteToLog("Connection lost to wclClient")
        End If

    Private Sub TClientReConnect_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TClientReConnect.Tick

        If Not WclClient.Connected And ClientConnect = True Then
            Try
                WclClient.Open()
            Catch ex As Exception
            End Try
        End If

        If WclClient.Connected And ClientConnect = True Then

            TClientReConnect.Enabled = False

            WriteToLog("Reconnected to wclClient")

            Dim Coder As Encoding = Encoding.ASCII
            Dim Buf() As Byte = Coder.GetBytes("AT+CLIP=1" + vbCrLf)
            WclClient.Write(Buf)
            Buf = Nothing
            Coder = Nothing
            WriteToLog("Sent AT+CLIP=1 to wclClient after Reconnecting")

            ClientConnect = True
        End If

    End Sub

I made a log of the actions ...

1 Connected wclClient 2008-5-24 09:12:35
2 Sent AT+CLIP=1 to wclClient 2008-5-24 09:12:35
3 Connection lost to wclClient 2008-5-24 09:46:36
4 Reconnected to wclClient 2008-5-24 09:46:38
5 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 09:46:39
6 Connection lost to wclClient 2008-5-24 10:22:39
7 Reconnected to wclClient 2008-5-24 10:22:44
8 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 10:22:44
9 Connection lost to wclClient 2008-5-24 10:43:43
10 Reconnected to wclClient 2008-5-24 10:43:49
11 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 10:43:50
12 Connection lost to wclClient 2008-5-24 11:12:54

2008-05-24 11:12:54
An unhandled win32 exception accurred in BTstackServer.exe[3292]
Unhandled exception at 0x0046baa1 in BTStackServer.exe: 0xC0000005: Access violation reading location 0x20705539.


13 Connected wclClient 2008-5-24 11:39:28
14 Sent AT+CLIP=1 to wclClient 2008-5-24 11:39:28
15 Connection lost to wclClient 2008-5-24 12:00:28
16 Reconnected to wclClient 2008-5-24 12:00:33
17 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 12:00:33
18 Connection lost to wclClient 2008-5-24 12:21:32
19 Reconnected to wclClient 2008-5-24 12:21:38
20 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 12:21:38
21 Connection lost to wclClient 2008-5-24 12:42:37
22 Reconnected to wclClient 2008-5-24 12:42:42
23 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 12:42:42
24 Connection lost to wclClient 2008-5-24 13:03:41
25 Reconnected to wclClient 2008-5-24 13:03:47
26 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 13:03:47
27 Connection lost to wclClient 2008-5-24 13:24:48
28 Reconnected to wclClient 2008-5-24 13:24:53
29 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 13:24:53
30 Connection lost to wclClient 2008-5-24 13:45:52
31 Reconnected to wclClient 2008-5-24 13:45:58
32 Sent AT+CLIP=1 to wclClient after Reconnecting 2008-5-24 13:45:58
33 Connection lost to wclClient 2008-5-24 14:07:59

And so on ....

It's strange because it's always about 20min apart...
And the thing at 11:12:54, maybe something else, but it happened when i did the log...

I hope we can solve this ...

And one other thing....
How do I use the ClassOfDevice code???
Like I said I'm a newbee  ???   :P

Thanx!  :)

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: wclClient Disconnects all the time
« Reply #1 on: May 24, 2008, 05:13:48 PM »
It is strange way to detect when cient connected by using timer. Why do not use OnConnect event?

The connection temintation may be initiated by phone as well as by stack if no data transfered.

Offline DILLIGAF

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: wclClient Disconnects all the time
« Reply #2 on: May 24, 2008, 05:27:45 PM »
HaHaHa   Of course!  :-[
Well I said I was a newbee, sometimes I don't see the tree because of the forest  :D

So i guess the wclClient not suppose to disconnect if nothing happens ...?! hmmm?
Ok, I will try with another phone later, when i find one...

about the code... Is it a good idea to use a timer when trying to reconnect ...?

What about the ClassOfDevice code??
How do I use it in Visual Basic so that i can see if the device is a phone...?

sorry about all the dumb questions, but i really want this to work ..

And thanx for the quick answer :)

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: wclClient Disconnects all the time
« Reply #3 on: May 24, 2008, 06:00:31 PM »
Timer for reconnect is not bad idea.

Do you use VB.NET? if so there is wclCODs class with all constants. To decode COD to somethin usefull:
http://forum.btframework.com/index.php?topic=171.0

Offline DILLIGAF

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: wclClient Disconnects all the time
« Reply #4 on: May 25, 2008, 01:23:30 AM »
Yes, i use VB .NET ...
I'm sorry to bother you with this question but I've been looking in the VBDemo and trying to figure it out on the web but I can't find anything..?

I use this code...
Code: [Select]
    Private Sub DevicesInRange(ByVal e As wclnet.BluetoothDiscoveryCompleteEventArgs)

        Dim Item As New ListViewItem

        lvInRange.Items.Clear()

        lvInRange.BeginUpdate()

        For i As Integer = 0 To e.Devices.Count - 1
            Device = e.Devices(i)
            Item = lvInRange.Items.Add(e.Devices.Item(i).Name(Radio))
            Item.SubItems.Add(e.Devices.Item(i).Address)
            Item.SubItems.Add(Str(e.Devices.Item(i).ClassOfDevice(Radio)))
        Next i

        lvInRange.EndUpdate()

    End Sub

And I get ClassOfDevice = 5243404

How do I use it with wclCODs class?

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: wclClient Disconnects all the time
« Reply #5 on: May 26, 2008, 02:25:39 PM »
Code: [Select]
function GetDeviceType(COD: Cardinal): WideString;
begin
  case (COD and COD_MAJOR_MASK) shr COD_MAJOR_BIT_OFFSET of
    COD_MAJOR_MISCELLANEOUS: Result := 'Unknown Device';

    COD_MAJOR_COMPUTER: case (COD and COD_MINOR_MASK) shr COD_MINOR_BIT_OFFSET of
                          COD_COMPUTER_MINOR_DESKTOP: Result := 'Desktop computer';
                          COD_COMPUTER_MINOR_SERVER: Result := 'Service computer';
                          COD_COMPUTER_MINOR_LAPTOP: Result := 'Laptop compiter';
                          COD_COMPUTER_MINOR_HANDHELD: Result := 'Handheld computer';
                          COD_COMPUTER_MINOR_PALM: Result := 'Palm computer';

                        else
                          Result := 'Computer';
                        end;

    COD_MAJOR_PHONE: case (COD and COD_MINOR_MASK) shr COD_MINOR_BIT_OFFSET of
                       COD_PHONE_MINOR_CELLULAR: Result := 'Cellular phone';
                       COD_PHONE_MINOR_CORDLESS: Result := 'Cordless phone';
                       COD_PHONE_MINOR_SMART: Result := 'Smartphone';
                       COD_PHONE_MINOR_WIRED_MODEM: Result := 'Modem';
                       COD_PHONE_MINOR_COMMON_ISDN_ACCESS: Result := 'ISDN Modem';

                     else
                       Result := 'Phone device';
                     end;

    COD_MAJOR_LAN_ACCESS: Result := 'LAN device';

    COD_MAJOR_AUDIO: case (COD and COD_MINOR_MASK) shr COD_MINOR_BIT_OFFSET of
                       COD_AUDIO_MINOR_HEADSET: Result := 'HeadSet';
                       COD_AUDIO_MINOR_HANDS_FREE: Result := 'HandsFree';
                       COD_AUDIO_MINOR_HEADSET_HANDS_FREE: Result := 'HeadSet + HandsFree';
                       COD_AUDIO_MINOR_MICROPHONE: Result := 'Microphone';
                       COD_AUDIO_MINOR_LOUDSPEAKER: Result := 'Loudspeaker';
                       COD_AUDIO_MINOR_HEADPHONES: Result := 'Headphones';
                       COD_AUDIO_MINOR_PORTABLE_AUDIO: Result := 'Portable Audio';
                       COD_AUDIO_MINOR_CAR_AUDIO: Result := 'Car audio';
                       COD_AUDIO_MINOR_SET_TOP_BOX: Result := 'Set tob box';
                       COD_AUDIO_MINOR_HIFI_AUDIO: Result := 'HiFi Audio';
                       COD_AUDIO_MINOR_VCR: Result := 'VCR Audio';
                       COD_AUDIO_MINOR_VIDEO_CAMERA: Result := 'Video Camera Audio';
                       COD_AUDIO_MINOR_CAMCORDER: Result := 'Camcoder Audio';
                       COD_AUDIO_MINOR_VIDEO_MONITOR: Result := 'Video Monitor Audio';
                       COD_AUDIO_MINOR_VIDEO_DISPLAY_LOUDSPEAKER: Result := 'Video Display Laudspeaker';
                       COD_AUDIO_MINOR_VIDEO_DISPLAY_CONFERENCING: Result := 'Video Display Conferencing';
                       COD_AUDIO_MINOR_GAMING_TOY: Result := 'Gaming Toy Audio';

                     else
                       Result := 'Audio device';
                     end;

    COD_MAJOR_PERIPHERAL: case (COD and COD_MINOR_MASK) shr COD_MINOR_BIT_OFFSET of
                            COD_PERIPHERAL_MINOR_KEYBOARD_MASK: Result := 'Keyboard';
                            COD_PERIPHERAL_MINOR_POINTER_MASK: Result := 'Pointer';
                            COD_PERIPHERAL_MINOR_JOYSTICK: Result := 'Joystick';
                            COD_PERIPHERAL_MINOR_GAMEPAD: Result := 'Gemapad';
                            COD_PERIPHERAL_MINOR_REMOTE_CONTROL: Result := 'Remote Control';
                            COD_PERIPHERAL_MINOR_SENSING: Result := 'Sensing';
                            COD_PERIPHERAL_MINOR_DIGITIZER_TABLET: Result := 'Digitizer Tablet';
                            COD_PERIPHERAL_MINOR_CARD_READER: Result := 'Card Reader';
                           
                          else
                            Result := 'Peripheral Device';
                          end;

    COD_MAJOR_IMAGING: case (COD and COD_MINOR_MASK) shr COD_MINOR_BIT_OFFSET of
                         COD_IMAGING_MINOR_DISPLAY_MASK: Result := 'Video Dispaly';
                         COD_IMAGING_MINOR_CAMERA_MASK: Result := 'Video Camera';
                         COD_IMAGING_MINOR_SCANNER_MASK: Result := 'Scanner';
                         COD_IMAGING_MINOR_PRINTER_MASK: Result := 'Printer';

                       else
                         Result := 'Video device';
                       end;

    COD_MAJOR_WEARABLE: Result := 'Wearable device';

    COD_MAJOR_TOY: case (COD and COD_MINOR_MASK) shr COD_MINOR_BIT_OFFSET of
                     COD_TOY_MINOR_ROBOT: Result := 'Robot Toy';
                     COD_TOY_MINOR_VEHICLE: Result := 'Vehicle Toy';
                     COD_TOY_MINOR_DOLLACTIONFIGURE: Result := 'Doll Action Figure';
                     COD_TOY_MINOR_CONTROLLER: Result := 'Toy Controller';

                   else
                     Result := 'Toy device';
                   end;

    COD_MAJOR_UNCLASSIFIED: Result := 'Unknown Device';
  end;
end;

Offline DILLIGAF

  • Newbie
  • *
  • Posts: 4
  • Karma: 0
Re: wclClient Disconnects all the time
« Reply #6 on: May 26, 2008, 10:07:27 PM »
thanx!  :)

hmm.. it's written in C+ right?
I will try to rewrite it to VB ... like i said I'm a newbie, and i haven't written anything in c+, yet  :P

I hope i will figure it out...  :-\

Offline Mike Petrichenko

  • Bluetooth Framework Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 3055
  • Karma: 1000
    • Soft Service Company
Re: wclClient Disconnects all the time
« Reply #7 on: May 26, 2008, 10:13:26 PM »
It is Delphi (Pascal)
Somewere on this forum I posted the same for VB. it is easy.

 

Sitemap 1 2 3 4 5 6 7 8 9