ds303
Posts: 8
Joined: Tue Nov 29, 2005 1:40 pm
Location: Germany

Connect without searching

Tue Dec 06, 2005 11:29 am

Hi at all.
I like to connect to an device without discovering first, but on my PPC I get the exeption: "Connection Failed". I think I did something wrong, but I don´t know what...
The strAddress is in the form (xx:xx:xx:xx:xx:xx)yy

Code: Select all

public void Connect(string strAddress)  
{
  Address address = new Address(strAddress);
  manager = Manager.GetManager();
  try
  {
    // Get first network (BlueTools 1.0 only supports one network == one       dongle)
    network = manager.Networks[0];
    //  Connect to device using its address
    remoteDevice = network.ConnectDevice(address, "My device");
    //  Connect to service using its channel number
    remoteService = remoteDevice.ConnectService(address.ServiceChannelNumber, "My service");
    //  Now we have a (remote) service object that you can open a  stream to...
    stream = remoteService.Stream;
  }
  catch (Exception exc)
  {
    MessageBox.Show(exc.Message);
    remoteService = null;
  }
}
I hope anybody can help me.
Thanks in advance!

Daniel

PS: I´ve installed the BlueTools Beta 9.

User avatar
johan
GpsGate
Posts: 15342
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Connect without searching

Tue Dec 06, 2005 11:39 am

The address format is (xx:xx:xx:xx:xx:xx):yy not (xx:xx:xx:xx:xx:xx)yy

You can verify how the Address constructor parsed the address by reading out address.ToString(), or checking address.ServiceChannelNumber.

Another reason for the failed connection can be that you need to bond to the remote device first.

(Your code for connecting to a device/service using its address is correct)

Regards,
Johan

Franson Support

ds303
Posts: 8
Joined: Tue Nov 29, 2005 1:40 pm
Location: Germany

RE: Connect without searching

Tue Dec 06, 2005 12:34 pm

Thank you for the fast response!

The address format seems to be right (00:07:80:00:52:90):01

I´ve added after the line:
remoteService = remoteDevice.ConnectService(address.ServiceChannelNumber, "My service");
the line:
remoteDevice.Bond(PINCODE);

It seems not to be the reason of the connection failure.

When I debugg the solution, the local variables remoteDevice and remoteService gets values, but the local variable Stream doesn´t get a value, it´s null.

User avatar
johan
GpsGate
Posts: 15342
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Connect without searching

Tue Dec 06, 2005 12:47 pm

Can you connect using the FindAndConnect sample?

In that case check the device address + service channel number you get after the discovery using RemoteService.Address.ToString()

Regards,
Johan

Franson Support

User avatar
johan
GpsGate
Posts: 15342
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Connect without searching

Tue Dec 06, 2005 1:01 pm

Did the bonding work? (That is if the remote device does support bonding.) If that is the case the service channel number might be wrong.

RemoteDevice.ConnectService() does not check if the service exists. This check is done when you try to get the stream object.

Regards,
Johan

Franson Support

ds303
Posts: 8
Joined: Tue Nov 29, 2005 1:40 pm
Location: Germany

RE: Connect without searching

Tue Dec 06, 2005 1:45 pm

Hi.

The remote device ("blue giga" Bluetooth module) does support bonding.
In the past, when I run the Find&Connect demo-application, a window comes up, to ask me for the PINCode. If I type there the right code, I could find my device in in the BluetoothManager (a Widcom DeviceDriverApplication I think) in Bonded-Devices again.

When I run the demo-application and ad
MessageBox.Show(RemoteService.Address.ToString()); I get the same address and the same service channel like in my application, but I get several error messages when it should set "currentStream = currentService.Stream", like:
The connection failed due to an unknown error
or
connection already open

I don´t know, what I´ve done wrong, in the past it works, without a problem, I´ve only updated from Beta7 to Beta9.



BTW: your support is great!!

ds303
Posts: 8
Joined: Tue Nov 29, 2005 1:40 pm
Location: Germany

RE: Connect without searching

Tue Dec 06, 2005 2:05 pm

I´ve done a HardReset of the PDA und installed the the BlueTools CAB file again.
The same Error with the Find&Connect demo..... I will now try to install the Beta7 again. Last week it was no problem to get it work....

If the program reaches
currentStream = currentService.Stream;
my device (I could configure it with Hyperterminal) returns a errormessage: NO CARRIER 0 ERROR 409 RFC_ABNORMAL_DISCONNECT.
Something in the RFCOMM Layer might be wrong...but I don´t know what..

Martin J
Posts: 11
Joined: Wed Oct 26, 2005 12:02 pm
Location: Sweden

RE: Connect without searching

Tue Dec 06, 2005 3:34 pm

Hi ds303!

This problem still occurs for me from time to time. You can read more about it in thread "Connection problem". Just like in your case a "hard reset" won't fix it, but there is a manual workaround for this:

1. Go into BT Manager and turn on BT
2. Set up a shortcut to some (any) units serial port service
3. Connect and then disconnect to this service via shortcut

Now the BT stack seems to be reset in some way so I can connect again. There is still a problem in beta 9 which makes this error come back though. If you just turn off then on BT (via BT Manager och by shutting the PDA off then on) all connections will again fail until you perform the steps above.

Hope this works for you until a fix comes out.

Regards,
/Martin J

ds303
Posts: 8
Joined: Tue Nov 29, 2005 1:40 pm
Location: Germany

RE: Connect without searching

Tue Dec 06, 2005 4:31 pm

Tank you Martin.
It seems to me, that you are right... :-(

I think the Bluetooth Manager should be run in the background, too.

If it's realy a bug, hopefully they will fix it soon. I'm writing my diploma thesis and I've not much time....

Thank you all for help!

bashar_tak
Posts: 10
Joined: Sun Jun 03, 2007 5:26 pm
Contact: Website

RE: Connect without searching

Wed Jun 20, 2007 4:22 am

Pinging the device is a good idea, but the problem is that you need to open a stream which dose need to be bonded. This obviously need the pincode to be confirmed in the client device. Of course not all of them. In WM5 it works fine but in SonyEricsson 750i for example it still ask for the pincode.

Best,
Bashar

Return to “BlueTools”