Frameworks > Bluetooth Framework
wclClient Disconnects all the time
DILLIGAF:
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: --- 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
--- End code ---
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! :)
Mike Petrichenko:
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.
DILLIGAF:
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 :)
Mike Petrichenko:
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
DILLIGAF:
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: --- 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
--- End code ---
And I get ClassOfDevice = 5243404
How do I use it with wclCODs class?
Navigation
[0] Message Index
[#] Next page
Go to full version